当前位置: 首页>>代码示例>>C#>>正文


C# ILexer.MoveNext方法代码示例

本文整理汇总了C#中ILexer.MoveNext方法的典型用法代码示例。如果您正苦于以下问题:C# ILexer.MoveNext方法的具体用法?C# ILexer.MoveNext怎么用?C# ILexer.MoveNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILexer的用法示例。


在下文中一共展示了ILexer.MoveNext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compile

        public CompiledBlock Compile(ILexer lexer, EarleFile file, EarleCompileOptions options)
        {
            var pCode = new List<byte>();
            var callLines = new Dictionary<int, int>();
            var breaks = new List<int>();
            var continues = new List<int>();
            var usedFiles = new List<string>();

            var didReturnAnyValue = false;
            var multiLine = false;

            var startLine = lexer.Current.Line;

            if (lexer.Current.Is(TokenType.Token, "{"))
            {
                multiLine = true;
                lexer.AssertMoveNext();
            }

            var requiresScope = false;

            do
            {
                if (multiLine && lexer.Current.Is(TokenType.Token, "}"))
                    break;

                var parserName = SyntaxGrammarProcessor.GetMatch(lexer, true);
                if (parserName == null)
                    throw new ParseException(lexer.Current, $"Expected statement, found token `{lexer.Current.Value}`");

                if (parserName == "STATEMENT_BREAK" && options.HasFlag(EarleCompileOptions.CanBreak))
                {
                    lexer.SkipToken(TokenType.Identifier, "break");
                    lexer.SkipToken(TokenType.Token, ";");

                    breaks.Add(pCode.Count);
                    pCode.Add((byte) OpCode.Jump);
                    pCode.AddRange(ArrayUtility.Repeat((byte) 0xaa, 4));
                    didReturnAnyValue = false;

                    if (options.HasFlag(EarleCompileOptions.EnforceMultiline))
                        break;
                }
                else if (parserName == "STATEMENT_CONTINUE" && options.HasFlag(EarleCompileOptions.CanContinue))
                {
                    lexer.SkipToken(TokenType.Identifier, "continue");
                    lexer.SkipToken(TokenType.Token, ";");

                    continues.Add(pCode.Count);
                    pCode.Add((byte) OpCode.Jump);
                    pCode.AddRange(ArrayUtility.Repeat((byte) 0xaa, 4));
                    didReturnAnyValue = false;

                    if (options.HasFlag(EarleCompileOptions.EnforceMultiline))
                        break;
                }
                else
                {
                    IParser parser;
                    if (!_parsers.TryGetValue(parserName, out parser))
                        throw new ParseException(lexer.Current,
                            $"Expected statement, found {parserName.ToLower()} `{lexer.Current.Value}`");

                    var parseOptions = options.HasFlag(EarleCompileOptions.MustReturn)
                        ? options ^ EarleCompileOptions.MustReturn
                        : options;

                    var block = parser.Parse(_runtime, file, lexer, parseOptions);

                    var startIndex = pCode.Count;
                    breaks.AddRange(block.Breaks.Select(b => b + pCode.Count));
                    foreach (var p in block.CallLines)
                        callLines.Add(p.Key + startIndex, p.Value);
                    continues.AddRange(block.Continues.Select(c => c + pCode.Count));
                    usedFiles.AddRange(block.ReferencedFiles.Where(f => !usedFiles.Contains(f)));
                    requiresScope = requiresScope || block.RequiresScope;
                    pCode.AddRange(block.PCode);

                    if (parser is ISimpleStatement)
                        lexer.SkipToken(TokenType.Token, ";");

                    didReturnAnyValue = parser is StatementReturnParser;

                    if (didReturnAnyValue && options.HasFlag(EarleCompileOptions.EnforceMultiline))
                        break;
                }

                if (options.HasFlag(EarleCompileOptions.EnforceMultiline) && SyntaxGrammarProcessor.MatchStartsWith(lexer, "LABEL_"))
                    break;
            } while (options.HasFlag(EarleCompileOptions.EnforceMultiline) ||
                     (multiLine && !lexer.Current.Is(TokenType.Token, "}")));

            if (multiLine)
            {
                lexer.AssertToken(TokenType.Token, "}");
                lexer.MoveNext();
            }

            if (!didReturnAnyValue && options.HasFlag(EarleCompileOptions.MustReturn))
            {
//.........这里部分代码省略.........
开发者ID:ikkentim,项目名称:earlescript,代码行数:101,代码来源:EarleCompiler.cs


注:本文中的ILexer.MoveNext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。