1use strict;
2use warnings;
3
4use lib qw( t/lib );
5
6use Test::More;
7use ANTLR::Runtime::Test;
8
9plan tests => 1;
10
11TODO: {
12local $TODO = 'Not implemented yet';
13# The SimpleCalc grammar from the five minutes tutorial.
14g_test_output_is({ grammar => <<'GRAMMAR', test_program => <<'CODE', expected => <<'OUTPUT' });
15grammar Fig;
16options { language = Perl5; }
17
18@header {
19use RunFig;
20}
21
22@members {
23has 'instances' => (
24    default => sub { {} }
25);
26}
27
28file returns [objects]
29    :   { $objects = []; }
30        (object { push @$objects, $object.o; })+
31    ;
32
33object returns [o]
34    :   qid v=ID?
35        {
36        $o = RunFig.newInstance($qid.text);
37        if (defined $v) {
38            $self->instances->{$v.text, $o);
39        }
40        }
41        '{' assign[$o]* '}'
42    ;
43
44assign[o]
45    :   ID '=' expr ';' {RunFig.setObjectProperty(o,$ID.text,$expr.value);}
46    ;
47
48expr returns [value]
49    :   STRING  { $value = $STRING.text; }
50    |   INT     { $value = Integer.valueOf($INT.text); }
51    |   '$' ID  { $value = instances.get($ID.text); }
52    |   '[' ']' { $value = new ArrayList(); }
53    |   {ArrayList elements = new ArrayList(); }
54        '[' e=expr { elements.add($e.value); }
55            (',' e=expr { elements.add($e.value); })*
56        ']'
57        { $value = elements; }
58    ;
59
60qid :   ID ('.' ID)*
61    ;
62
63STRING : '"' .* '"' { setText(getText().substring(1, getText().length()-1)); } ;
64INT :   '0'..'9'+ ;
65ID  :   ('_'|'a'..'z'|'A'..'Z') ('_'|'a'..'z'|'A'..'Z'|'0'..'9')* ;
66WS  :   (' '|'\n'|'\t')+ { $channel = $self->HIDDEN; } ;
67CMT :   '/*' .* '*/'     { $channel = $self->HIDDEN; } ;
68GRAMMAR
69
70CODE
71
72OUTPUT
73}
74