diff --git a/smalidea/src/main/antlr3/smalideaParser.g b/smalidea/src/main/antlr3/smalideaParser.g index 581fae5f..d4f06808 100644 --- a/smalidea/src/main/antlr3/smalideaParser.g +++ b/smalidea/src/main/antlr3/smalideaParser.g @@ -88,15 +88,15 @@ import javax.annotation.Nullable; } } + @Override + public void recover(IntStream input, RecognitionException re) { + BitSet followSet = computeErrorRecoverySet(); + beginResync(); + consumeUntil(input, followSet); + endResync(); + } + public Marker recoverWithMarker(IntStream input, RecognitionException re) { - if ( state.lastErrorIndex==input.index() ) { - // uh oh, another error at same token index; must be a case - // where LT(1) is in the recovery token set so nothing is - // consumed; consume a single token so at least to prevent - // an infinite loop; this is a failsafe. - input.consume(); - } - state.lastErrorIndex = input.index(); BitSet followSet = computeErrorRecoverySet(); beginResync(); Marker marker = mark(); @@ -407,17 +407,20 @@ member_name method_prototype @init { Marker marker = mark(); } - : OPEN_PAREN param_list CLOSE_PAREN type_descriptor; + : open_paren param_list close_paren type_descriptor + { marker.done(SmaliElementTypes.METHOD_PROTOTYPE); }; catch [RecognitionException re] { recover(input, re); - reportError(re); - } - finally { - marker.done(SmaliElementTypes.METHOD_PROTOTYPE); + reportError(marker, re, false); } -param_list - @init { Marker marker = mark(); } +open_paren + : OPEN_PAREN; + +close_paren + : CLOSE_PAREN; + +param_list_inner : ((PARAM_LIST_START param* PARAM_LIST_END) | (PARAM_LIST_OR_ID_START param* PARAM_LIST_OR_ID_END) | (param*)); @@ -425,9 +428,11 @@ param_list Marker errorMarker = recoverWithMarker(input, re); reportError(errorMarker, re, false); } - finally { - marker.done(SmaliElementTypes.METHOD_PARAM_LIST); - } + +param_list + @init { Marker marker = mark(); } + : param_list_inner + { marker.done(SmaliElementTypes.METHOD_PARAM_LIST); }; param @init { diff --git a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliMethodPrototype.java b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliMethodPrototype.java index e3c6a4ba..15142890 100644 --- a/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliMethodPrototype.java +++ b/smalidea/src/main/java/org/jf/smalidea/psi/impl/SmaliMethodPrototype.java @@ -52,8 +52,8 @@ public class SmaliMethodPrototype extends SmaliStubBasedPsiElement \ No newline at end of file + SmaliMethodParamList(METHOD_PARAM_LIST) + \ No newline at end of file diff --git a/smalidea/testData/InvalidMethod2.smalidea b/smalidea/testData/InvalidMethod2.smalidea new file mode 100644 index 00000000..d5301430 --- /dev/null +++ b/smalidea/testData/InvalidMethod2.smalidea @@ -0,0 +1,6 @@ +.class Ltest; +.super Ljava/lang/Object; + +.method blah + +.method \ No newline at end of file diff --git a/smalidea/testData/InvalidMethod2.txt b/smalidea/testData/InvalidMethod2.txt new file mode 100644 index 00000000..955e9b9a --- /dev/null +++ b/smalidea/testData/InvalidMethod2.txt @@ -0,0 +1,50 @@ +smali.FILE + SmaliClass(CLASS) + SmaliModifierList(MODIFIER_LIST) + + SmaliExtendsList(EXTENDS_LIST) + + SmaliImplementsList(IMPLEMENTS_LIST) + + PsiElement(CLASS_STATEMENT) + PsiElement(CLASS_DIRECTIVE)('.class') + PsiWhiteSpace(' ') + PsiElement(ACCESS_LIST) + + PsiElement(CLASS_TYPE) + PsiElement(CLASS_DESCRIPTOR)('Ltest;') + PsiWhiteSpace('\n') + PsiElement(SUPER_STATEMENT) + PsiElement(SUPER_DIRECTIVE)('.super') + PsiWhiteSpace(' ') + PsiElement(CLASS_TYPE) + PsiElement(CLASS_DESCRIPTOR)('Ljava/lang/Object;') + PsiWhiteSpace('\n\n') + SmaliMethod(METHOD) + SmaliModifierList(MODIFIER_LIST) + + PsiElement(METHOD_DIRECTIVE)('.method') + PsiWhiteSpace(' ') + PsiElement(ACCESS_LIST) + + PsiElement(MEMBER_NAME) + PsiElement(SIMPLE_NAME)('blah') + PsiWhiteSpace('\n\n') + SmaliMethodPrototype(METHOD_PROTOTYPE) + PsiErrorElement:mismatched input '.method' expecting OPEN_PAREN + + SmaliMethodParamList(METHOD_PARAM_LIST) + + PsiErrorElement:missing END_METHOD_DIRECTIVE at '.method' + + SmaliMethod(METHOD) + SmaliModifierList(MODIFIER_LIST) + + PsiElement(METHOD_DIRECTIVE)('.method') + PsiElement(ACCESS_LIST) + + PsiErrorElement:no viable alternative at input '' + + SmaliMethodPrototype(METHOD_PROTOTYPE) + SmaliMethodParamList(METHOD_PARAM_LIST) + \ No newline at end of file