SUGAR_P() public method

public SUGAR_P ( ReportLevel pe, LineInfo line, int lpos, string format ) : uint
pe ReportLevel
line LineInfo
lpos int
format string
return uint
Exemplo n.º 1
0
 // static kbool_t Stmt_parseSyntaxRule(CTX, kStmt *stmt, kArray *tls, int s, int e)
 public bool parseSyntaxRule(Context ctx, IList<Token> tls, int s, int e)
 {
     bool ret = false;
     Syntax syn = this.ks.GetSyntaxRule(tls, s, e);
     //Debug.Assert(syn != null);
     if (syn != null && syn.SyntaxRule != null)
     {
         this.syn = syn;
         ret = (matchSyntaxRule(ctx, syn.SyntaxRule, this.ULine, tls, s, e, false) != -1);
     }
     else
     {
         ctx.SUGAR_P(ReportLevel.ERR, this.ULine, 0, "undefined syntax rule for '{0}'", syn.KeyWord.ToString());
     }
     return ret;
 }
Exemplo n.º 2
0
 // static kExpr* Stmt_newExpr2(CTX, kStmt *stmt, kArray *tls, int s, int e)
 public KonohaExpr newExpr2(Context ctx, IList<Token> tls, int s, int e)
 {
     if(s < e) {
         Syntax syn = null;
         int idx = findBinaryOp(ctx, tls, s, e, ref syn);
         if(idx != -1) {
             Console.WriteLine("** Found BinaryOp: s={0}, idx={1}, e={2}, '{3}' **", s, idx, e, tls[idx].Text);
             return ParseExpr(ctx, syn, tls, s, idx, e);
         }
         int c = s;
         syn = ks.GetSyntax(tls[c].Keyword);
         Debug.Assert(syn != null);
         return ParseExpr(ctx, syn, tls, c, c, e);
     }
     else {
         if (0 < s - 1) {
             ctx.SUGAR_P(ReportLevel.ERR, ULine, -1, "expected expression after {0}", tls[s-1].Text);
         }
         else if(e < tls.Count) {
             ctx.SUGAR_P(ReportLevel.ERR, ULine, -1, "expected expression before {0}", tls[e].Text);
         }
         else {
             ctx.SUGAR_P(ReportLevel.ERR, ULine, 0, "expected expression");
         }
         return null;
     }
 }
