/** Useful for when you are sure that you are not part of a composite * already. Used in Interp/RandomPhrase and testing. */ public Grammar() { builtFromString = true; composite = new CompositeGrammar(this); }
@SuppressWarnings("OverridableMethodCallInConstructor") public CompositeGrammar(Grammar g) { this(); setDelegationRoot(g); }
public void minimizeRuleSet() { Set<String> ruleDefs = new HashSet<String>(); _minimizeRuleSet(ruleDefs, delegateGrammarTreeRoot); }
/** Get delegates below direct delegates of g */ public List<Grammar> getIndirectDelegates(Grammar g) { List<Grammar> direct = getDirectDelegates(g); List<Grammar> delegates = getDelegates(g); if ( direct!=null ) { delegates.removeAll(direct); } return delegates; }
public void setGrammarContent(String grammarString) throws RecognitionException { StringReader r = new StringReader(grammarString); parseAndBuildAST(r); composite.assignTokenTypes(); composite.defineGrammarSymbols(); }
random = new Random(seed); CompositeGrammar composite = new CompositeGrammar(); Tool tool = new Tool(); Grammar parser = new Grammar(tool, grammarFileName, composite); composite.setDelegationRoot(parser); br.close(); parser.composite.assignTokenTypes(); parser.composite.defineGrammarSymbols(); parser.composite.createNFAs();
grammar.composite.assignTokenTypes(); grammar.composite.defineGrammarSymbols(); grammar.composite.createNFAs(); lexerGrammar.composite.assignTokenTypes(); lexerGrammar.composite.defineGrammarSymbols(); lexerGrammar.composite.createNFAs();
/** * Return a list of File objects that name files ANTLR will read * to process T.g; This can be .tokens files if the grammar uses the tokenVocab option * as well as any imported grammar files. */ public List<File> getDependenciesFileList() { // Find all the things other than imported grammars List<File> files = getNonImportDependenciesFileList(); // Handle imported grammars List<Grammar> imports = grammar.composite.getDelegates(grammar.composite.getRootGrammar()); for (Grammar g : imports) { String libdir = tool.getLibraryDirectory(); String fileName = groomQualifiedFileName(libdir, g.fileName); files.add(new File(fileName)); } if (files.isEmpty()) { return null; } return files; }
CompositeGrammar composite = new CompositeGrammar(); Grammar grammar = new Grammar(this, grammarFileName, composite); composite.setDelegationRoot(grammar); FileReader fr; File f;
/** Get list of all delegates from all grammars directly or indirectly * imported into this grammar. */ public List<Grammar> getDelegates() { return composite.getDelegates(this); }
/** Get set of all rules imported from all delegate grammars even if * indirectly delegated. */ public Set<? extends Rule> getAllImportedRules() { return composite.getAllImportedRules(this); }
private Grammar createLexerGrammarFromCombinedGrammar(Grammar grammar) throws Exception { String lexerGrammarStr = grammar.getLexerGrammar(); if(lexerGrammarStr == null) return null; Grammar lexerGrammar = new Grammar(); lexerGrammar.implicitLexer = true; lexerGrammar.setTool(engine.getANTLRTool()); lexerGrammar.setFileName("<internally-generated-lexer>"); lexerGrammar.importTokenVocabulary(grammar); lexerGrammar.setGrammarContent(lexerGrammarStr); lexerGrammar.composite.createNFAs(); return lexerGrammar; }
public void addState(NFAState state) { grammar.composite.addState(state); }
/** Get the set of Rules that need to have manual delegations * like "void rule() { importedGrammar.rule(); }" * * If this grammar is master, get list of all rule definitions from all * delegate grammars. Only master has complete interface from combined * grammars...we will generated delegates as helper objects. * * Composite grammars that are not the root/master do not have complete * interfaces. It is not my intention that people use subcomposites. * Only the outermost grammar should be used from outside code. The * other grammar components are specifically generated to work only * with the master/root. * * delegatedRules = imported - overridden */ public Set<? extends Rule> getDelegatedRules() { return composite.getDelegatedRules(this); }
/** Used for testing and Interp/RandomPhrase. Only useful on * noncomposite grammars. */ public Grammar(Tool tool, String grammarString) throws antlr.RecognitionException { this(); setTool(tool); setFileName("<string>"); StringReader r = new StringReader(grammarString); parseAndBuildAST(r); composite.assignTokenTypes(); defineGrammarSymbols(); checkNameSpaceAndActions(); }
random = new Random(seed); CompositeGrammar composite = new CompositeGrammar(); Tool tool = new Tool(); Grammar parser = new Grammar(tool, grammarFileName, composite); composite.setDelegationRoot(parser); br.close(); parser.composite.assignTokenTypes(); parser.composite.defineGrammarSymbols(); parser.composite.createNFAs();
grammar.composite.assignTokenTypes(); grammar.composite.defineGrammarSymbols(); grammar.composite.createNFAs(); lexerGrammar.composite.assignTokenTypes(); lexerGrammar.composite.defineGrammarSymbols(); lexerGrammar.composite.createNFAs();
/** * Return a list of File objects that name files ANTLR will read * to process T.g; This can be .tokens files if the grammar uses the tokenVocab option * as well as any imported grammar files. */ public List<File> getDependenciesFileList() { // Find all the things other than imported grammars List<File> files = getNonImportDependenciesFileList(); // Handle imported grammars List<Grammar> imports = grammar.composite.getDelegates(grammar.composite.getRootGrammar()); for (Grammar g : imports) { String libdir = tool.getLibraryDirectory(); String fileName = groomQualifiedFileName(libdir, g.fileName); files.add(new File(fileName)); } if (files.isEmpty()) { return null; } return files; }
CompositeGrammar composite = new CompositeGrammar(); Grammar grammar = new Grammar(this, grammarFileName, composite); composite.setDelegationRoot(grammar); FileReader fr; File f;
public void setGrammarContent(String grammarString) throws RecognitionException { StringReader r = new StringReader(grammarString); parseAndBuildAST(r); composite.assignTokenTypes(); composite.defineGrammarSymbols(); }