Split out a separate class access list, to improve parsing

This commit is contained in:
Ben Gruver 2015-02-16 10:45:26 -08:00
parent ea04d22ffd
commit f47973006b
4 changed files with 33 additions and 1 deletions

View File

@ -209,7 +209,7 @@ smali_file
class_spec class_spec
@init { Marker marker = mark(); } @init { Marker marker = mark(); }
: CLASS_DIRECTIVE access_list class_descriptor : CLASS_DIRECTIVE class_access_list class_descriptor
{ marker.done(SmaliElementTypes.CLASS_STATEMENT); }; { marker.done(SmaliElementTypes.CLASS_STATEMENT); };
catch [RecognitionException re] { catch [RecognitionException re] {
recover(input, re); recover(input, re);
@ -243,6 +243,18 @@ source_spec
reportError(marker, re, false); reportError(marker, re, false);
} }
// class_access_list should be separate from access_list, because
// it exists in a slightly different context, and can consume
// ACCESS_SPECs greedily, without having to look ahead.
class_access_list
@init { Marker marker = mark(); }
: ACCESS_SPEC*
{ marker.done(SmaliElementTypes.ACCESS_LIST); };
catch [RecognitionException re] {
recover(input, re);
reportError(marker, re, false);
}
access_list access_list
@init { Marker marker = mark(); } @init { Marker marker = mark(); }
: ACCESS_SPEC* : ACCESS_SPEC*

View File

@ -98,6 +98,7 @@ public class ParserTest extends ParsingTestCase {
public void testEmpty() throws Exception { doTest(true); } public void testEmpty() throws Exception { doTest(true); }
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 testParamListInvalidParameter() throws Exception { doTest(true); } public void testParamListInvalidParameter() throws Exception { doTest(true); }
public void testSuperClassInvalidSyntax() throws Exception { doTest(true); } public void testSuperClassInvalidSyntax() throws Exception { doTest(true); }
public void testSuperClassInvalidSyntax2() throws Exception { doTest(true); } public void testSuperClassInvalidSyntax2() throws Exception { doTest(true); }

View File

@ -0,0 +1 @@
.class public .class Ltest;

View File

@ -0,0 +1,18 @@
smali.FILE
SmaliClass(CLASS)
SmaliModifierList(MODIFIER_LIST)
<empty list>
SmaliExtendsList(EXTENDS_LIST)
<empty list>
SmaliImplementsList(IMPLEMENTS_LIST)
<empty list>
PsiElement(CLASS_STATEMENT)
PsiElement(CLASS_DIRECTIVE)('.class')
PsiWhiteSpace(' ')
PsiElement(ACCESS_LIST)
PsiElement(ACCESS_SPEC)('public')
PsiWhiteSpace(' ')
PsiErrorElement:extraneous input '.class' expecting CLASS_DESCRIPTOR
PsiElement(CLASS_DIRECTIVE)('.class')
PsiWhiteSpace(' ')
PsiElement(CLASS_DESCRIPTOR)('Ltest;')