public override void InitializeFromParseStream(ParseProcessState state) { while (state.MoveNext(true) != null) { //move a token - this wll cause the next item in the steream to be created // var nextToken = state.MoveNext(); var newElement = state.CreateCurrent(); if (newElement != null) { //a element was created - at this level it would be a statement unorderdelements.Add(newElement); } //if iis a close group token (such as ) or ] ) then exit here to slide back to the parent if (newElement is GroupCloserPlaceHolderElement) { ContainedElement = newElement; return; } //peek next ifits a eol or a eof then orginize the statement and return var nxt = state.Peek(1); if (nxt == null) { throw new ParseException("Statment ended with a null, EOF or NEWLINE expected"); } var nxtval = nxt.Value.TokenType; if (nxtval == LexedTokenType.NEWLINE || nxtval == LexedTokenType.EOF) { ArrangeContainedElements(); return; } } }
public override void InitializeFromParseStream(ParseProcessState state) { while (state.MoveNext(MyTransitions[state.State], false) != null) { var curr = state.Current().Value; switch (state.State) { case StatementState.NumericQuantifierStart: { if (curr.TokenType == LexedTokenType.NUMBER) { if (state.Peek(1).Value.TokenType == LexedTokenType.CLOSECURLY) { var parseval = int.Parse(curr.TokenText); this.MinOccours = parseval; this.MaxOccours = parseval; state.State = StatementState.NumericQuantifierMax; break; } MinOccours = int.Parse(curr.TokenText); state.State = StatementState.NumericQuantifierMin; } else { state.State = StatementState.NumericQuantifierComma; } break; } case StatementState.NumericQuantifierMin: { state.State = StatementState.NumericQuantifierComma; break; } case StatementState.NumericQuantifierComma: { if (curr.TokenType == LexedTokenType.NUMBER) { MaxOccours = int.Parse(curr.TokenText); state.State = StatementState.NumericQuantifierMax; } else { state.State = StatementState.NumericQuantifierEnd; return; } break; } case StatementState.NumericQuantifierMax: { state.State = StatementState.NumericQuantifierEnd; return; } case StatementState.NumericQuantifierEnd: return; default: throw new Exception("Invalid State '" + state.State.ToString() + " in NumericQuantifier , this is caused by an internal bug"); } } }