aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gruver <bgruv@google.com>2015-02-28 10:16:50 -0800
committerBen Gruver <bgruv@google.com>2015-03-04 20:56:53 -0800
commitff7172c68dfb070bb6993c17ad21ff1336db80ee (patch)
tree21ee1c64d8e6f50f495df92c35376a6daa3d1b4d
parent16c154b96eaa005b68971eac3a5115de9ef5fcdc (diff)
downloadsmali-ff7172c68dfb070bb6993c17ad21ff1336db80ee.tar.gz
Improve error recovery of colons in various places
-rw-r--r--smalidea/src/main/antlr3/smalideaParser.g28
-rw-r--r--smalidea/src/test/java/org/jf/smalidea/ParserTest.java1
-rw-r--r--smalidea/testData/InvalidEnumLiteral.smalidea1
-rw-r--r--smalidea/testData/InvalidEnumLiteral.txt36
4 files changed, 52 insertions, 14 deletions
diff --git a/smalidea/src/main/antlr3/smalideaParser.g b/smalidea/src/main/antlr3/smalideaParser.g
index 7c6185e7..17e0445f 100644
--- a/smalidea/src/main/antlr3/smalideaParser.g
+++ b/smalidea/src/main/antlr3/smalideaParser.g
@@ -296,14 +296,6 @@ field
reportError(marker, re, false);
}
-colon
- : COLON;
- catch [RecognitionException re] {
- Marker marker = mark();
- recover(input, re);
- reportError(marker, re, false);
- }
-
end_field_directive
: END_FIELD_DIRECTIVE;
@@ -476,6 +468,14 @@ comma
reportError(errorMarker, re, false);
}
+colon
+ : COLON;
+ catch [RecognitionException re] {
+ Marker errorMarker = mark();
+ recover(input, re);
+ reportError(errorMarker, re, false);
+ }
+
param_list_inner
: ((PARAM_LIST_START param* PARAM_LIST_END)
| (PARAM_LIST_OR_ID_START param* PARAM_LIST_OR_ID_END)
@@ -689,7 +689,7 @@ array_literal
enum_literal
@init { Marker marker = mark(); }
- : ENUM_DIRECTIVE reference_type_descriptor arrow simple_name COLON reference_type_descriptor
+ : ENUM_DIRECTIVE reference_type_descriptor arrow simple_name colon reference_type_descriptor
{ marker.done(SmaliElementTypes.LITERAL); };
catch [RecognitionException re] {
recover(input, re);
@@ -701,7 +701,7 @@ type_field_method_literal
@init { Marker marker = mark(); }
: ( reference_type_descriptor
( arrow
- ( member_name COLON nonvoid_type_descriptor
+ ( member_name colon nonvoid_type_descriptor
| member_name method_prototype_reference
)
| /* epsilon */
@@ -864,7 +864,7 @@ fully_qualified_method
// TODO: check missing initial token
fully_qualified_field
@init { Marker marker = mark(); }
- : reference_type_descriptor arrow member_name COLON nonvoid_type_descriptor
+ : reference_type_descriptor arrow member_name colon nonvoid_type_descriptor
{ marker.done(SmaliElementTypes.FIELD_REFERENCE); };
catch [RecognitionException re] {
recover(input, re);
@@ -874,7 +874,7 @@ fully_qualified_field
// TODO: check missing initial token
label
@init { Marker marker = mark(); }
- : COLON simple_name
+ : colon simple_name
{ marker.done(SmaliElementTypes.LABEL); };
catch [RecognitionException re] {
recover(input, re);
@@ -884,7 +884,7 @@ label
// TODO: check missing initial token
label_ref
@init { Marker marker = mark(); }
- : COLON simple_name
+ : colon simple_name
{ marker.done(SmaliElementTypes.LABEL_REFERENCE); };
catch [RecognitionException re] {
recover(input, re);
@@ -971,7 +971,7 @@ line_directive
local_directive
@init { Marker marker = mark(); }
- : LOCAL_DIRECTIVE register (comma (null_literal | string_literal) COLON (void_type | nonvoid_type_descriptor)
+ : LOCAL_DIRECTIVE register (comma (null_literal | string_literal) colon (void_type | nonvoid_type_descriptor)
(comma string_literal)? )?
{ marker.done(SmaliElementTypes.LOCAL_DEBUG_STATEMENT); };
catch [RecognitionException re] {
diff --git a/smalidea/src/test/java/org/jf/smalidea/ParserTest.java b/smalidea/src/test/java/org/jf/smalidea/ParserTest.java
index 7610874a..395919b4 100644
--- a/smalidea/src/test/java/org/jf/smalidea/ParserTest.java
+++ b/smalidea/src/test/java/org/jf/smalidea/ParserTest.java
@@ -47,6 +47,7 @@ public class ParserTest extends LightCodeInsightParsingTestCase {
public void testInvalidClassDirective() throws Exception { doTest(true); }
public void testInvalidClassDirective2() throws Exception { doTest(true); }
public void testInvalidClassDirective3() throws Exception { doTest(true); }
+ public void testInvalidEnumLiteral() throws Exception { doTest(true); }
public void testInvalidField() throws Exception { doTest(true); }
public void testInvalidField2() throws Exception { doTest(true); }
public void testInvalidField3() throws Exception { doTest(true); }
diff --git a/smalidea/testData/InvalidEnumLiteral.smalidea b/smalidea/testData/InvalidEnumLiteral.smalidea
new file mode 100644
index 00000000..8853cc3a
--- /dev/null
+++ b/smalidea/testData/InvalidEnumLiteral.smalidea
@@ -0,0 +1 @@
+.field public static blah:Ljava/lang/Object; = .enum Lblah;->blah .blah Lblah; \ No newline at end of file
diff --git a/smalidea/testData/InvalidEnumLiteral.txt b/smalidea/testData/InvalidEnumLiteral.txt
new file mode 100644
index 00000000..2b595727
--- /dev/null
+++ b/smalidea/testData/InvalidEnumLiteral.txt
@@ -0,0 +1,36 @@
+smali.FILE
+ SmaliClass(CLASS)
+ SmaliExtendsList(EXTENDS_LIST)
+ <empty list>
+ SmaliImplementsList(IMPLEMENTS_LIST)
+ <empty list>
+ SmaliField(FIELD)
+ PsiElement(FIELD_DIRECTIVE)('.field')
+ PsiWhiteSpace(' ')
+ SmaliModifierList(MODIFIER_LIST)
+ PsiElement(ACCESS_SPEC)('public')
+ PsiWhiteSpace(' ')
+ PsiElement(ACCESS_SPEC)('static')
+ PsiWhiteSpace(' ')
+ PsiElement(MEMBER_NAME)
+ PsiElement(SIMPLE_NAME)('blah')
+ PsiElement(COLON)(':')
+ PsiElement(CLASS_TYPE)
+ PsiElement(CLASS_DESCRIPTOR)('Ljava/lang/Object;')
+ PsiWhiteSpace(' ')
+ PsiElement(FIELD_INITIALIZER)
+ PsiElement(EQUAL)('=')
+ PsiWhiteSpace(' ')
+ PsiElement(LITERAL)
+ PsiElement(ENUM_DIRECTIVE)('.enum')
+ PsiWhiteSpace(' ')
+ PsiElement(CLASS_TYPE)
+ PsiElement(CLASS_DESCRIPTOR)('Lblah;')
+ PsiElement(ARROW)('->')
+ PsiElement(SIMPLE_NAME)('blah')
+ PsiWhiteSpace(' ')
+ PsiErrorElement:mismatched input '.blah' expecting COLON
+ PsiElement(BAD_CHARACTER)('.blah')
+ PsiWhiteSpace(' ')
+ PsiElement(CLASS_TYPE)
+ PsiElement(CLASS_DESCRIPTOR)('Lblah;') \ No newline at end of file