src/EasyFrameWork/RuleEngine/Scripting/Compiler/Lexer.cs

(完整代码) 1KB

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using System.Collections.Generic;

namespace Easy.RuleEngine.Scripting.Compiler
{
    public class Lexer
    {
        private readonly Tokenizer _tokenizer;
        private readonly List<Token> _tokens = new List<Token>();
        private int _tokenIndex;

        public Lexer(Tokenizer tokenizer)
        {
            _tokenizer = tokenizer;
        }

        public Token Token()
        {
            if (_tokenIndex == _tokens.Count)
            {
                _tokens.Add(_tokenizer.NextToken());
            }
            return _tokens[_tokenIndex];
        }

        public void NextToken()
        {
            _tokenIndex++;
        }

        public Marker Mark()
        {
            return new Marker(_tokens.Count);
        }

        public void Mark(Marker marker)
        {
            _tokenIndex = marker.TokenIndex;
        }

        public struct Marker
        {
            private readonly int _tokenIndex;

            public Marker(int tokenIndex)
            {
                _tokenIndex = tokenIndex;
            }

            public int TokenIndex
            {
                get { return _tokenIndex; }
            }
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。