Пример #1
0
 List<ANTLRMessage> getMessagesOfType(List<ANTLRMessage> msgs, Class c) {
   List<ANTLRMessage> filtered = new ArrayList<ANTLRMessage>();
   for (ANTLRMessage m : msgs) {
     if (m.getClass() == c) filtered.add(m);
   }
   return filtered;
 }
Пример #2
0
 public List<Integer> getTokenTypes(String input, LexerATNSimulator lexerATN) {
   ANTLRStringStream in = new ANTLRStringStream(input);
   List<Integer> tokenTypes = new ArrayList<Integer>();
   int ttype = 0;
   do {
     ttype = lexerATN.matchATN(in);
     tokenTypes.add(ttype);
   } while (ttype != Token.EOF);
   return tokenTypes;
 }
Пример #3
0
 List<Integer> getTypesFromString(Grammar g, String expecting) {
   List<Integer> expectingTokenTypes = new ArrayList<Integer>();
   if (expecting != null && !expecting.trim().equals("")) {
     for (String tname : expecting.replace(" ", "").split(",")) {
       int ttype = g.getTokenType(tname);
       expectingTokenTypes.add(ttype);
     }
   }
   return expectingTokenTypes;
 }
Пример #4
0
 public List<String> getTokenTypes(LexerGrammar lg, ATN atn, CharStream input, boolean adaptive) {
   LexerATNSimulator interp = new LexerATNSimulator(atn);
   List<String> tokenTypes = new ArrayList<String>();
   int ttype;
   do {
     if (adaptive) ttype = interp.match(input, Lexer.DEFAULT_MODE);
     else ttype = interp.matchATN(input);
     if (ttype == Token.EOF) tokenTypes.add("EOF");
     else {
       tokenTypes.add(lg.typeToTokenList.get(ttype));
     }
   } while (ttype != Token.EOF);
   return tokenTypes;
 }
Пример #5
0
 /** Return true if all is ok, no errors */
 protected boolean antlr(
     String fileName, String grammarFileName, String grammarStr, boolean debug) {
   boolean allIsWell = true;
   mkdir(tmpdir);
   writeFile(tmpdir, fileName, grammarStr);
   try {
     final List options = new ArrayList();
     if (debug) {
       options.add("-debug");
     }
     options.add("-o");
     options.add(tmpdir);
     options.add("-lib");
     options.add(tmpdir);
     options.add(new File(tmpdir, grammarFileName).toString());
     final String[] optionsA = new String[options.size()];
     options.toArray(optionsA);
     ErrorQueue equeue = new ErrorQueue();
     Tool antlr = newTool(optionsA);
     antlr.addListener(equeue);
     antlr.processGrammarsOnCommandLine();
     if (equeue.errors.size() > 0) {
       allIsWell = false;
       System.err.println("antlr reports errors from " + options);
       for (int i = 0; i < equeue.errors.size(); i++) {
         ANTLRMessage msg = (ANTLRMessage) equeue.errors.get(i);
         System.err.println(msg);
       }
       System.out.println("!!!\ngrammar:");
       System.out.println(grammarStr);
       System.out.println("###");
     }
   } catch (Exception e) {
     allIsWell = false;
     System.err.println("problems building grammar: " + e);
     e.printStackTrace(System.err);
   }
   return allIsWell;
 }
Пример #6
0
 public Token get(int i) {
   return new org.antlr.v4.runtime.CommonToken(types.get(i));
 }
Пример #7
0
 public Token LT(int i) {
   if ((p + i - 1) >= types.size()) return new CommonToken(-1);
   return new CommonToken(types.get(p + i - 1));
 }
Пример #8
0
 public int size() {
   return types.size();
 }