IronKonoha.Token.toERR C# (CSharp) Method

toERR() public method

public toERR ( Context ctx, uint errorcode ) : void
ctx Context
errorcode uint
return void
        public void toERR(Context ctx, uint errorcode)
        {
            this.Type = TokenType.ERR;
            this.Text = ctx.ctxsugar.errors.strings[(int)errorcode];
        }

Usage Example

Exemplo n.º 1
0
        // static int makeTree(CTX, kKonohaSpace *ks, ktoken_t tt, kArray *tls, int s, int e, int closech, kArray *tlsdst, kToken **tkERRRef)
        private int makeTree(TokenType tokentype, IList<Token> tokens, int start, int end, char closeChar, IList<Token> tokensDst, out Token errorToken)
        {
            int i, probablyCloseBefore = end - 1;
            Token tk = tokens[start];
            Debug.Assert(tk.Keyword == 0);

            Token tkP = new Token(tokentype, tk.Text, closeChar) { Keyword = (KeywordType)tokentype };
            tokensDst.Add(tkP);
            tkP.Sub = new List<Token>();
            for (i = start + 1; i < end; i++)
            {
                tk = tokens[i];
                Debug.Assert(tk.Keyword == 0);
                if (tk.Type == TokenType.ERR)
                    break;  // ERR
                Debug.Assert(tk.TopChar != '{');
                if (tk.TopChar == '(')
                {
                    i = makeTree(TokenType.AST_PARENTHESIS, tokens, i, end, ')', tkP.Sub, out errorToken);
                    tk.Keyword = KeywordType.Parenthesis;
                    continue;
                }
                else if (tk.TopChar == '[')
                {
                    i = makeTree(TokenType.AST_BRANCET, tokens, i, end, ']', tkP.Sub, out errorToken);
                    tk.Keyword = KeywordType.Brancet;
                    continue;
                }
                else if (tk.TopChar == closeChar)
                {
                    errorToken = null;
                    return i;
                }
                if ((closeChar == ')' || closeChar == ']') && tk.Type == TokenType.CODE)
                    probablyCloseBefore = i;
                if (tk.Type == TokenType.INDENT && closeChar != '}')
                    continue;  // remove INDENT;
                i = appendKeyword(tokens, i, end, tkP.Sub, out errorToken);
            }
            if (tk.Type != TokenType.ERR)
            {
                uint errref = ctx.SUGAR_P(ReportLevel.ERR, tk.ULine, 0, "'{0}' is expected (probably before {1})", closeChar.ToString(), tokens[probablyCloseBefore].Text);
                tkP.toERR(this.ctx, errref);
            }
            else
            {
                tkP.Type = TokenType.ERR;
            }
            errorToken = tkP;
            return end;
        }