started work at the Visitors templates by making a copy of the Listener templates

This commit is contained in:
Christian Gudrian 2016-10-06 21:42:25 +02:00
parent 46df58d5d7
commit a90c9d6669
11 changed files with 274 additions and 1 deletions

View File

@ -12,5 +12,6 @@ TestFolders ::= [
"Performance": [],
"SemPredEvalLexer": [],
"SemPredEvalParser": [],
"Sets": []
"Sets": [],
"Visitors": []
]

View File

@ -0,0 +1,47 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Input() ::= "1 2"
Rule() ::= "s"
Output() ::= <<
(a 1 2)
1
2<\n>
>>
Errors() ::= ""
grammar(grammarName) ::= <<
grammar <grammarName>;
@parser::header {
<ImportVisitor(grammarName)>
}
@parser::members {
<BasicVisitor(grammarName)>
}
s
@after {
<ToStringTree("$ctx.r"):writeln()>
<WalkVisitor("$ctx.r")>
}
: r=a ;
a : INT INT
| ID
;
MULT: '*' ;
ADD : '+' ;
INT : [0-9]+ ;
ID : [a-z]+ ;
WS : [ \t\n]+ -> skip ;
>>

View File

@ -0,0 +1,9 @@
TestTemplates ::= [
"Basic": [],
"TokenGetters_1": [],
"TokenGetters_2": [],
"RuleGetters_1": [],
"RuleGetters_2": [],
"LR": [],
"LRWithLabels": []
]

View File

@ -0,0 +1,51 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Input() ::= "1+2*3"
Rule() ::= "s"
Output() ::= <<
(e (e 1) + (e (e 2) * (e 3)))
1
2
3
2 3 2
1 2 1<\n>
>>
Errors() ::= ""
grammar(grammarName) ::= <<
grammar <grammarName>;
@parser::header {
<ImportVisitor(grammarName)>
}
@parser::members {
<LRVisitor(grammarName)>
}
s
@after {
<ToStringTree("$ctx.r"):writeln()>
<WalkVisitor("$ctx.r")>
}
: r=e ;
e : e op='*' e
| e op='+' e
| INT
;
MULT: '*' ;
ADD : '+' ;
INT : [0-9]+ ;
ID : [a-z]+ ;
WS : [ \t\n]+ -> skip ;
>>

View File

@ -0,0 +1,50 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Input() ::= "1(2,3)"
Rule() ::= "s"
Output() ::= <<
(e (e 1) ( (eList (e 2) , (e 3)) ))
1
2
3
1 [13 6]<\n>
>>
Errors() ::= ""
grammar(grammarName) ::= <<
grammar <grammarName>;
@parser::header {
<ImportVisitor(grammarName)>
}
@parser::members {
<LRWithLabelsVisitor(grammarName)>
}
s
@after {
<ToStringTree("$ctx.r"):writeln()>
<WalkVisitor("$ctx.r")>
}
: r=e ;
e : e '(' eList ')' # Call
| INT # Int
;
eList : e (',' e)* ;
MULT: '*' ;
ADD : '+' ;
INT : [0-9]+ ;
ID : [a-z]+ ;
WS : [ \t\n]+ -> skip ;
>>

View File

@ -0,0 +1,38 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
@parser::header {
<ImportVisitor(grammarName)>
}
@parser::members {
<RuleGetterVisitor(grammarName)>
}
s
@after {
<ToStringTree("$ctx.r"):writeln()>
<WalkVisitor("$ctx.r")>
}
: r=a ;
a : b b // forces list
| b // a list still
;
b : ID | INT;
MULT: '*' ;
ADD : '+' ;
INT : [0-9]+ ;
ID : [a-z]+ ;
WS : [ \t\n]+ -> skip ;
>>

View File

@ -0,0 +1,10 @@
import "RuleGetters.stg"
Input() ::= "1 2"
Output() ::= <<
(a (b 1) (b 2))
1 2 1<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,10 @@
import "RuleGetters.stg"
Input() ::= "abc"
Output() ::= <<
(a (b abc))
abc<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,37 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
@parser::header {
<ImportVisitor(grammarName)>
}
@parser::members {
<TokenGetterVisitor(grammarName)>
}
s
@after {
<ToStringTree("$ctx.r"):writeln()>
<WalkVisitor("$ctx.r")>
}
: r=a ;
a : INT INT
| ID
;
MULT: '*' ;
ADD : '+' ;
INT : [0-9]+ ;
ID : [a-z]+ ;
WS : [ \t\n]+ -> skip ;
>>

View File

@ -0,0 +1,10 @@
import "TokenGetters.stg"
Input() ::= "1 2"
Output() ::= <<
(a 1 2)
1 2 [1, 2]<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,10 @@
import "TokenGetters.stg"
Input() ::= "abc"
Output() ::= <<
(a abc)
[@0,0:2='abc',\<4>,1:0]<\n>
>>
Errors() ::= ""