public String getErrorMessage(RecognitionException e, String[] tokenNames) { if ( e instanceof SemanticException ) { return e.getMessage(); } else { return super.getErrorMessage(e, tokenNames); } }
/** Check if current node in input has a context. Context means sequence * of nodes towards root of tree. For example, you might say context * is "MULT" which means my parent must be MULT. "CLASS VARDEF" says * current node must be child of a VARDEF and whose parent is a CLASS node. * You can use "..." to mean zero-or-more nodes. "METHOD ... VARDEF" * means my parent is VARDEF and somewhere above that is a METHOD node. * The first node in the context is not necessarily the root. The context * matcher stops matching and returns true when it runs out of context. * There is no way to force the first node to be the root. */ public boolean inContext(String context) { return inContext(input.getTreeAdaptor(), getTokenNames(), input.LT(1), context); }
public TreeParser(TreeNodeStream input) { super(); // highlight that we go to super to set state object setTreeNodeStream(input); }
@Override protected Object getMissingSymbol(IntStream input, RecognitionException e, int expectedTokenType, BitSet follow) { Object o = super.getMissingSymbol(input, e, expectedTokenType, follow); dbg.consumeNode(o); return o; }
/** Prefix error message with the grammar name because message is * always intended for the programmer because the parser built * the input tree not the user. */ @Override public String getErrorHeader(RecognitionException e) { return getGrammarFileName()+": node from "+ (e.approximateLineInfo?"after ":"")+"line "+e.line+":"+e.charPositionInLine; }
@Override protected Object getMissingSymbol(IntStream input, RecognitionException e, int expectedTokenType, BitSet follow) { String tokenText = "<missing "+getTokenNames()[expectedTokenType]+">"; TreeAdaptor adaptor = ((TreeNodeStream)e.input).getTreeAdaptor(); return adaptor.create(new CommonToken(expectedTokenType, tokenText)); }
Object ancestor = getAncestor(adaptor, tokenNames, t, goal); if ( ancestor==null ) return false; t = ancestor;
@Override public void reportError(RecognitionException e) { super.reportError(e); }
/** Check if current node in input has a context. Context means sequence * of nodes towards root of tree. For example, you might say context * is "MULT" which means my parent must be MULT. "CLASS VARDEF" says * current node must be child of a VARDEF and whose parent is a CLASS node. * You can use "..." to mean zero-or-more nodes. "METHOD ... VARDEF" * means my parent is VARDEF and somewhere above that is a METHOD node. * The first node in the context is not necessarily the root. The context * matcher stops matching and returns true when it runs out of context. * There is no way to force the first node to be the root. */ public boolean inContext(String context) { return inContext(input.getTreeAdaptor(), getTokenNames(), input.LT(1), context); }
public TreeParser(TreeNodeStream input, RecognizerSharedState state) { super(state); // share the state object with another parser setTreeNodeStream(input); }
protected Object getMissingSymbol(IntStream input, RecognitionException e, int expectedTokenType, BitSet follow) { Object o = super.getMissingSymbol(input, e, expectedTokenType, follow); dbg.consumeNode(o); return o; }
/** Prefix error message with the grammar name because message is * always intended for the programmer because the parser built * the input tree not the user. */ @Override public String getErrorHeader(RecognitionException e) { return getGrammarFileName()+": node from "+ (e.approximateLineInfo?"after ":"")+"line "+e.line+":"+e.charPositionInLine; }
@Override protected Object getMissingSymbol(IntStream input, RecognitionException e, int expectedTokenType, BitSet follow) { String tokenText = "<missing "+getTokenNames()[expectedTokenType]+">"; TreeAdaptor adaptor = ((TreeNodeStream)e.input).getTreeAdaptor(); return adaptor.create(new CommonToken(expectedTokenType, tokenText)); }
Object ancestor = getAncestor(adaptor, tokenNames, t, goal); if ( ancestor==null ) return false; t = ancestor;
@Override public void reportError(RecognitionException e) { super.reportError(e); throw new IllegalArgumentException("Failed"); }
/** Check if current node in input has a context. Context means sequence * of nodes towards root of tree. For example, you might say context * is "MULT" which means my parent must be MULT. "CLASS VARDEF" says * current node must be child of a VARDEF and whose parent is a CLASS node. * You can use "..." to mean zero-or-more nodes. "METHOD ... VARDEF" * means my parent is VARDEF and somewhere above that is a METHOD node. * The first node in the context is not necessarily the root. The context * matcher stops matching and returns true when it runs out of context. * There is no way to force the first node to be the root. */ public boolean inContext(String context) { return inContext(input.getTreeAdaptor(), getTokenNames(), input.LT(1), context); }
public TreeParser(TreeNodeStream input) { super(); // highlight that we go to super to set state object setTreeNodeStream(input); }
@Override protected Object getMissingSymbol(IntStream input, RecognitionException e, int expectedTokenType, BitSet follow) { Object o = super.getMissingSymbol(input, e, expectedTokenType, follow); dbg.consumeNode(o); return o; }
/** Prefix error message with the grammar name because message is * always intended for the programmer because the parser built * the input tree not the user. */ @Override public String getErrorHeader(RecognitionException e) { return getGrammarFileName()+": node from "+ (e.approximateLineInfo?"after ":"")+"line "+e.line+":"+e.charPositionInLine; }
protected Object getMissingSymbol(IntStream input, RecognitionException e, int expectedTokenType, BitSet follow) { String tokenText = "<missing "+getTokenNames()[expectedTokenType]+">"; TreeAdaptor adaptor = ((TreeNodeStream)e.input).getTreeAdaptor(); return adaptor.create(new CommonToken(expectedTokenType, tokenText)); }