Package org.antlr.v4.tool

Examples of org.antlr.v4.tool.Grammar


  @ModelElement public Action header;

  public ListenerFile(OutputModelFactory factory, String fileName) {
    super(factory, fileName);
    Grammar g = factory.getGrammar();
    parserName = g.getRecognizerName();
    grammarName = g.name;
    for (Rule r : g.rules.values()) {
      Map<String, List<Pair<Integer,AltAST>>> labels = r.getAltLabels();
      if ( labels!=null ) {
        for (Map.Entry<String, List<Pair<Integer, AltAST>>> pair : labels.entrySet()) {
View Full Code Here


  @ModelElement public Map<String, Action> namedActions;

  public LexerFile(OutputModelFactory factory, String fileName) {
    super(factory, fileName);
    namedActions = new HashMap<String, Action>();
    Grammar g = factory.getGrammar();
    for (String name : g.namedActions.keySet()) {
      ActionAST ast = g.namedActions.get(name);
      namedActions.put(name, new Action(factory, ast));
    }
    genPackage = factory.getGrammar().tool.genPackage;
View Full Code Here

    new LinkedHashMap<Rule, RuleSempredFunction>();

  public Recognizer(OutputModelFactory factory) {
    super(factory);

    Grammar g = factory.getGrammar();
    grammarFileName = new File(g.fileName).getName();
    grammarName = g.name;
    name = g.getRecognizerName();
    tokens = new LinkedHashMap<String,Integer>();
    for (Map.Entry<String, Integer> entry : g.tokenNameToTypeMap.entrySet()) {
      Integer ttype = entry.getValue();
      if ( ttype>0 ) {
        tokens.put(entry.getKey(), ttype);
      }
    }

    ruleNames = g.rules.keySet();
    rules = g.rules.values();
    atn = new SerializedATN(factory, g.atn);
    if (g.getOptionString("superClass") != null) {
      superClass = new ActionText(null, g.getOptionString("superClass"));
    }
    else {
      superClass = null;
    }

    CodeGenerator gen = factory.getGenerator();
    tokenNames = translateTokenStringsToTarget(g.getTokenDisplayNames(), gen);
    literalNames = translateTokenStringsToTarget(g.getTokenLiteralNames(), gen);
    symbolicNames = translateTokenStringsToTarget(g.getTokenSymbolicNames(), gen);
  }
View Full Code Here

    public final String InputSymbolType;

    public OutputFile(OutputModelFactory factory, String fileName) {
        super(factory);
        this.fileName = fileName;
        Grammar g = factory.getGrammar();
    grammarFileName = g.fileName;
    ANTLRVersion = Tool.VERSION;
        TokenLabelType = g.getOptionString("TokenLabelType");
        InputSymbolType = TokenLabelType;
    }
View Full Code Here

  public Lexer(OutputModelFactory factory, LexerFile file) {
    super(factory);
    this.file = file; // who contains us?

    Grammar g = factory.getGrammar();
    channels = new LinkedHashMap<String, Integer>(g.channelNameToValueMap);
    modes = ((LexerGrammar)g).modes.keySet();
  }
View Full Code Here

        "s8->RuleStop_a_1\n" +
        "RuleStop_a_1-EOF->s9\n";
    checkRuleATN(g, "a", expecting);
  }
  @Test public void testAorBorEmptyPlus() throws Exception {
    Grammar g = new Grammar(
      "parser grammar P;\n"+
      "a : (A | B | )+ ;");
    String expecting =
      "RuleStart_a_0->PlusBlockStart_5\n" +
        "PlusBlockStart_5->s2\n" +
View Full Code Here

        "s8->RuleStop_a_1\n" +
        "RuleStop_a_1-EOF->s9\n";
    checkRuleATN(g, "a", expecting);
  }
  @Test public void testAStar() throws Exception {
    Grammar g = new Grammar(
      "parser grammar P;\n"+
      "a : A*;");
    String expecting =
      "RuleStart_a_0->StarLoopEntry_5\n" +
        "StarLoopEntry_5->StarBlockStart_3\n" +
View Full Code Here

        "BlockEnd_4->StarLoopBack_7\n" +
        "StarLoopBack_7->StarLoopEntry_5\n";
    checkRuleATN(g, "a", expecting);
  }
  @Test public void testNestedAstar() throws Exception {
    Grammar g = new Grammar(
      "parser grammar P;\n"+
      "a : (COMMA ID*)*;");
    String expecting =
      "RuleStart_a_0->StarLoopEntry_11\n" +
        "StarLoopEntry_11->StarBlockStart_9\n" +
View Full Code Here

        "StarLoopBack_13->StarLoopEntry_11\n" +
        "StarLoopBack_8->StarLoopEntry_6\n";
    checkRuleATN(g, "a", expecting);
  }
  @Test public void testAorBstar() throws Exception {
    Grammar g = new Grammar(
      "parser grammar P;\n"+
      "a : (A | B{;})* ;");
    String expecting =
      "RuleStart_a_0->StarLoopEntry_7\n" +
        "StarLoopEntry_7->StarBlockStart_5\n" +
View Full Code Here

        "s4-action_0:-1->BlockEnd_6\n" +
        "StarLoopBack_9->StarLoopEntry_7\n";
    checkRuleATN(g, "a", expecting);
  }
  @Test public void testPredicatedAorB() throws Exception {
    Grammar g = new Grammar(
      "parser grammar P;\n"+
      "a : {p1}? A | {p2}? B ;");
    String expecting =
      "RuleStart_a_0->BlockStart_6\n" +
        "BlockStart_6->s2\n" +
View Full Code Here

TOP

Related Classes of org.antlr.v4.tool.Grammar

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.