예제 #1
0
        public virtual void AppendToken(Token token)
        {
            if (token == null)
            {
                return;
            }

            mTokens.Add(token);
        }
        protected override bool OnComplete()
        {
            this.Context.NextPos();

            var tmpToken = new Token();

            tmpToken.Text = this.Text;

            tmpToken.TokenType = TokenKind.String;

            tmpToken.Line = mBeginLine;
            tmpToken.Pos = mBeginPos;

            this.Context.AppendToken(tmpToken);

            return true;
        }
예제 #3
0
        protected override bool OnComplete()
        {
            var tmpToken = new Token();

            tmpToken.Text = this.Text;

            if(this.IsDigitsOnly)
            {
                tmpToken.TokenType = TokenKind.Number;
            }else{
                tmpToken.TokenType = TokenKind.Name;
            }

            tmpToken.Line = mBeginLine;
            tmpToken.Pos = mBeginPos;

            this.Context.AppendToken(tmpToken);

            return true;
        }
예제 #4
0
        protected override ResultOfProcess ProcessChar(int c, Char ch)
        {
            if (Char.IsLetterOrDigit(ch) || ch == '_')
            {
                this.Context.Recovery(c);

                var tmpNameOrDigitLeaf = new NameOrDigitLeaf(this.Context);

                return tmpNameOrDigitLeaf.Run();
            }

            if(ch == '.')
            {
                this.Context.NextPos();

                var tmpToken = new Token();

                tmpToken.TokenType = TokenKind.Point;
                tmpToken.Text = ".";

                tmpToken.Line = this.Context.CurrLine;
                tmpToken.Pos = this.Context.CurrPos;

                this.Context.AppendToken(tmpToken);

                return ResultOfProcess.Continue;
            }

            if(ch == ',')
            {
                this.Context.NextPos();

                var tmpToken = new Token();

                tmpToken.TokenType = TokenKind.Comma;
                tmpToken.Text = ",";

                tmpToken.Line = this.Context.CurrLine;
                tmpToken.Pos = this.Context.CurrPos;

                this.Context.AppendToken(tmpToken);

                return ResultOfProcess.Continue;
            }

            if(ch == '"')
            {
                var tmpTwoQuotesStringLeaf = new TwoQuotesStringLeaf(this.Context);

                return tmpTwoQuotesStringLeaf.Run();
            }

            if(ch == ';')
            {
                this.Context.NextPos();

                var tmpToken = new Token();

                tmpToken.TokenType = TokenKind.Semicolon;
                tmpToken.Text = ";";

                tmpToken.Line = this.Context.CurrLine;
                tmpToken.Pos = this.Context.CurrPos;

                this.Context.AppendToken(tmpToken);

                return ResultOfProcess.Continue;
            }

            if(ch == '(')
            {
                this.Context.NextPos();

                var tmpToken = new Token();

                tmpToken.TokenType = TokenKind.OPEN_ROUND_BRACKET;
                tmpToken.Text = "(";

                tmpToken.Line = this.Context.CurrLine;
                tmpToken.Pos = this.Context.CurrPos;

                this.Context.AppendToken(tmpToken);

                return ResultOfProcess.Continue;
            }

            if(ch == ')')
            {
                this.Context.NextPos();

                var tmpToken = new Token();

                tmpToken.TokenType = TokenKind.CLOSE_ROUND_BRACKET;
                tmpToken.Text = ")";

                tmpToken.Line = this.Context.CurrLine;
                tmpToken.Pos = this.Context.CurrPos;

                this.Context.AppendToken(tmpToken);

                return ResultOfProcess.Continue;
            }

            if(c == 13)
            {
                return ResultOfProcess.Continue;
            }

            if (c == 10)
            {
                this.Context.NextLine();

                return ResultOfProcess.Continue;
            }

            if(ch == ' ')
            {
                this.Context.NextPos();

                return ResultOfProcess.Continue;
            }

            this.Context.NextPos();

            var tmpSb = new StringBuilder();

            tmpSb.Append("Unexpected symbol \"");
            tmpSb.Append(ch);
            tmpSb.Append("\"");

            var tmpExcept = new LexerException(tmpSb.ToString());

            tmpExcept.Line = this.Context.CurrLine;
            tmpExcept.Pos = this.Context.CurrPos;

            NLog.LogManager.GetCurrentClassLogger().Info(ch.ToString());

            tmpExcept.TokenText = ch.ToString();

            throw tmpExcept;
        }