Exemple #1
0
        private static void ParseFuncName(Lexer.Lexer lexer, out Exp exp, out bool hasColon)
        {
            hasColon = false;
            lexer.NextIdentifier(out var line, out var name);
            exp = new NameExp {
                Line = line, Name = name
            };

            while (lexer.LookAhead() == ETokenType.SepDot)
            {
                lexer.NextToken(out _, out _, out _);
                lexer.NextIdentifier(out line, out name);
                var idx = new StringExp {
                    Line = line, Str = name
                };
                exp = new TableAccessExp
                {
                    LastLine  = line,
                    KeyExp    = idx,
                    PrefixExp = exp,
                };
            }

            if (lexer.LookAhead() == ETokenType.SepColon)
            {
                lexer.NextToken(out _, out _, out _);
                lexer.NextIdentifier(out line, out name);
                var idx = new StringExp {
                    Line = line, Str = name
                };
                exp = new TableAccessExp
                {
                    LastLine  = line,
                    PrefixExp = exp,
                    KeyExp    = idx,
                };
                hasColon = true;
            }
        }
Exemple #2
0
        private static void ParseParList(Lexer.Lexer lexer, out List <string> parList, out bool isVararg)
        {
            parList  = new List <string>();
            isVararg = false;

            switch (lexer.LookAhead())
            {
            case ETokenType.SepRParen:
                return;

            case ETokenType.Vararg:
            {
                lexer.NextToken(out _, out _, out _);
                isVararg = true;
                return;
            }
            }

            lexer.NextIdentifier(out _, out var name);
            parList.Add(name);

            while (lexer.LookAhead() == ETokenType.SepComma)
            {
                lexer.NextToken(out _, out _, out _);
                if (lexer.LookAhead() == ETokenType.Identifier)
                {
                    lexer.NextIdentifier(out _, out name);
                    parList.Add(name);
                }
                else
                {
                    lexer.NextTokenOfKind(ETokenType.Vararg, out _, out _);
                    isVararg = true;
                    break;
                }
            }
        }