Exemplo n.º 3
0
 // static int matchSyntaxRule(CTX, kStmt *stmt, kArray *rules, kline_t /*parent*/uline, kArray *tls, int s, int e, int optional)
 public int matchSyntaxRule(Context ctx, IList<Token> rules, LineInfo /*parent*/uline, IList<Token> tls, int s, int e, bool optional)
 {
     int ri, ti, rule_size = rules.Count;
     ti = s;
     for (ri = 0; ri < rule_size && ti < e; ri++)
     {
         Token rule = rules[ri];
         Token tk = tls[ti];
         uline = tk.ULine;
         Console.WriteLine("matching rule={0},{1},{2} token={3},{4},{5}", ri, rule.Type, rule.Keyword, ti - s, tk.Type, tk.Text);
         if (rule.Type == TokenType.CODE)
         {
             if (rule.Keyword != tk.Keyword)
             {
                 if (optional)
                 {
                     return s;
                 }
                 tk.Print(ctx, ReportLevel.ERR, "{0} needs '{1}'", this.syn.KeyWord, rule.Keyword);
                 return -1;
             }
             ti++;
             continue;
         }
         else if (rule.Type == TokenType.METANAME)
         {
             Syntax syn = this.ks.GetSyntax(rule.Keyword);
             if (syn == null || syn.ParseStmt == null)
             {
                 tk.Print(ctx, ReportLevel.ERR, "unknown syntax pattern: {0}", rule.Keyword);
                 return -1;
             }
             int c = e;
             if (ri + 1 < rule_size && rules[ri + 1].Type == TokenType.CODE)
             {
                 c = lookAheadKeyword(tls, ti + 1, e, rules[ri + 1]);
                 if (c == -1)
                 {
                     if (optional)
                     {
                         return s;
                     }
                     tk.Print(ctx, ReportLevel.ERR, "{0} needs '{1}'", this.syn.KeyWord, rule.Keyword);
                     return -1;
                 }
                 ri++;
             }
             int err_count = ctx.ctxsugar.err_count;
             int next = ParseStmt(ctx, syn, rule.nameid, tls, ti, c);
             Console.WriteLine("matched '{0}' nameid='{1}', next={2}=>{3}", rule.Keyword, rule.nameid.Name, ti, next);
             if (next == -1)
             {
                 if (optional)
                 {
                     return s;
                 }
                 if (err_count == ctx.sugarerr_count)
                 {
                     tk.Print(ctx, ReportLevel.ERR, "unknown syntax pattern: {0}", this.syn.KeyWord, rule.Keyword, tk.Text);
                 }
                 return -1;
             }
             ////XXX Why???
             //optional = 0;
             ti = (c == e) ? next : c + 1;
             continue;
         }
         else if (rule.Type == TokenType.AST_OPTIONAL)
         {
             int next = matchSyntaxRule(ctx, rule.Sub, uline, tls, ti, e, true);
             if (next == -1)
             {
                 return -1;
             }
             ti = next;
             continue;
         }
         else if (rule.Type == TokenType.AST_PARENTHESIS || rule.Type == TokenType.AST_BRACE || rule.Type == TokenType.AST_BRANCET)
         {
             if (tk.Type == rule.Type && rule.TopChar == tk.TopChar)
             {
                 int next = matchSyntaxRule(ctx, rule.Sub, uline, tk.Sub, 0, tk.Sub.Count, false);
                 if (next == -1)
                 {
                     return -1;
                 }
                 ti++;
             }
             else
             {
                 if (optional)
                 {
                     return s;
                 }
                 tk.Print(ctx, ReportLevel.ERR, "{0} needs '{1}'", this.syn.KeyWord, rule.TopChar);
                 return -1;
             }
         }
     }
     if (!optional)
     {
         for (; ri < rules.Count; ri++)
         {
             Token rule = rules[ri];
             if (rule.Type != TokenType.AST_OPTIONAL)
             {
                 ctx.SUGAR_P(ReportLevel.ERR, uline, -1, "{0} needs syntax pattern: {1}", this.syn.KeyWord, rule.Keyword);
                 return -1;
             }
         }
         //WARN_Ignored(_ctx, tls, ti, e);
     }
     return ti;
 }
Exemplo n.º 4
0
 // ast.h
 // static KMETHOD UndefinedParseExpr(CTX, ksfp_t *sfp _RIX)
 public static KonohaExpr UndefinedParseExpr(Context ctx, Syntax syn, KStatement stmt, IList<Token> tls, int start, int c, int end)
 {
     Token tk = tls[c];
     ctx.SUGAR_P(ReportLevel.ERR, tk.ULine, 0, "undefined expression parser for '{0}'", tk.Text);
     return null;
 }
Exemplo n.º 5
0
 internal Token ResolveType(Context ctx, Token tkP)
 {
     int i;
     // 型引数の取得
     int size = tkP.Sub.Count;
     var p = new List<KonohaParam>();
     for (i = 0; i < size; i++)
     {
         Token tkT = (tkP.Sub[i]);
         if (tkT.Keyword == KeywordType.Type)
         {
             p.Add(new KonohaParam() { Type = tkT.Type });
         }
     }
     throw new NotImplementedException();
     // 以下未実装
     KonohaClass ct;
     if (p.Count > 0)
     {
         ct = null;// this.ctx.share.ca.cts[(int)this.Type];
         if (ct.cparam == KonohaParam.NULL)
         {
             ctx.SUGAR_P(ReportLevel.ERR, this.ULine, 0, "not generic type: %s", this.KType.ToString());
             return this;
         }
         //ct = kClassTable_Generics(ct, TY_void, p.Count, p);
     }
     else
     {
         //ct = CT_P0(_ctx, CT_Array, this_type(this));
     }
     this.Type = (TokenType)ct.cid;
     return this;
 }
Exemplo n.º 6
0
 public void Print(Context ctx, ReportLevel pe, string fmt, params object[] ap)
 {
     ctx.SUGAR_P(pe, this.ULine, 0, fmt, ap);
 }