Skip to content

Commit

Permalink
Remove default lex method from BaseParser
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Brown committed May 12, 2011
1 parent 6534bf6 commit 7aa785a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
27 changes: 0 additions & 27 deletions mmeta/BaseParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -691,33 +691,6 @@ public <T extends Enum<T>> Token<T> build_token(Enum<T> type, int pos, int start
public <T extends Enum<T>> Token<T> build_token(Enum<T> type, int pos, int start, int endpos) {
return new Token<T>(type, pos, start, endpos);
}

public Object lex() throws RuleFailure {
return _error("");
}

public Object _lex(Enum<?> type) throws RuleFailure {
_lex();
if (cached_token.type == type) {
return cached_token;
} else {
_pos = cached_token.pos;
return _error(type.name().substring(1));
}
}

public Token _lex() throws RuleFailure {
if (cached_token.pos != _pos) {
try {
Object t = lex();
cached_token = (Token<?>)t;
} catch (RuleFailure ex) {
cached_token = new Token(null, _pos, _pos, _pos);
}
}
_pos = cached_token.endpos;
return cached_token;
}

public class Token<T extends Enum<T>> {
public Token(Enum<T> type, int pos, int start, int end) {
Expand Down
9 changes: 8 additions & 1 deletion test/TestParser.mmeta
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ parser TestParser {
@lexer = MirahLexer.new(_string, @chars, self)
}

def lex {
def _lex {
t = @lexer.lex(_pos)
_enter(t.text)
_exit(t)
t
}

def _lex(type:Tokens) {
token = _lex
raise @error unless token.type == type
token
}

def checkstring(s:String) {
Expand Down

0 comments on commit 7aa785a

Please sign in to comment.