Improve error recovery of colons in various places

This commit is contained in:
Ben Gruver 2015-02-28 10:16:50 -08:00
parent 16c154b96e
commit ff7172c68d
4 changed files with 52 additions and 14 deletions

View File

@ -296,14 +296,6 @@ field
reportError(marker, re, false); 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
: END_FIELD_DIRECTIVE; : END_FIELD_DIRECTIVE;
@ -476,6 +468,14 @@ comma
reportError(errorMarker, re, false); reportError(errorMarker, re, false);
} }
colon
: COLON;
catch [RecognitionException re] {
Marker errorMarker = mark();
recover(input, re);
reportError(errorMarker, re, false);
}
param_list_inner param_list_inner
: ((PARAM_LIST_START param* PARAM_LIST_END) : ((PARAM_LIST_START param* PARAM_LIST_END)
| (PARAM_LIST_OR_ID_START param* PARAM_LIST_OR_ID_END) | (PARAM_LIST_OR_ID_START param* PARAM_LIST_OR_ID_END)
@ -689,7 +689,7 @@ array_literal
enum_literal enum_literal
@init { Marker marker = mark(); } @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); }; { marker.done(SmaliElementTypes.LITERAL); };
catch [RecognitionException re] { catch [RecognitionException re] {
recover(input, re); recover(input, re);
@ -701,7 +701,7 @@ type_field_method_literal
@init { Marker marker = mark(); } @init { Marker marker = mark(); }
: ( reference_type_descriptor : ( reference_type_descriptor
( arrow ( arrow
( member_name COLON nonvoid_type_descriptor ( member_name colon nonvoid_type_descriptor
| member_name method_prototype_reference | member_name method_prototype_reference
) )
| /* epsilon */ | /* epsilon */
@ -864,7 +864,7 @@ fully_qualified_method
// TODO: check missing initial token // TODO: check missing initial token
fully_qualified_field fully_qualified_field
@init { Marker marker = mark(); } @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); }; { marker.done(SmaliElementTypes.FIELD_REFERENCE); };
catch [RecognitionException re] { catch [RecognitionException re] {
recover(input, re); recover(input, re);
@ -874,7 +874,7 @@ fully_qualified_field
// TODO: check missing initial token // TODO: check missing initial token
label label
@init { Marker marker = mark(); } @init { Marker marker = mark(); }
: COLON simple_name : colon simple_name
{ marker.done(SmaliElementTypes.LABEL); }; { marker.done(SmaliElementTypes.LABEL); };
catch [RecognitionException re] { catch [RecognitionException re] {
recover(input, re); recover(input, re);
@ -884,7 +884,7 @@ label
// TODO: check missing initial token // TODO: check missing initial token
label_ref label_ref
@init { Marker marker = mark(); } @init { Marker marker = mark(); }
: COLON simple_name : colon simple_name
{ marker.done(SmaliElementTypes.LABEL_REFERENCE); }; { marker.done(SmaliElementTypes.LABEL_REFERENCE); };
catch [RecognitionException re] { catch [RecognitionException re] {
recover(input, re); recover(input, re);
@ -971,7 +971,7 @@ line_directive
local_directive local_directive
@init { Marker marker = mark(); } @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)? )? (comma string_literal)? )?
{ marker.done(SmaliElementTypes.LOCAL_DEBUG_STATEMENT); }; { marker.done(SmaliElementTypes.LOCAL_DEBUG_STATEMENT); };
catch [RecognitionException re] { catch [RecognitionException re] {

View File

@ -47,6 +47,7 @@ public class ParserTest extends LightCodeInsightParsingTestCase {
public void testInvalidClassDirective() throws Exception { doTest(true); } public void testInvalidClassDirective() throws Exception { doTest(true); }
public void testInvalidClassDirective2() throws Exception { doTest(true); } public void testInvalidClassDirective2() throws Exception { doTest(true); }
public void testInvalidClassDirective3() 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 testInvalidField() throws Exception { doTest(true); }
public void testInvalidField2() throws Exception { doTest(true); } public void testInvalidField2() throws Exception { doTest(true); }
public void testInvalidField3() throws Exception { doTest(true); } public void testInvalidField3() throws Exception { doTest(true); }

View File

@ -0,0 +1 @@
.field public static blah:Ljava/lang/Object; = .enum Lblah;->blah .blah Lblah;

View File

@ -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;')