Example #1
0
        private ScriptBlock CreateBlock(ScriptToken start, ScriptBlock scope)
        {
            var startIndex = start.Index;
            var endIndex   = scope.Index + scope.Content.Length;
            var content    = _content.Substring(startIndex, endIndex - startIndex);

            return(new ScriptBlock(startIndex, content, false));
        }
Example #2
0
        public ScriptBlock ParseNext()
        {
            if (_current == null)
            {
                return(null);
            }

            _start = _current;

            while (true)
            {
                switch (_current.Type)
                {
                case ScriptTokenType.Semicolon:
                {
                    var block = CreateBlock(false);
                    Read();     // Nom nom nom
                    return(block);
                }

                case ScriptTokenType.LeftParenthesis:
                {
                    SkipBlock(ScriptTokenType.LeftParenthesis, ScriptTokenType.RightParenthesis);
                    break;
                }

                case ScriptTokenType.LeftBrace:
                {
                    return(ParseScope());
                }

                case ScriptTokenType.If:
                {
                    return(ParseStatement(ScriptTokenType.If));
                }

                case ScriptTokenType.Else:
                {
                    return(ParseStatement(ScriptTokenType.Else));
                }

                case ScriptTokenType.While:
                {
                    return(ParseStatement(ScriptTokenType.While));
                }

                case ScriptTokenType.Switch:
                {
                    return(ParseStatement(ScriptTokenType.Switch));
                }
                }

                if (!Read())
                {
                    return(CreateBlock(false));
                }
            }
        }
Example #3
0
 private bool Read()
 {
     _current = _tokenizer.GetNextToken();
     return(_current != null);
 }
Example #4
0
        private ScriptBlock CreateBlock(ScriptToken current, bool hasScope)
        {
            var content = _content.Substring(_start.Index, current.Index + current.Length - _start.Index);

            return(new ScriptBlock(_start.Index, content, hasScope));
        }
Example #5
0
 public ScriptParser(string content)
 {
     _content   = content;
     _tokenizer = new ScriptTokenizer(content);
     _current   = _tokenizer.GetNextToken();
 }