The attached grammar seems to parse fine when given empty input and
calling into the parsing method but with gunit I it gives me
NullPointerException.

betelge...@pena ~/python/depend $ gunit Depend.testsuite
-----------------------------------------------------------------------
executing testsuite for grammar:Depend with 108 tests
-----------------------------------------------------------------------
1 failures found:
test3 (depend, line5) -
expected: ()
actual: java.lang.NullPointerException

Regards,
Petteri

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

grammar Depend;

options {
        backtrack=true;
        output=AST;
}
tokens {
        ALL_OF;
        ANY_OF;
        CATEGORY;
        PKG_DEP;
        PN;
        SLOT;
        USE_CONDITIONAL;
        USE_FLAG;
}
@header {
        import java.util.regex.Pattern;
}

@members {
public class EAPIFeatures
{
        public static final boolean DEFAULT = true;
        public boolean STRONG_BLOCK = DEFAULT;
        public boolean SLOT_DEPENDS = DEFAULT;
        public boolean USE_DEPENDS = DEFAULT;
}

        private EAPIFeatures features = new EAPIFeatures();
        private Pattern pn_end = Pattern.compile(".*-\\d+");
        private boolean needs_version;
        private boolean accept_asterisk;
        public DependParser(TokenStream input, EAPIFeatures features) {
                this(input);
                this.features = features;
        }
}


depend: WS? expr? WS? -> expr?;

expr    :       expr_type (WS expr_type)* -> expr_type+;

expr_type:
        any_of | use_conditional | all_of | pkg_dep;

all_of
        : '(' WS expr WS ')' -> ^(ALL_OF expr);
any_of
        :       '||' WS '(' WS (expr WS)* ')' -> ^(ANY_OF expr+);

use_conditional
        :       NOT? use_flag '?' WS '(' WS (expr WS)* ')' -> ^(USE_CONDITIONAL 
^(use_flag NOT?) expr+);

pkg_dep
        :       block_oper? (versioned_dep | qpn) slot_dep? use_dep? -> 
^(PKG_DEP );

versioned_dep
@init {
        needs_version = true;
}
@after {
        needs_version = false;
        accept_asterisk = false;
}
:       OPERATOR qpn version_spec
        | EQUALS {accept_asterisk=true;} qpn version_spec;

block_oper      :       '!' ({features.STRONG_BLOCK}?=> '!'?);

version_spec
        :       EAPI0_VERSION_SPEC  asterisk?;

asterisk:
        {accept_asterisk}?=> '*'
        | {!accept_asterisk}?=>;

use_dep :
        {features.USE_DEPENDS}?=> '[' use_dep_atom (',' use_dep_atom)* ']'
        | {!features.USE_DEPENDS}?=> ;

use_dep_atom
        :       ('!'|HYPHEN)? use_flag (EQUALS|'?')?;

slot_dep:
        {features.SLOT_DEPENDS}?=> ':' slot_name
        | {!features.SLOT_DEPENDS}?=>;


qpn     :        category '/' pn -> category PN[$pn.text];

pn      :       pn_start 
        |       pn_start pn_end;

pn_end
        :       (options { greedy=false;} : pn_part)* (pn_part pn_follows)=> 
pn_part {!pn_end.matcher($pn_end.text).matches()}?;

pn_start : INTEGER|ALPHA|'+'|'_';
pn_part:  INTEGER|ALPHA|'+'|'_'|HYPHEN;

pn_follows
:
         {needs_version}?=> version_spec (WS|EOF) 
         | {!needs_version}?=> (WS|EOF);

slot_name
        :       name[true,true,true,false] -> SLOT[$slot_name.text];

// must begin with alphanumerics
use_flag:       name[false,false,false,true] -> USE_FLAG[$use_flag.text];

category:       name[true,true,true,false] -> CATEGORY[$category.text];

name[boolean start_plus,
     boolean start_under,
     boolean end_dot,
     boolean end_at]:
        (
        name_part
        | {start_plus}? '+'
        | {start_under}? '_'
        )

        (
        name_part
        | '+'
        | '_'
        | HYPHEN
        | {end_dot}? '.'
        | {end_at}? '@'
        )*;

name_part:      INTEGER|ALPHA|EAPI0_VERSION_SPEC;

INTEGER :       DIGIT+;

EAPI0_VERSION_SPEC
        : HYPHEN INTEGER ('.' INTEGER)* (LOWER)? STATE_SUFFIX* REVISION?;


