NPLMono.NPLLex.luaX_lex C# (CSharp) Method

luaX_lex() public static method

public static luaX_lex ( LexState LS, SemInfo seminfo ) : int
LS LexState
seminfo SemInfo
return int
        public static int luaX_lex(LexState LS, SemInfo seminfo)
        {
            for (; ; )
            {
                switch (LS.current)
                {

                    case '\n':
                    case '\r':
                        {
                            inclinenumber(LS);
                            continue;
                        }
                    case '-':
                        {
                            next(LS);
                            if (LS.current != '-') return '-';
                            /* else is a comment */
                            next(LS);
                            if (LS.current == '[' && (next(LS) == '['))
                            {
                                read_long_string(LS, null);  /* long comment */
                            }
                            else
                            {/* short comment */
                                while (LS.current != '\n' && LS.current != '\r' && LS.current != EOZ)
                                    next(LS);
                            }
                            continue;
                        }
                    case '[':
                        {
                            next(LS);
                            if (LS.current != '[') return '[';
                            else
                            {
                                read_long_string(LS, seminfo);
                                return (int)RESERVED.TK_STRING;
                            }
                        }
                    case '=':
                        {
                            next(LS);
                            if (LS.current != '=') return '=';
                            else { next(LS); return (int)RESERVED.TK_EQ; }
                        }
                    case '<':
                        {
                            next(LS);
                            if (LS.current != '=') return '<';
                            else { next(LS); return (int)RESERVED.TK_LE; }
                        }
                    case '>':
                        {
                            next(LS);
                            if (LS.current != '=') return '>';
                            else { next(LS); return (int)RESERVED.TK_GE; }
                        }
                    case '~':
                        {
                            next(LS);
                            if (LS.current != '=') return '~';
                            else { next(LS); return (int)RESERVED.TK_NE; }
                        }
                    case '"':
                    case '\'':
                        {
                            read_string(LS, LS.current, seminfo);
                            return (int)RESERVED.TK_STRING;
                        }
                    case '.':
                        {
                            next(LS);
                            if (LS.current == '.')
                            {
                                next(LS);
                                if (LS.current == '.')
                                {
                                    next(LS);
                                    return (int)RESERVED.TK_DOTS;   /* ... */
                                }
                                else return (int)RESERVED.TK_CONCAT;   /* .. */
                            }
                            else if (!Char.IsDigit((char)LS.current)) return '.';
                            else
                            {
                                read_numeral(LS, 1, seminfo);
                                return (int)RESERVED.TK_NUMBER;
                            }
                        }
                    case EOZ:
                        {
                            return (int)RESERVED.TK_EOS;
                        }
                    default:
                        {
                            if (Char.IsWhiteSpace((char)LS.current))
                            {
                                next(LS);
                                continue;
                            }
                            else if (Char.IsDigit((char)LS.current))
                            {
                                read_numeral(LS, 0, seminfo);
                                return (int)RESERVED.TK_NUMBER;
                            }
                            else if (char.IsLetter((char)LS.current) || LS.current == '_')
                            {
                                /* identifier or reserved word */
                                int l = readname(LS);
                                string ts = new string(LS.buff, 0, l);

                                // The following code implemented below
                                //if (ts.tsv.reserved > 0)  /* reserved word? */
                                // 	return ts.tsv.reserved - 1 + FIRST_RESERVED;

                                /* reserved word? */
                                for (int i = 0; i < NUM_RESERVED; ++i)
                                {
                                    if (ts == token2string[i])
                                        return i + FIRST_RESERVED;
                                }

                                seminfo.ts = ts;
                                return (int)RESERVED.TK_NAME;
                            }
                            else
                            {
                                int c = LS.current;
                                if (Char.IsControl((char)c))
                                    luaX_error(LS, "invalid control char",
                                        string.Format("char(0})", c));
                                next(LS);
                                return c;  /* single-char tokens (+ - / ...) */
                            }
                            //break;
                        }
                }
            }//for (;;) {
        }