| 1 | |
package org.webslinger.javacc.support; |
| 2 | |
|
| 3 | |
import java.util.List; |
| 4 | |
import java.util.LinkedList; |
| 5 | |
|
| 6 | 3 | public abstract class AbstractParser { |
| 7 | 3 | protected LinkedList<GenericParseException> errors = new LinkedList<GenericParseException>(); |
| 8 | |
protected int closeTokens[]; |
| 9 | |
|
| 10 | |
protected void jjtreeOpenNodeScope(Object n) { |
| 11 | |
|
| 12 | |
|
| 13 | 207 | } |
| 14 | |
|
| 15 | |
protected void jjtreeCloseNodeScope(Object n) { |
| 16 | |
|
| 17 | |
|
| 18 | 206 | if (n instanceof PostProcessNode) ((PostProcessNode) n).postProcess(); |
| 19 | 206 | } |
| 20 | |
|
| 21 | |
public List<GenericParseException> getErrors() { |
| 22 | 0 | return errors; |
| 23 | |
} |
| 24 | |
|
| 25 | |
protected void handleException(GenericParseException e) { |
| 26 | |
|
| 27 | |
|
| 28 | 0 | if (isEOFKind(e.getNextTokenKind())) return; |
| 29 | 0 | errors.add(e); |
| 30 | 0 | } |
| 31 | |
|
| 32 | |
protected abstract int getNextTokenKind(); |
| 33 | |
protected abstract boolean isEOFKind(int kind); |
| 34 | |
|
| 35 | |
protected void error_skipto(String location, String message, GenericParseException e, int kind) { |
| 36 | |
|
| 37 | |
int nextKind; |
| 38 | 0 | int ignoreKind = e.getNextTokenKind(); |
| 39 | |
do { |
| 40 | 0 | nextKind = getNextTokenKind(); |
| 41 | 0 | } while (nextKind != kind && !isEOFKind(nextKind) && nextKind == ignoreKind); |
| 42 | 0 | if (!isEOFKind(nextKind)) errors.add(new LocatedException(location, message, e.getBeginLine(), e.getBeginColumn())); |
| 43 | 0 | while (nextKind != kind && !isEOFKind(nextKind)) { |
| 44 | 0 | nextKind = getNextTokenKind(); |
| 45 | |
} |
| 46 | 0 | } |
| 47 | |
|
| 48 | |
protected void error_skipto(int kind) { |
| 49 | |
|
| 50 | |
int nextKind; |
| 51 | |
do { |
| 52 | 0 | nextKind = getNextTokenKind(); |
| 53 | 0 | } while (nextKind != kind && !isEOFKind(nextKind)); |
| 54 | 0 | } |
| 55 | |
|
| 56 | |
protected void checkCloseToken(int token) throws CloseTokenFoundException { |
| 57 | 1 | System.err.println("isCloseToken(" + token + ") " + closeTokens[token]); |
| 58 | 1 | if (closeTokens[token] != 0) { |
| 59 | 1 | CloseTokenFoundException e = new CloseTokenFoundException(token); |
| 60 | 1 | throw e; |
| 61 | |
} |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
protected boolean isCloseTokenAllowed(int token) { |
| 65 | 0 | return closeTokens[token] == 0; |
| 66 | |
} |
| 67 | |
|
| 68 | |
protected void disableCloseToken(int token) { |
| 69 | 3 | closeTokens[token]--; |
| 70 | 3 | } |
| 71 | |
|
| 72 | |
protected void enableCloseToken(int token) { |
| 73 | 6 | closeTokens[token]++; |
| 74 | 6 | } |
| 75 | |
} |