fragment STATE_SUFFIX
        : '_' STATE INTEGER?;

fragment STATE: 'alpha'|'beta'|'pre'|'rc'|'p';

fragment REVISION: REVISION_START INTEGER;
fragment REVISION_START: '-r';

ALPHA: (LOWER|UPPER)+;

HYPHEN: '-';
NOT:    '!';
OPERATOR:       '<' | '<=' | '~' | '>=' | '>';
EQUALS: '=';

WS  : (' '|'\r'|'\t'|'\u000C'|'\n')+; //There are places of mandatory ws so 
don't hide it

fragment DIGIT  :       '0'..'9';
fragment LOWER  :       'a'..'z';
fragment UPPER  :       'A'..'Z';
gunit Depend;
depend:
"  ||  ( app-foo/bar lol? ( >=dev-java/lol-3 )  )  " OK
"|| ( ( x11-libs/libXtst x11-libs/libX11 ) virtual/x11 )" OK
"" -> ()

any_of:
"|| ( app-foo/bar app-foo/another )" OK
"||( app-foo/bar )" FAIL
"|| (app-foo/bar )" FAIL
"|| ( app-foo/bar)" FAIL

all_of:
"( app-foo/first app-foo/second )" OK

use_conditional:
"foo? ( app-foo/bar )" OK
"!build? ( sys-apps/sed >=sys-devel/binutils-2.11.90.0.31 )" OK
"foo ? ( )" FAIL
"foo?( app-foo/bar )" FAIL


pkg_dep:
">=app-cat/pkg-3" OK
"<app-cat/pkg-1.1.1a_alpha-r4" OK
"cat.a.gory/packageName-a" OK
"cat.a.gory/packageName-" OK
"=.cat.a.gory/packageName-12a" FAIL
"cat/foo-3" FAIL
">=app-cat/pkg" FAIL
"dev-tex/mplib[lua]" OK
"dev-tex/foo:2" OK

versioned_dep:
"=cat.a.gory/packageName-1" OK
"=cat.a.gory/packageName+a-12a" OK
"=cat.a.gory/packageName-a-12a" OK
"=cat.a.gory/packageName-a-12a" OK
"=cat.a.gory/packageName--12a" OK
"=sys-devel/automake-1.10*" OK
">=sys-devel/automake-1.10*" FAIL

version_spec:
"-3" OK

use_dep:
"[lua]" OK
"[bar,baz]" OK
"[-lua]" OK
"[!bar?]" OK
"[!bar=,bar?]" OK

EAPI0_VERSION_SPEC:
"-1.1.1" OK
"-1.22.333a" OK
"-1.1.1a-r3" OK
"-3" OK
"-2_alpha_beta" OK
"-12a" OK

qpn:
"app-foo/bar" OK

slot_name:
".SLOT" FAIL
"alpha" OK
"beta" OK
"123" OK
"foo" OK
"a-r" OK
"a-1a" OK

use_flag:
"foo" OK
"foo+" OK
"foo_a" OK
"f@@@" OK
"f...@2" OK
"f-r1" OK
"alpha" OK
"123" OK
"@@" FAIL
"+FOO" FAIL
"a-1a" OK

category:
"foo" OK
"foo1" OK
"11foo" OK
"app-foo" OK
"virtual" OK
"alpha" OK
"beta" OK
"foo--" OK
"123" OK
"a-r" OK
"cat.a.gory" OK
"a-1a" OK
"-foo" FAIL
".foo" FAIL
".foo." FAIL

pn:
"_foo" OK
"_foo-bar" OK
"+bar11+" OK
"foo--" OK
"app-foo-bar" OK
"pkg-a" OK
"-laa" FAIL
"foo-12" FAIL
"foo-1" FAIL
"alpha" OK
"beta" OK
"123" OK
"core" OK
"core-1.2-r3" FAIL

pn_follows:
"       " OK
"1.1" FAIL

OPERATOR:
"<" OK
"<=" OK
"~" OK
">=" OK
">" OK

INTEGER:
"" FAIL
"1213" OK
"1221a" FAIL

UPPER:
"A" OK
"p" FAIL
"CC" FAIL

LOWER:
"P" FAIL
"k" OK
"pp" FAIL

WS:
" " OK
"  " OK
"       " OK
"ff" FAIL
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to