mirror of
https://github.com/revanced/smali.git
synced 2025-05-22 19:08:52 +02:00
Print out an error message for invalid tokens in the lexer, but add a way to suppress the errors
Suppress the lexer errors for unit tests git-svn-id: https://smali.googlecode.com/svn/trunk@758 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
a377d50495
commit
73d1b5d3cb
@ -28,10 +28,17 @@ import static org.jf.smali.smaliParser.*;
|
||||
|
||||
private File sourceFile;
|
||||
|
||||
private boolean suppressErrors;
|
||||
|
||||
public Token nextToken() {
|
||||
try {
|
||||
Token token = yylex();
|
||||
if (token instanceof InvalidToken) {
|
||||
InvalidToken invalidToken = (InvalidToken)token;
|
||||
if (!suppressErrors) {
|
||||
System.err.println(getErrorHeader(invalidToken) + " Error for input '" +
|
||||
invalidToken.getText() + "': " + invalidToken.getMessage());
|
||||
}
|
||||
lexerErrors++;
|
||||
}
|
||||
return token;
|
||||
@ -58,6 +65,10 @@ import static org.jf.smali.smaliParser.*;
|
||||
return this.yycolumn;
|
||||
}
|
||||
|
||||
public void setSuppressErrors(boolean suppressErrors) {
|
||||
this.suppressErrors = suppressErrors;
|
||||
}
|
||||
|
||||
public void setSourceFile(File sourceFile) {
|
||||
this.sourceFile = sourceFile;
|
||||
}
|
||||
@ -155,8 +166,8 @@ import static org.jf.smali.smaliParser.*;
|
||||
return token;
|
||||
}
|
||||
|
||||
public String getErrorHeader(RecognitionException e) {
|
||||
return getSourceName()+"["+ e.line+","+e.charPositionInLine+"]";
|
||||
public String getErrorHeader(InvalidToken token) {
|
||||
return getSourceName()+"["+ token.getLine()+","+token.getCharPositionInLine()+"]";
|
||||
}
|
||||
%}
|
||||
|
||||
|
@ -154,6 +154,8 @@ public class LexerTest {
|
||||
Assert.fail("Could not load " + smaliFile);
|
||||
}
|
||||
smaliFlexLexer lexer = new smaliFlexLexer(smaliStream);
|
||||
lexer.setSourceFile(new File(test + ".smali"));
|
||||
lexer.setSuppressErrors(true);
|
||||
|
||||
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
||||
List tokens = tokenStream.getTokens();
|
||||
|
Loading…
x
Reference in New Issue
Block a user