public override bool Parse(SyntacticState state) { if (state.IsEndOfData) return false; LexicalEntry entry = state.GetInner(state.InnerPosition); if (entry.Key != Identifier.S.Key) return false; // parse all identidiers except those // which are similar to LINQ keywords string name = state.GetOuter(entry); if (name == "ascending" || name == "by" || name == "descending" || name == "equals" || name == "from" || name == "group" || name == "in" || name == "into" || name == "join" || name == "let" || name == "on" || name == "orderby" || name == "select" || name == "where") return false; state.AddAbsolute( Key, state.InnerPosition + 1, entry.EndPosition); return true; }
/// <summary> /// Tries to parse a batch of similar syntactic items with specified delimiter. /// </summary> public bool ParseMany(SyntacticState state, SyntacticItem part, SyntacticItem delimiter) { return Parse( (syntacticState, args) => ParseManyInternal(syntacticState, args[0], args[1]), state, new[] { part, delimiter }); }
public override bool Parse(SyntacticState state) { // check whether we need to ignore nullable types int flag = state.GetFlag<int>(StateFlags.IgnoreNullableAfterPosition); if (flag > 0 && state.InnerPosition >= flag) { // perform parsing ignoring nullable types state.RaiseFlag(StateFlags.IgnoreNullable); bool parsed = ParseAny( state, new ParseAll(LeftAngleBracketTerminal.S, ShiftExpression.S), new ParseAll(RightAngleBracketTerminal.S, ShiftExpression.S), new ParseAll(LessOrEqualTerminal.S, ShiftExpression.S), new ParseAll(GreaterOrEqualTerminal.S, ShiftExpression.S), new ParseAll(IsTerminal.S, Type.S), new ParseAll(AsTerminal.S, Type.S)); state.LowerFlag(StateFlags.IgnoreNullable); return parsed; } // perform usual parsing return ParseAny( state, new ParseAll(LeftAngleBracketTerminal.S, ShiftExpression.S), new ParseAll(RightAngleBracketTerminal.S, ShiftExpression.S), new ParseAll(LessOrEqualTerminal.S, ShiftExpression.S), new ParseAll(GreaterOrEqualTerminal.S, ShiftExpression.S), new ParseAll(IsTerminal.S, Type.S), new ParseAll(AsTerminal.S, Type.S)); }
public override bool Parse(SyntacticState state) { int innerIndex = state.InnerPosition; int outerIndex = state.OuterPosition; // non-assignment-expression is required if (!NonAssignmentExpression.S.Parse(state)) return false; // if unary-expression has been captured // we should try to capture rest parts of assignment if (state.CheckEntry(UnaryExpression.S.Key, innerIndex)) { int inner = state.InnerPosition; int outer = state.OuterPosition; // the rest parts of assigment are assignment-operator if (AssignmentOperator.S.Parse(state)) { // and another expression (recursive call here) if (S.Parse(state)) { } else { state.Reset(inner, outer); } } } state.AddBack(Key, innerIndex, outerIndex); return true; }
public override bool Parse(SyntacticState state) { return ParseAny( state, ObjectInitializer.S, CollectionInitializer.S); }
public override bool Parse(SyntacticState state) { return ParseAll( state, PrimaryNoArrayCreationExpressionSimple.S, PrimaryExpressionSuffixes.O); }
public override bool Parse(SyntacticState state) { // this terminal consists of two lexical punctuators // and should be parsed in a special way if (state.InnerPosition + 1 >= state.InnerLength) return false; LexicalEntry e1 = state.GetInner(state.InnerPosition); if (state.GetOuter(e1) != ">") return false; LexicalEntry e2 = state.GetInner(state.InnerPosition + 1); if (state.GetOuter(e2) != ">=") return false; if (e2.StartPosition != e1.StartPosition + 1) return false; state.AddAbsolute( Key, state.InnerPosition + 2, state.OuterPosition + 3); return true; }
/// <summary> /// Tries to parse any of specified syntactic items. /// </summary> public bool ParseAny(SyntacticState state, params SyntacticItem[] parts) { return Parse( ParseAnyInternal, state, parts); }
public override bool Parse(SyntacticState state) { return ParseAll( state, LeftCurlyBracketTerminal.S, StatementList.O, RightCurlyBracketTerminal.S); }
public override bool Parse(SyntacticState state) { return ParseAll( state, TypePart.S, QuestionTerminal.O, RankSpecifiers.S); }
public override bool Parse(SyntacticState state) { return ParseAny( state, LabeledStatement.S, DeclarationStatement.S, EmbeddedStatement.S); }
public void SyntacticState_Uncovered() { Ensure.Throws(() => new SyntacticState(null, "data")); Ensure.Throws(() => new SyntacticState(new List<LexicalEntry>(), null)); SyntacticState state = new SyntacticState(new List<LexicalEntry>(), "data"); Assert.AreEqual(4, state.OuterLength); }
public override bool Parse(SyntacticState state) { int innerIndex = state.InnerPosition; int outerIndex = state.OuterPosition; // null-coalescing-expression is required if (!NullCoalescingExpression.S.Parse(state)) return false; // if captured expression ends with "?" LexicalEntry entry = state.GetInner(state.InnerPosition - 1); if (state.GetOuter(entry) == "?") { // check whether "? and :" part goes after bool full = ParseAll( state, QuestionTerminal.S, Expression.S, ColonTerminal.S, Expression.S); // if so, everything is OK if (full) { state.AddBack(Key, innerIndex, outerIndex); return true; } // if not, make another attempt to parse conditional expression // handling null-coalescing-expression without trailing "?" state.Reset(innerIndex, outerIndex); // if we could do that, we can return if (ParseAll( state, NullCoalescingExpressionShorten.S, QuestionTerminal.S, Expression.S, ColonTerminal.S, Expression.S)) { return true; } // if not, parse initial null-coalescing-expression once again NullCoalescingExpression.S.Parse(state); } ParseAll( state, QuestionTerminal.S, Expression.S, ColonTerminal.S, Expression.S); state.AddBack(Key, innerIndex, outerIndex); return true; }
public override bool Parse(SyntacticState state) { return(ParseAny( state, ClassDeclaration.S, StructDeclaration.S, InterfaceDeclaration.S, EnumDeclaration.S, DelegateDeclaration.S)); }
public override bool Parse(SyntacticState state) { return ParseAll( state, LeftCurlyBracketTerminal.S, ExternAliasDirectives.O, UsingDirectives.O, NamespaceMemberDeclarations.O, RightCurlyBracketTerminal.S); }
public override bool Parse(SyntacticState state) { return(ParseAll( state, LeftCurlyBracketTerminal.S, ExternAliasDirectives.O, UsingDirectives.O, NamespaceMemberDeclarations.O, RightCurlyBracketTerminal.S)); }
public override bool Parse(SyntacticState state) { return ParseAll( state, new LexicalTerminal(FunctionPrefix.S), Whitespaces.O, Expression.S, RightRoundBracketTerminal.S, Whitespaces.O); }
public override bool Parse(SyntacticState state) { return ParseAny( state, ClassDeclaration.S, StructDeclaration.S, InterfaceDeclaration.S, EnumDeclaration.S, DelegateDeclaration.S); }
public override bool Parse(SyntacticState state) { return(ParseAll( state, new LexicalTerminal(FunctionPrefix.S), Whitespaces.O, Expression.S, RightRoundBracketTerminal.S, Whitespaces.O)); }
/// <summary> /// Returns true only if all input data has been successfully parsed. /// </summary> public static bool ParseFull(this SyntacticItem item, SyntacticState state) { bool parsed = item.Parse(state); if (!parsed) return false; if (!state.IsEndOfData) return false; return true; }
public override bool Parse(SyntacticState state) { return ParseAny( state, CastExpression.S, PrimaryExpression.S, PreIncrementExpression.S, PreDecrementExpression.S, new ParseAll(PlusTerminal.S, S), new ParseAll(MinusTerminal.S, S), new ParseAll(ExclamationTerminal.S, S), new ParseAll(TildeTerminal.S, S)); }
public override bool Parse(SyntacticState state) { return ParseAny( state, CastExpression.S, PrimaryExpression.S, PreIncrementExpression.S, PreDecrementExpression.S, new ParseAll(PlusTerminal.S, S), new ParseAll(MinusTerminal.S, S), new ParseAll(ExclamationTerminal.S, S), new ParseAll(TildeTerminal.S, S)); }
public override bool Parse(SyntacticState state) { return ParseAny( state, new ParseAll( LeftCurlyBracketTerminal.S, VariableInitializerList.O, RightCurlyBracketTerminal.S), new ParseAll( LeftCurlyBracketTerminal.S, VariableInitializerList.S, CommaTerminal.S, RightCurlyBracketTerminal.S)); }
public override bool Parse(SyntacticState state) { return(ParseAny( state, new ParseAll( LeftCurlyBracketTerminal.S, VariableInitializerList.O, RightCurlyBracketTerminal.S), new ParseAll( LeftCurlyBracketTerminal.S, VariableInitializerList.S, CommaTerminal.S, RightCurlyBracketTerminal.S))); }
/// <summary> /// Tries to parse specified data as a syntactic item. /// </summary> public static bool TryParse(SyntacticItem item, string data) { LexicalState lexicalState = new LexicalState(data); if (!Input.S.ParseFull(lexicalState)) return false; SyntacticState syntacticState = new SyntacticState( lexicalState.ExtractTokens(), data); if (!item.ParseFull(syntacticState)) return false; return true; }
/// <summary> /// Tries to parse an entity from the specified syntactic machine state. /// In case of success returns true and advances parsing position. /// </summary> public override bool Parse(SyntacticState state) { if (state.IsEndOfData) return false; LexicalEntry entry = state.GetInner(state.InnerPosition); if (entry.Key != m_item.Key) return false; state.AddAbsolute( Key, state.InnerPosition + 1, entry.EndPosition); return true; }
/// <summary> /// Returns true only if all input data has been successfully parsed. /// </summary> public static bool ParseFull(this SyntacticItem item, SyntacticState state) { bool parsed = item.Parse(state); if (!parsed) { return(false); } if (!state.IsEndOfData) { return(false); } return(true); }
public override bool Parse(SyntacticState state) { return(ParseAny( state, Block.S, EmptyStatement.S, ExpressionStatement.S, SelectionStatement.S, IterationStatement.S, JumpStatement.S, TryStatement.S, CheckedStatement.S, UncheckedStatement.S, LockStatement.S, UsingStatement.S, YieldStatement.S)); }
/// <summary> /// Tries to parse an entity from the specified syntactic machine state. /// In case of success returns true and advances parsing position. /// </summary> public override bool Parse(SyntacticState state) { if (state.IsEndOfData) return false; LexicalEntry entry = state.GetInner(state.InnerPosition); string text = state.GetOuter(entry); if (text != m_text) return false; state.AddAbsolute( Key, state.InnerPosition + 1, entry.EndPosition); return true; }
public override bool Parse(SyntacticState state) { // in some cases we might need to prohibit // using LINQ keywords as identifiers if (state.CheckFlag(StateFlags.InsideLinq)) { return(ParseAll( state, IdentifierInLinqTerminal.S, TypeArgumentList.O)); } return(ParseAll( state, IdentifierTerminal.S, TypeArgumentList.O)); }
public override bool Parse(SyntacticState state) { // in some cases we might need to prohibit // using LINQ keywords as identifiers if (state.CheckFlag(StateFlags.InsideLinq)) { return ParseAll( state, IdentifierInLinqTerminal.S, TypeArgumentList.O); } return ParseAll( state, IdentifierTerminal.S, TypeArgumentList.O); }
public override bool Parse(SyntacticState state) { // this is a special case when we are trying to // catch null-coalescing-expression without trailing "?" int innerIndex = state.InnerPosition; int outerIndex = state.OuterPosition; // ensure that usual null-coalescing-expression can be parsed if (!NullCoalescingExpression.S.Parse(state)) { return(false); } // we should not do anything if captured expression // doesn't end with a "?" LexicalEntry entry = state.GetInner(state.InnerPosition - 1); if (state.GetOuter(entry) != "?") { return(true); } // get a position of the last type entry int lastTypeIndex = 0; for (int i = innerIndex; i <= state.InnerPosition; i++) { if (state.CheckEntry(Type.S.Key, i)) { lastTypeIndex = i; } } // reset parsing and make another attempt // ignoring nullable types after specified index state.Reset(innerIndex, outerIndex); state.SetFlag(StateFlags.IgnoreNullableAfterPosition, lastTypeIndex - 1); bool parsed = ParseMany( state, ConditionalOrExpression.S, DoubleQuestionTerminal.S); state.ResetFlag(StateFlags.IgnoreNullableAfterPosition); return(parsed); }
public override bool Parse(SyntacticState state) { // this is a special case when we want to // prohibit using LINQ keywords as identifiers state.RaiseFlag(StateFlags.InsideLinq); bool parsed = ParseAny( state, FromClause.S, LetClause.S, WhereClause.S, JoinIntoClause.S, JoinClause.S, OrderbyClause.S); state.LowerFlag(StateFlags.InsideLinq); return parsed; }
public override bool Parse(SyntacticState state) { // in some cases we might need to // ignore nullable types if (state.CheckFlag(StateFlags.IgnoreNullable)) { return ParseAll( state, TypePart.S, RankSpecifiers.O); } return ParseAll( state, TypePart.S, QuestionTerminal.O, RankSpecifiers.O); }
public override bool Parse(SyntacticState state) { // in some cases we might need to // ignore nullable types if (state.CheckFlag(StateFlags.IgnoreNullable)) { return(ParseAll( state, TypePart.S, RankSpecifiers.O)); } return(ParseAll( state, TypePart.S, QuestionTerminal.O, RankSpecifiers.O)); }
public override bool Parse(SyntacticState state) { // this is a special case when we want to // prohibit using LINQ keywords as identifiers state.RaiseFlag(StateFlags.InsideLinq); bool parsed = ParseAny( state, FromClause.S, LetClause.S, WhereClause.S, JoinIntoClause.S, JoinClause.S, OrderbyClause.S); state.LowerFlag(StateFlags.InsideLinq); return(parsed); }
public override bool Parse(SyntacticState state) { if (state.IsEndOfData) { return(false); } LexicalEntry entry = state.GetInner(state.InnerPosition); if (entry.Key != Identifier.S.Key) { return(false); } // parse all identidiers except those // which are similar to LINQ keywords string name = state.GetOuter(entry); if (name == "ascending" || name == "by" || name == "descending" || name == "equals" || name == "from" || name == "group" || name == "in" || name == "into" || name == "join" || name == "let" || name == "on" || name == "orderby" || name == "select" || name == "where") { return(false); } state.AddAbsolute( Key, state.InnerPosition + 1, entry.EndPosition); return(true); }
public override bool Parse(SyntacticState state) { return ParseAny( state, LiteralTerminal.S, MemberAccessSimple.S, SimpleName.S, ParenthesizedExpression.S, ThisAccess.S, BaseAccess.S, ObjectCreationExpression.S, DelegateCreationExpression.S, AnonymousObjectCreationExpression.S, TypeofExpression.S, CheckedExpression.S, UncheckedExpression.S, DefaultValueExpression.S, AnonymousMethodExpression.S, ArrayCreationExpression.S); }
/// <summary> /// Tries to parse specified data as a syntactic item. /// </summary> public static bool TryParse(SyntacticItem item, string data) { LexicalState lexicalState = new LexicalState(data); if (!Input.S.ParseFull(lexicalState)) { return(false); } SyntacticState syntacticState = new SyntacticState( lexicalState.ExtractTokens(), data); if (!item.ParseFull(syntacticState)) { return(false); } return(true); }
public override bool Parse(SyntacticState state) { return(ParseAny( state, LiteralTerminal.S, MemberAccessSimple.S, SimpleName.S, ParenthesizedExpression.S, ThisAccess.S, BaseAccess.S, ObjectCreationExpression.S, DelegateCreationExpression.S, AnonymousObjectCreationExpression.S, TypeofExpression.S, CheckedExpression.S, UncheckedExpression.S, DefaultValueExpression.S, AnonymousMethodExpression.S, ArrayCreationExpression.S)); }
public override bool Parse(SyntacticState state) { // this is a special case when we are trying to // catch null-coalescing-expression without trailing "?" int innerIndex = state.InnerPosition; int outerIndex = state.OuterPosition; // ensure that usual null-coalescing-expression can be parsed if (!NullCoalescingExpression.S.Parse(state)) return false; // we should not do anything if captured expression // doesn't end with a "?" LexicalEntry entry = state.GetInner(state.InnerPosition - 1); if (state.GetOuter(entry) != "?") return true; // get a position of the last type entry int lastTypeIndex = 0; for (int i = innerIndex; i <= state.InnerPosition; i++) { if (state.CheckEntry(Type.S.Key, i)) lastTypeIndex = i; } // reset parsing and make another attempt // ignoring nullable types after specified index state.Reset(innerIndex, outerIndex); state.SetFlag(StateFlags.IgnoreNullableAfterPosition, lastTypeIndex - 1); bool parsed = ParseMany( state, ConditionalOrExpression.S, DoubleQuestionTerminal.S); state.ResetFlag(StateFlags.IgnoreNullableAfterPosition); return parsed; }
public override bool Parse(SyntacticState state) { if (state.IsEndOfData) return false; // ensure that identifier is captured LexicalEntry entry = state.GetInner(state.InnerPosition); if (entry.Key != Identifier.S.Key) return false; // check that identifier consists only of specified letters string checkOuter = state.GetOuter(entry); LexicalState checkState = new LexicalState(checkOuter); if (!m_check.ParseFull(checkState)) return false; state.AddAbsolute( Key, state.InnerPosition + 1, entry.EndPosition); return true; }
/// <summary> /// Tries to parse an entity from the specified syntactic machine state. /// In case of success returns true and advances parsing position. /// </summary> public override bool Parse(SyntacticState state) { return(ParseAny(state, m_items)); }
public void SpecificAtKeyword_Uncovered() { SyntacticState state = new SyntacticState(new List <LexicalEntry>(), "empty"); Assert.IsFalse(LeftTop.S.Parse(state)); }
/// <summary> /// Tries to parse an entity from the specified syntactic machine state. /// In case of success returns true and advances parsing position. /// </summary> public override bool Parse(SyntacticState state) { return true; }
/// <summary> /// Tries to parse an entity from the specified syntactic machine state. /// In case of success returns true and advances parsing position. /// </summary> public override bool Parse(SyntacticState state) { return(true); }
/// <summary> /// Tries to parse an entity from the specified syntactic machine state. /// In case of success returns true and advances parsing position. /// </summary> public override bool Parse(SyntacticState state) { return(ParseMany(state, m_part, m_delimiter)); }
/// <summary> /// Tries to parse an entity from the specified syntactic machine state. /// In case of success returns true and advances parsing position. /// </summary> public override bool Parse(SyntacticState state) { return ParseMany(state, m_part, m_delimiter); }
public override bool Parse(SyntacticState state) { int innerIndex = state.InnerPosition; int outerIndex = state.OuterPosition; // null-coalescing-expression is required if (!NullCoalescingExpression.S.Parse(state)) { return(false); } // if captured expression ends with "?" LexicalEntry entry = state.GetInner(state.InnerPosition - 1); if (state.GetOuter(entry) == "?") { // check whether "? and :" part goes after bool full = ParseAll( state, QuestionTerminal.S, Expression.S, ColonTerminal.S, Expression.S); // if so, everything is OK if (full) { state.AddBack(Key, innerIndex, outerIndex); return(true); } // if not, make another attempt to parse conditional expression // handling null-coalescing-expression without trailing "?" state.Reset(innerIndex, outerIndex); // if we could do that, we can return if (ParseAll( state, NullCoalescingExpressionShorten.S, QuestionTerminal.S, Expression.S, ColonTerminal.S, Expression.S)) { return(true); } // if not, parse initial null-coalescing-expression once again NullCoalescingExpression.S.Parse(state); } ParseAll( state, QuestionTerminal.S, Expression.S, ColonTerminal.S, Expression.S); state.AddBack(Key, innerIndex, outerIndex); return(true); }