Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added lexer token class ExtToken with customized printing of tokens, …
…which * hides the mostly-useless token type numbers which were causing the tests to change unnecessarily, and * displays tokens whose text is modified (e.g. "'a'" lexes to a token whose text is "a") with a reconstruction of their original text. git-svn-id: http://switchb.org/svn/e/cl-e/trunk@786 bf3ccfa1-f3f3-0310-a3d5-cea1fe9d5a75
- Loading branch information
Showing
4 changed files
with
94 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2007 Kevin Reid, under the terms of the MIT X license | ||
// found at http://www.opensource.org/licenses/mit-license.html ............... | ||
|
||
import antlr.CommonToken; | ||
|
||
/** Modified print behavior over CommonToken; in particular, does not print the numeric token type, which is not useful information to the user; also knows how to reverse text transformations for particular token types. */ | ||
public class ExtToken extends CommonToken { | ||
|
||
/** this is the constructor invoked by CharScanner */ | ||
public ExtToken() { super(); } | ||
|
||
public String getOriginalText() { | ||
if (type == ETokenTypes.EOF) { | ||
return "<EOF>"; | ||
} else if (type == ETokenTypes.SOURCE_VALUE_HOLE) { | ||
return "<$-hole #" + getText() + ">"; | ||
} else if (type == ETokenTypes.SOURCE_PATTERN_HOLE) { | ||
return "<@-hole #" + getText() + ">"; | ||
} else if (type == ETokenTypes.DOLLAR_IDENT) { | ||
return "$" + getText(); | ||
} else if (type == ETokenTypes.AT_IDENT) { | ||
return "@" + getText(); | ||
} else if (type == ETokenTypes.DOLLARESC) { | ||
return "$\\" + getText(); // XXX escape | ||
} else if (type == ETokenTypes.CHAR_LITERAL) { | ||
return "'" + getText() + "'"; // XXX escape | ||
} else if (type == ETokenTypes.STRING) { | ||
return "\"" + getText() + "\""; // XXX escape | ||
} else if (type == ETokenTypes.HEX) { | ||
return "0x" + getText(); | ||
} else if (type == ETokenTypes.OCTAL) { | ||
return "0" + getText(); | ||
} else if (type == ETokenTypes.URI) { | ||
return "<" + getText() + ">"; | ||
} else if (type == ETokenTypes.URIGetter) { | ||
return "<" + getText() + ">"; | ||
} else if (type == ETokenTypes.URIStart) { | ||
return "<" + getText(); | ||
} else { | ||
return getText(); | ||
} | ||
} | ||
|
||
public String toString() { | ||
return "<\"" + getOriginalText() + "\" @ " + getLine() + ":" + getColumn() + ">"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters