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; }
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); }
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); }
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) { 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) { // 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); }
/// <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) { 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) { // 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; }
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); }