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


C# ILexer.AssertMoveNext方法代码示例

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


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

示例2: CompileFunction

        public EarleFunction CompileFunction(ILexer lexer, EarleFile file)
        {
            if (lexer == null) throw new ArgumentNullException(nameof(lexer));

            var name = lexer.Current.Value.ToLower();
            var parameters = new List<string>();

            lexer.AssertMoveNext();

            lexer.SkipToken(TokenType.Token, "(");

            while (!lexer.Current.Is(TokenType.Token, ")"))
            {
                lexer.AssertToken(TokenType.Identifier);

                if (parameters.Contains(lexer.Current.Value))
                    throw new ParseException(lexer.Current, $"Duplicate parameter name in function \"{name}\"");

                parameters.Add(lexer.Current.Value);
                lexer.AssertMoveNext();

                if (lexer.Current.Is(TokenType.Token, ")"))
                    break;

                lexer.SkipToken(TokenType.Token, ",");
            }

            lexer.SkipToken(TokenType.Token, ")");

            var lastLine = lexer.Current.Line;
            var block = Compile(lexer, file, EarleCompileOptions.Method);
            file.AddReferencedFiles(block.ReferencedFiles);

            return new EarleFunction(file, name, parameters.ToArray(), block.PCode, block.CallLines);
        }
开发者ID:ikkentim,项目名称:earlescript,代码行数:35,代码来源:EarleCompiler.cs


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