private Token ParseTo(IEnumerator iterator) { ParseToState state = ParseToState.FunctionName; Token name = new Token(TokenType.Word, null); TokenList args = new TokenList(); TokenList def = new TokenList(); bool reading = true; bool prev_newline = false; while (reading && iterator.MoveNext()) { Token token = (Token)iterator.Current; if (state != ParseToState.Content && token.Type == TokenType.Newline) { state = ParseToState.Content; prev_newline = true; continue; } switch (state) { case ParseToState.FunctionName: name = token; state = AdvanceState(state); break; case ParseToState.Argument: case ParseToState.ArgumentWithValue: case ParseToState.ArgumentCollector: if (token.Type == TokenType.OpenBracket) { TokenList arg = ParseBrackets(iterator); if (state == ParseToState.Argument || (state == ParseToState.ArgumentWithValue && arg.Count == 1)) { state = AdvanceState(state); } args.Add(new Token(TokenType.PlaceholderElement, new Element(ElementType.List, arg))); } else { args.Add(token); } break; case ParseToState.Content: if (prev_newline && token.Type == TokenType.Word && String.Compare((string)token.Val, "end", true) == 0) { reading = false; } else { def.Add(token); prev_newline = (token.Type == TokenType.Newline); } break; } } TokenList func = new TokenList(); func.Add(name); func.Add(new Token(TokenType.PlaceholderGroup, args)); func.Add(new Token(TokenType.PlaceholderGroup, def)); Function func_obj = CreateFunction(func); funcs.AddMessage(func_obj); if (to_parse == null) { to_parse = new ArrayList(); } to_parse.Add(func_obj); return(new Token(TokenType.PlaceholderElement, new Element(ElementType.Function, func_obj))); }
private ParseToState AdvanceState (ParseToState state) { return (ParseToState) ((int) state + 1); }
private ParseToState AdvanceState(ParseToState state) { return((ParseToState)((int)state + 1)); }