/** add new delegate to composite tree */ protected void addDelegateGrammar(Grammar delegateGrammar) { CompositeGrammarTree t = composite.delegateGrammarTreeRoot.findNode(this); t.addChild(new CompositeGrammarTree(delegateGrammar)); // make sure new grammar shares this composite delegateGrammar.composite = this.composite; }
/** Return a postorder list of grammars; root is last in list */ public List<Grammar> getPostOrderedGrammarList() { List<Grammar> grammars = new ArrayList<Grammar>(); _getPostOrderedGrammarList(grammars); return grammars; }
/** Return a preorder list of grammars; root is first in list */ public List<Grammar> getPreOrderedGrammarList() { List<Grammar> grammars = new ArrayList<Grammar>(); _getPreOrderedGrammarList(grammars); return grammars; }
/** Add delegate grammar as child of delegator */ public void addGrammar(Grammar delegator, Grammar delegate) { if ( delegator.compositeTreeNode==null ) { delegator.compositeTreeNode = new CompositeGrammarTree(delegator); } delegator.compositeTreeNode.addChild(new CompositeGrammarTree(delegate)); /*// find delegator in tree so we can add a child to it CompositeGrammarTree t = delegateGrammarTreeRoot.findNode(delegator); t.addChild(); */ // make sure new grammar shares this composite delegate.composite = this; }
/** Get list of all delegates from all grammars in the delegate subtree of g. * The grammars are in delegation tree preorder. Don't include g itself * in list as it is not a delegate of itself. */ public List<Grammar> getDelegates(Grammar g) { CompositeGrammarTree t = delegateGrammarTreeRoot.findNode(g); if ( t==null ) { return null; // no delegates } List<Grammar> grammars = t.getPostOrderedGrammarList(); grammars.remove(grammars.size()-1); // remove g (last one) return grammars; }
/** Get parent of this grammar */ public Grammar getDelegator(Grammar g) { CompositeGrammarTree me = delegateGrammarTreeRoot.findNode(g); if ( me==null ) { return null; // not found } if ( me.parent!=null ) { return me.parent.grammar; } return null; }
public void defineGrammarSymbols() { delegateGrammarTreeRoot.trimLexerImportsIntoCombined(); List<Grammar> grammars = delegateGrammarTreeRoot.getPostOrderedGrammarList(); for (int i = 0; grammars!=null && i < grammars.size(); i++) { Grammar g = (Grammar)grammars.get(i); g.defineGrammarSymbols(); } for (int i = 0; grammars!=null && i < grammars.size(); i++) { Grammar g = (Grammar)grammars.get(i); g.checkNameSpaceAndActions(); } minimizeRuleSet(); }
public void createNFAs() { if ( ErrorManager.doNotAttemptAnalysis() ) { return; } List<Grammar> grammars = delegateGrammarTreeRoot.getPostOrderedGrammarList(); List<String> names = new ArrayList<String>(); for (int i = 0; i < grammars.size(); i++) { Grammar g = (Grammar) grammars.get(i); names.add(g.name); } //System.out.println("### createNFAs for composite; grammars: "+names); for (int i = 0; grammars!=null && i < grammars.size(); i++) { Grammar g = (Grammar)grammars.get(i); g.createRuleStartAndStopNFAStates(); } for (int i = 0; grammars!=null && i < grammars.size(); i++) { Grammar g = (Grammar)grammars.get(i); g.buildNFA(); } }
/** Get all rule definitions from all direct/indirect delegate grammars * of g. */ public Set<? extends Rule> getAllImportedRules(Grammar g) { Set<String> ruleNames = new HashSet<String>(); Set<Rule> rules = new HashSet<Rule>(); CompositeGrammarTree subtreeRoot = delegateGrammarTreeRoot.findNode(g); List<Grammar> grammars = subtreeRoot.getPreOrderedGrammarList(); // walk all grammars preorder, priority given to grammar listed first. for (int i = 0; i < grammars.size(); i++) { Grammar delegate = grammars.get(i); // for each rule in delegate, add to rules if no rule with that // name as been seen. (can't use removeAll; wrong hashcode/equals on Rule) for (Rule r : delegate.getRules()) { if ( !ruleNames.contains(r.name) ) { ruleNames.add(r.name); // track that we've seen this rules.add(r); } } } return rules; }
public Rule getRule(String ruleName) { return delegateGrammarTreeRoot.getRule(ruleName); }
public Object getOption(String key) { return delegateGrammarTreeRoot.getOption(key); }
public void setDelegationRoot(Grammar root) { delegateGrammarTreeRoot = new CompositeGrammarTree(root); root.compositeTreeNode = delegateGrammarTreeRoot; }
public void trimLexerImportsIntoCombined() { CompositeGrammarTree p = this; if ( p.grammar.type == Grammar.LEXER && p.parent!=null && p.parent.grammar.type == Grammar.COMBINED ) { //System.out.println("wacking "+p.grammar.name+" from "+p.parent.grammar.name); p.parent.children.remove(this); } for (int i = 0; children!=null && i < children.size(); i++) { CompositeGrammarTree child = children.get(i); child.trimLexerImportsIntoCombined(); } } }
/** Get parent of this grammar */ public Grammar getDelegator(Grammar g) { CompositeGrammarTree me = delegateGrammarTreeRoot.findNode(g); if ( me==null ) { return null; // not found } if ( me.parent!=null ) { return me.parent.grammar; } return null; }
/** Get list of all delegates from all grammars in the delegate subtree of g. * The grammars are in delegation tree preorder. Don't include g itself * in list as it is not a delegate of itself. */ public List<Grammar> getDelegates(Grammar g) { CompositeGrammarTree t = delegateGrammarTreeRoot.findNode(g); if ( t==null ) { return null; // no delegates } List<Grammar> grammars = t.getPostOrderedGrammarList(); grammars.remove(grammars.size()-1); // remove g (last one) return grammars; }
public void defineGrammarSymbols() { delegateGrammarTreeRoot.trimLexerImportsIntoCombined(); List<Grammar> grammars = delegateGrammarTreeRoot.getPostOrderedGrammarList(); for (int i = 0; grammars!=null && i < grammars.size(); i++) { Grammar g = grammars.get(i); g.defineGrammarSymbols(); } for (int i = 0; grammars!=null && i < grammars.size(); i++) { Grammar g = grammars.get(i); g.checkNameSpaceAndActions(); } minimizeRuleSet(); }
/** Add delegate grammar as child of delegator */ public void addGrammar(Grammar delegator, Grammar delegate) { if ( delegator.compositeTreeNode==null ) { delegator.compositeTreeNode = new CompositeGrammarTree(delegator); } delegator.compositeTreeNode.addChild(new CompositeGrammarTree(delegate)); /*// find delegator in tree so we can add a child to it CompositeGrammarTree t = delegateGrammarTreeRoot.findNode(delegator); t.addChild(); */ // make sure new grammar shares this composite delegate.composite = this; }
public void createNFAs() { if ( ErrorManager.doNotAttemptAnalysis() ) { return; } List<Grammar> grammars = delegateGrammarTreeRoot.getPostOrderedGrammarList(); //System.out.println("### createNFAs for composite; grammars: "+names); for (int i = 0; grammars!=null && i < grammars.size(); i++) { Grammar g = grammars.get(i); g.createRuleStartAndStopNFAStates(); } for (int i = 0; grammars!=null && i < grammars.size(); i++) { Grammar g = grammars.get(i); g.buildNFA(); } }
/** Get all rule definitions from all direct/indirect delegate grammars * of g. */ public Set<? extends Rule> getAllImportedRules(Grammar g) { Set<String> ruleNames = new HashSet<String>(); Set<Rule> rules = new HashSet<Rule>(); CompositeGrammarTree subtreeRoot = delegateGrammarTreeRoot.findNode(g); List<Grammar> grammars = subtreeRoot.getPreOrderedGrammarList(); // walk all grammars preorder, priority given to grammar listed first. for (int i = 0; i < grammars.size(); i++) { Grammar delegate = grammars.get(i); // for each rule in delegate, add to rules if no rule with that // name as been seen. (can't use removeAll; wrong hashcode/equals on Rule) for (Rule r : delegate.getRules()) { if ( !ruleNames.contains(r.name) ) { ruleNames.add(r.name); // track that we've seen this rules.add(r); } } } return rules; }
public Rule getRule(String ruleName) { return delegateGrammarTreeRoot.getRule(ruleName); }