internal int TestBlockAsSet(GrammarAST t) { Rule r = grammar.GetLocallyDefinedRule(currentRuleName); if (r.HasRewrite(outerAltNum)) { return(-1); } TreeToNFAConverter other = new TreeToNFAConverter(grammar, nfa, factory, new CommonTreeNodeStream(t)); other.state.backtracking++; other.currentRuleName = currentRuleName; other.outerAltNum = outerAltNum; other.blockLevel = blockLevel; var result = other.testBlockAsSet(); if (other.state.failed) { return(-1); } return(result); }
public IIntSet SetRule(GrammarAST t) { TreeToNFAConverter other = new TreeToNFAConverter(grammar, nfa, factory, new CommonTreeNodeStream(t)); other.currentRuleName = currentRuleName; other.outerAltNum = outerAltNum; other.blockLevel = blockLevel; return(other.setRule()); }
public int TestSetRule( GrammarAST t ) { TreeToNFAConverter other = new TreeToNFAConverter( grammar, nfa, factory, new CommonTreeNodeStream( t ) ); other.state.backtracking++; other.currentRuleName = currentRuleName; other.outerAltNum = outerAltNum; other.blockLevel = blockLevel; var result = other.testSetRule(); if ( other.state.failed ) state.failed = true; return result; }
public virtual bool IsValidSet(TreeToNFAConverter nfabuilder, GrammarAST t) { bool valid = true; try { //[email protected]("parse BLOCK as set tree: "+t.toStringTree()); int alts = nfabuilder.TestBlockAsSet( t ); valid = ( alts > 1 ); } catch ( RecognitionException /*re*/ ) { // The rule did not parse as a set, return false; ignore exception valid = false; } //[email protected]("valid? "+valid); return valid; }
public virtual IIntSet GetSetFromRule(TreeToNFAConverter nfabuilder, string ruleName) { Rule r = GetRule( ruleName ); if ( r == null ) { return null; } IIntSet elements = null; //[email protected]("parsed tree: "+r.tree.toStringTree()); elements = nfabuilder.SetRule( r.Tree ); //[email protected]("elements="+elements); return elements; }
public virtual void BuildNFA() { if ( nfa == null ) { CreateRuleStartAndStopNFAStates(); } if ( nfa.Complete ) { // don't let it create more than once; has side-effects return; } //[email protected]("### build "+getGrammarTypeString()+" grammar "+name+" NFAs"); if ( Rules.Count == 0 ) { return; } Antlr.Runtime.Tree.ITreeNodeStream input = new Antlr.Runtime.Tree.CommonTreeNodeStream( grammarTree ); TreeToNFAConverter nfaBuilder = new TreeToNFAConverter( this, nfa, factory, input ); try { nfaBuilder.grammar_(); } catch ( RecognitionException re ) { ErrorManager.Error( ErrorManager.MSG_BAD_AST_STRUCTURE, name, re ); } nfa.Complete = true; }
internal int TestBlockAsSet( GrammarAST t ) { Rule r = grammar.GetLocallyDefinedRule( currentRuleName ); if ( r.HasRewrite( outerAltNum ) ) return -1; TreeToNFAConverter other = new TreeToNFAConverter( grammar, nfa, factory, new CommonTreeNodeStream( t ) ); other.state.backtracking++; other.currentRuleName = currentRuleName; other.outerAltNum = outerAltNum; other.blockLevel = blockLevel; var result = other.testBlockAsSet(); if ( other.state.failed ) return -1; return result; }
public IIntSet SetRule( GrammarAST t ) { TreeToNFAConverter other = new TreeToNFAConverter( grammar, nfa, factory, new CommonTreeNodeStream( t ) ); other.currentRuleName = currentRuleName; other.outerAltNum = outerAltNum; other.blockLevel = blockLevel; return other.setRule(); }