Package org.apache.dvsl

Examples of org.apache.dvsl.DVSLTask$Tool


      }
    }
    }

    protected org.antlr.v4.Tool newTool(String[] args) {
    Tool tool = new Tool(args);
    return tool;
  }
View Full Code Here


    Tool tool = new Tool(args);
    return tool;
  }

  protected Tool newTool() {
    org.antlr.v4.Tool tool = new Tool(new String[] {"-o", tmpdir});
    return tool;
  }
View Full Code Here

  }

  protected void semanticProcess(Grammar g) {
    if ( g.ast!=null && !g.ast.hasErrors ) {
      System.out.println(g.ast.toStringTree());
      Tool antlr = new Tool();
      SemanticPipeline sem = new SemanticPipeline(g);
      sem.process();
      if ( g.getImportedGrammars()!=null ) { // process imported grammars (if any)
        for (Grammar imp : g.getImportedGrammars()) {
          antlr.processNonCombinedGrammar(imp, false);
        }
      }
    }
  }
View Full Code Here

    }
    options.add(new File(tmpdir,grammarFileName).toString());

    final String[] optionsA = new String[options.size()];
    options.toArray(optionsA);
    Tool antlr = newTool(optionsA);
    ErrorQueue equeue = new ErrorQueue(antlr);
    antlr.addListener(equeue);
    if (defaultListener) {
      antlr.addListener(new DefaultToolListener(antlr));
    }
    antlr.processGrammarsOnCommandLine();

    if ( !defaultListener && !equeue.errors.isEmpty() ) {
      System.err.println("antlr reports errors from "+options);
      for (int i = 0; i < equeue.errors.size(); i++) {
        ANTLRMessage msg = equeue.errors.get(i);
View Full Code Here

  public ParserInterpreterForTesting(@NotNull Grammar g) {
    this.g = g;
  }

  public ParserInterpreterForTesting(@NotNull Grammar g, @NotNull TokenStream input) {
    Tool antlr = new Tool();
    antlr.process(g,false);
    parser = new DummyParser(g, g.atn, input);
    atnSimulator =
      new ParserATNSimulator(parser, g.atn, parser.decisionToDFA,
                      parser.sharedContextCache);
  }
View Full Code Here

    Map<String,Integer> tokens = new LinkedHashMap<String,Integer>();
    int maxTokenType = -1;
    File fullFile = getImportedVocabFile();
    FileInputStream fis = null;
    BufferedReader br = null;
    Tool tool = g.tool;
    String vocabName = g.getOptionString("tokenVocab");
    try {
      Pattern tokenDefPattern = Pattern.compile("([^\n]+?)[ \\t]*?=[ \\t]*?([0-9]+)");
      fis = new FileInputStream(fullFile);
      InputStreamReader isr;
      if (tool.grammarEncoding != null) {
        isr = new InputStreamReader(fis, tool.grammarEncoding);
      }
      else {
        isr = new InputStreamReader(fis);
      }

      br = new BufferedReader(isr);
      String tokenDef = br.readLine();
      int lineNum = 1;
      while ( tokenDef!=null ) {
        Matcher matcher = tokenDefPattern.matcher(tokenDef);
        if ( matcher.find() ) {
          String tokenID = matcher.group(1);
          String tokenTypeS = matcher.group(2);
          int tokenType;
          try {
            tokenType = Integer.valueOf(tokenTypeS);
          }
          catch (NumberFormatException nfe) {
            tool.errMgr.toolError(ErrorType.TOKENS_FILE_SYNTAX_ERROR,
                        vocabName + CodeGenerator.VOCAB_FILE_EXTENSION,
                        " bad token type: "+tokenTypeS,
                        lineNum);
            tokenType = Token.INVALID_TOKEN_TYPE;
          }
          tool.log("grammar", "import "+tokenID+"="+tokenType);
          tokens.put(tokenID, tokenType);
          maxTokenType = Math.max(maxTokenType,tokenType);
          lineNum++;
        }
        else {
View Full Code Here

  public Grammar(String fileName, String grammarText, Grammar tokenVocabSource, @Nullable ANTLRToolListener listener)
    throws org.antlr.runtime.RecognitionException
  {
        this.text = grammarText;
    this.fileName = fileName;
    this.tool = new Tool();
    this.tool.addListener(listener);
    org.antlr.runtime.ANTLRStringStream in = new org.antlr.runtime.ANTLRStringStream(grammarText);
    in.name = fileName;

    this.ast = tool.parse(fileName, in);
View Full Code Here

    return implicitLexer;
  }

  /** convenience method for Tool.loadGrammar() */
  public static Grammar load(String fileName) {
    Tool antlr = new Tool();
    return antlr.loadGrammar(fileName);
  }
View Full Code Here

      String gstr =
        "grammar U;\n"+
        "a : A;\n"+
        "A : a;\n";

      Tool tool = new Tool();
      tool.removeListeners();
      tool.addListener(errorQueue);
      assertEquals(0, errorQueue.size());
      GrammarRootAST grammarRootAST = tool.parseGrammarFromString(gstr);
      assertEquals(0, errorQueue.size());
      Grammar g = tool.createGrammar(grammarRootAST);
      assertEquals(0, errorQueue.size());
      g.fileName = "<string>";
      tool.process(g, false);
    }
    catch (Exception e) {
      threwException = true;
      e.printStackTrace();
    }
View Full Code Here

    this.out = out;
  }

  public String run(final String grammarFileName, final String startRule,
      final String inputText) {
    Tool antlr = new Tool();

    String combinedGrammarFileName = null;
    String lexerGrammarFileName = null;
    String parserGrammarFileName = null;

    // load to examine it
    Grammar g = antlr.loadGrammar(grammarFileName);

    // examine's Grammar AST from v4 itself;
    // hence use ANTLRParser.X not ANTLRv4Parser from this plugin
    switch (g.getType()) {
      case ANTLRParser.PARSER:
View Full Code Here

TOP

Related Classes of org.apache.dvsl.DVSLTask$Tool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.