Пример #1
0
 public Token ScanTokenAt(int tokenIndex, Action match)
 {
     while (!IsPushCompleted && !_currentTokenPush.IncrementalStop() && _currentTokenPush.Current <= tokenIndex)
     {
         match();
     }
     return(Tokens.ElementAtOrDefault(tokenIndex));
 }
Пример #2
0
        public void MatchOne()
        {
            Skip();
            if (Index < Content.Length && !_push.IncrementalStop())
            {
                bool matched =
                    MatchActionComment() ||
                    MatchNumber() ||
                    MatchSymbol('{', TokenType.CurlyBracket_Open) ||
                    MatchSymbol('}', TokenType.CurlyBracket_Close) ||
                    MatchSymbol('(', TokenType.Parentheses_Open) ||
                    MatchSymbol(')', TokenType.Parentheses_Close) ||
                    MatchSymbol('[', TokenType.SquareBracket_Open) ||
                    MatchSymbol(']', TokenType.SquareBracket_Close) ||
                    MatchSymbol(':', TokenType.Colon) ||
                    MatchSymbol('?', TokenType.QuestionMark) ||
                    MatchSymbol(';', TokenType.Semicolon) ||
                    MatchSymbol('.', TokenType.Dot) ||
                    MatchSymbol('~', TokenType.Squiggle) ||
                    MatchSymbol("=>", TokenType.Arrow) ||
                    MatchSymbol("!=", TokenType.NotEqual) ||
                    MatchSymbol("==", TokenType.EqualEqual) ||
                    MatchSymbol("<=", TokenType.LessThanOrEqual) ||
                    MatchSymbol(">=", TokenType.GreaterThanOrEqual) ||
                    MatchSymbol('!', TokenType.Exclamation) ||
                    MatchSymbol("^=", TokenType.HatEqual) ||
                    MatchSymbol("*=", TokenType.MultiplyEqual) ||
                    MatchSymbol("/=", TokenType.DivideEqual) ||
                    MatchSymbol("%=", TokenType.ModuloEqual) ||
                    MatchSymbol("+=", TokenType.AddEqual) ||
                    MatchSymbol("-=", TokenType.SubtractEqual) ||
                    MatchSymbol('=', TokenType.Equal) ||
                    MatchSymbol('<', TokenType.LessThan) ||
                    MatchSymbol('>', TokenType.GreaterThan) ||
                    MatchSymbol(',', TokenType.Comma) ||
                    MatchSymbol('^', TokenType.Hat) ||
                    MatchSymbol('*', TokenType.Multiply) ||
                    MatchSymbol('/', TokenType.Divide) ||
                    MatchSymbol('%', TokenType.Modulo) ||
                    MatchSymbol("++", TokenType.PlusPlus) ||
                    MatchSymbol('+', TokenType.Add) ||
                    MatchSymbol("--", TokenType.MinusMinus) ||
                    MatchSymbol('-', TokenType.Subtract) ||
                    MatchSymbol("&&", TokenType.And) ||
                    MatchSymbol("||", TokenType.Or) ||
                    MatchSymbol("|", TokenType.Pipe) ||
                    MatchSymbol('@', TokenType.At) ||
                    MatchKeyword("import", TokenType.Import) ||
                    MatchKeyword("for", TokenType.For) ||
                    MatchKeyword("while", TokenType.While) ||
                    MatchKeyword("foreach", TokenType.Foreach) ||
                    MatchKeyword("in", TokenType.In) ||
                    MatchKeyword("rule", TokenType.Rule) ||
                    MatchKeyword("disabled", TokenType.Disabled) ||
                    MatchKeyword("true", TokenType.True) ||
                    MatchKeyword("false", TokenType.False) ||
                    MatchKeyword("null", TokenType.Null) ||
                    MatchKeyword("if", TokenType.If) ||
                    MatchKeyword("else", TokenType.Else) ||
                    MatchKeyword("break", TokenType.Break) ||
                    MatchKeyword("continue", TokenType.Continue) ||
                    MatchKeyword("return", TokenType.Return) ||
                    MatchKeyword("switch", TokenType.Switch) ||
                    MatchKeyword("case", TokenType.Case) ||
                    MatchKeyword("default", TokenType.Default) ||
                    MatchKeyword("class", TokenType.Class) ||
                    MatchKeyword("struct", TokenType.Struct) ||
                    MatchKeyword("enum", TokenType.Enum) ||
                    MatchKeyword("new", TokenType.New) ||
                    MatchKeyword("delete", TokenType.Delete) ||
                    MatchKeyword("define", TokenType.Define) ||
                    MatchKeyword("void", TokenType.Void) ||
                    MatchKeyword("public", TokenType.Public) ||
                    MatchKeyword("private", TokenType.Private) ||
                    MatchKeyword("protected", TokenType.Protected) ||
                    MatchKeyword("static", TokenType.Static) ||
                    MatchKeyword("override", TokenType.Override) ||
                    MatchKeyword("virtual", TokenType.Virtual) ||
                    MatchKeyword("recursive", TokenType.Recursive) ||
                    MatchKeyword("globalvar", TokenType.GlobalVar) ||
                    MatchKeyword("playervar", TokenType.PlayerVar) ||
                    MatchKeyword("ref", TokenType.Ref) ||
                    MatchKeyword("this", TokenType.This) ||
                    MatchKeyword("root", TokenType.Root) ||
                    MatchKeyword("async", TokenType.Async) ||
                    MatchKeyword("constructor", TokenType.Constructor) ||
                    MatchKeyword("as", TokenType.As) ||
                    MatchKeyword("type", TokenType.Type) ||
                    MatchKeyword("single", TokenType.Single) ||
                    MatchKeyword("const", TokenType.Const) ||
                    MatchIdentifier() ||
                    MatchString();

                if (matched)
                {
                    Skip();
                }
                else
                {
                    Unknown();
                }
            }
            PostMatch();
        }