Пример #1
0
 private boolean makeSyntaxRule(CTX ctx, List<Token> tls, int s, int e, List<Token> adst) {
   String nameid = null;
   for (int i = s; i < e; i++) {
     Token tk = tls.get(i);
     if (tk.tt == TK.INDENT) continue;
     if (tk.tt == TK.TEXT) {
       int[] ia = new int[] {i};
       if (checkNestedSyntax(ctx, tls, ia, e, TK.AST_PARENTHESIS, '(', ')')
           || checkNestedSyntax(ctx, tls, ia, e, TK.AST_BRANCET, '[', ']')
           || checkNestedSyntax(ctx, tls, ia, e, TK.AST_BRACE, '{', '}')) {
         i = ia[0];
       } else {
         tk.tt = TK.CODE;
         tk.kw = tk.text;
       }
       adst.add(tk);
       continue;
     }
     if (tk.tt == TK.SYMBOL || tk.tt == TK.USYMBOL) {
       if (i > 0 && tls.get(i - 1).topch == '$') {
         tk.kw = "$" + tk.text;
         tk.tt = TK.METANAME;
         if (nameid == null) nameid = tk.kw;
         tk.nameid = nameid;
         nameid = null;
         adst.add(tk);
         continue;
       }
       if (i + 1 < e && tls.get(i + 1).topch == ':') {
         nameid = tls.get(i).text;
         i++;
         continue;
       }
     }
     if (tk.tt == TK.OPERATOR) {
       int[] ia = new int[] {i};
       if (checkNestedSyntax(ctx, tls, ia, e, TK.AST_OPTIONAL, '[', ']')) {
         adst.add(tk);
         i = ia[0];
         continue;
       }
       if (tls.get(i).topch == '$') continue;
     }
     return false;
   }
   return true;
 }
Пример #2
0
 private boolean checkNestedSyntax(
     CTX ctx, List<Token> tls, int[] s, int e, int tt, int opench, int closech) {
   int i = s[0];
   Token tk = tls.get(i);
   String t = tk.text;
   if (t.length() == 1 && t.charAt(0) == opench) {
     int ne = findTopCh(ctx, tls, i + 1, e, tk.tt, closech);
     tk.tt = tt;
     if (tt >= 0 && tt < KW.TK_KW.length) tk.kw = KW.TK_KW[tt];
     tk.sub = new ArrayList<Token>();
     tk.topch = opench;
     tk.closech = closech;
     makeSyntaxRule(ctx, tls, i + 1, ne, tk.sub);
     s[0] = ne;
     return true;
   }
   return false;
 }