rm scopes for rules/grammar, added locals [int i, int j] for rules. i do not generate anything for the LOCALS tree at moment

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 8912]
This commit is contained in:
parrt 2011-07-27 16:43:16 -08:00
parent 2136287966
commit 2db09cdeb9
31 changed files with 186 additions and 805 deletions

View File

@ -391,19 +391,6 @@ ThisRulePropertyRef_tree(r) ::= "_localctx.tree"
ThisRulePropertyRef_text(r) ::= "((TokenStream)input).toString(_localctx.start, input.LT(-1))"
ThisRulePropertyRef_st(r) ::= "_localctx.st"
DynScopeRef(s) ::= "<s.scope>"
DynScopeAttrRef(s) ::= "<s.scope>.peek().<s.attr>"
DynScopeAttrRef_negIndex(s, indexChunks) ::=
"<s.scope>.get(<s.scope>.size()-<indexChunks>-1).<s.attr>"
DynScopeAttrRef_index(s, indexChunks) ::=
"<s.scope>.get(<indexChunks>).<s.attr>"
SetDynScopeAttr(s, rhsChunks) ::=
"<s.scope>.peek().<s.attr> =<rhsChunks>;"
SetDynScopeAttr_negIndex(s, indexChunks, rhsChunks) ::=
"<s.scope>.get(<s.scope>.size()-<indexChunks>-1).<s.attr> =<rhsChunks>;"
SetDynScopeAttr_index(s, indexChunks, rhsChunks) ::=
"<s.scope>.get(<indexChunks>).<s.attr> =<rhsChunks>;"
AddToLabelList(a) ::= "_localctx.<a.listName>.add(<labelref(a.label)>);"
TokenDecl(t) ::= "Token <t.name>;"
@ -415,7 +402,6 @@ RuleContextListDecl(rdecl) ::= "List\<<rdecl.ctxName>> <rdecl.name> = new ArrayL
/** Default RuleContext type name for a Parser rule */
ParserRuleContext() ::= "ParserRuleContext"
RuleDynamicScopeStructName(ruleName) ::= "<ruleName>_stk"
ImplicitTokenLabel(tokenName) ::= "_t<tokenName>"
ImplicitRuleLabel(ruleName) ::= "_r<ruleName>"
ImplicitSetLabel(id) ::= "_tset<id>"

View File

@ -510,12 +510,13 @@ public class ParserATNFactory implements ATNFactory {
public ATNState newState() { return newState(null); }
public boolean isGreedy(BlockAST blkAST) {
boolean greedy = true;
String greedyOption = blkAST.getOption("greedy");
if ( blockHasWildcardAlt(blkAST) || greedyOption!=null&&greedyOption.equals("false") ) {
greedy = false;
}
return greedy;
return true;
// boolean greedy = true;
// String greedyOption = blkAST.getOption("greedy");
// if ( blockHasWildcardAlt(blkAST) || greedyOption!=null&&greedyOption.equals("false") ) {
// greedy = false;
// }
// return greedy;
}
// (BLOCK (ALT .)) or (BLOCK (ALT 'a') (ALT .))

View File

@ -149,10 +149,6 @@ public class ActionTranslator implements ActionSplitterListener {
chunks.add(new ListLabelRef(x.getText())); // $ids for ids+=ID etc...
return;
}
if ( node.resolver.resolveToDynamicScope(x.getText(), node)!=null ) {
chunks.add(new DynScopeRef(getDynamicScopeName(x.getText()))); // $S for scope S is ok
return;
}
// switch ( a.dict.type ) {
// case ARG: chunks.add(new ArgRef(x.getText())); break;
// case RET: chunks.add(new RetValueRef(x.getText())); break;
@ -207,39 +203,6 @@ public class ActionTranslator implements ActionSplitterListener {
chunks.add(s);
}
public void dynamicScopeAttr(String expr, Token x, Token y) {
System.out.println("scoped "+x+"."+y);
// we assume valid, just gen code
chunks.add(new DynScopeAttrRef(getDynamicScopeName(x.getText()), y.getText()));
}
public void setDynamicScopeAttr(String expr, Token x, Token y, Token rhs) {
List<ActionChunk> rhsChunks = translateActionChunk(factory,rf,rhs.getText(),node);
chunks.add(new SetDynScopeAttr(getDynamicScopeName(x.getText()), y.getText(), rhsChunks));
}
public void dynamicNegativeIndexedScopeAttr(String expr, Token x, Token y, Token index) {
List<ActionChunk> indexChunks = translateActionChunk(factory,rf,index.getText(),node);
chunks.add(new DynScopeAttrRef_negIndex(getDynamicScopeName(x.getText()), y.getText(), indexChunks));
}
public void setDynamicNegativeIndexedScopeAttr(String expr, Token x, Token y, Token index, Token rhs) {
List<ActionChunk> indexChunks = translateActionChunk(factory,rf,index.getText(),node);
List<ActionChunk> rhsChunks = translateActionChunk(factory,rf,rhs.getText(),node);
chunks.add(new SetDynScopeAttr_negIndex(getDynamicScopeName(x.getText()), y.getText(), indexChunks, rhsChunks));
}
public void dynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y, Token index) {
List<ActionChunk> indexChunks = translateActionChunk(factory,rf,index.getText(),node);
chunks.add(new DynScopeAttrRef_index(getDynamicScopeName(x.getText()), y.getText(), indexChunks));
}
public void setDynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y, Token index, Token rhs) {
List<ActionChunk> indexChunks = translateActionChunk(factory,rf,index.getText(),node);
List<ActionChunk> rhsChunks = translateActionChunk(factory,rf,rhs.getText(),node);
chunks.add(new SetDynScopeAttr_index(getDynamicScopeName(x.getText()), y.getText(), indexChunks, rhsChunks));
}
public void templateInstance(String expr) {
}
@ -315,17 +278,6 @@ public class ActionTranslator implements ActionSplitterListener {
return factory.getGenerator().target.getImplicitRuleLabel(x);
}
public String getDynamicScopeName(String x) {
String scope;
if ( factory.getGrammar().getRule(x)==null ) {
scope = factory.getGenerator().target.getGlobalDynamicScopeStructName(x);
}
else {
scope = factory.getGenerator().target.getRuleDynamicScopeStructName(x);
}
return scope;
}
// public String getTokenLabel(String x, ActionAST node) {
// Alternative alt = node.resolver.
// Rule r = node.ATNState.rule;

View File

@ -223,13 +223,6 @@ public class Target {
return r.name+"_ctx";
}
public String getRuleDynamicScopeStructName(String ruleName) {
ST st = gen.templates.getInstanceOf("RuleDynamicScopeStructName");
st.add("ruleName", ruleName);
return st.render();
}
public String getGlobalDynamicScopeStructName(String scopeName) { return scopeName; }
// should be same for all refs to same token like $ID within single rule function
public String getImplicitTokenLabel(String tokenName) {
ST st = gen.templates.getInstanceOf("ImplicitTokenLabel");

View File

@ -43,7 +43,6 @@ public class RuleFunction extends OutputModelObject {
public String name;
public List<String> modifiers;
public String ctxType;
public List<String> globalScopesUsed;
public Collection<String> ruleLabels;
public Collection<String> tokenLabels;
public List<String> elementsReferencedInRewrite;
@ -87,8 +86,6 @@ public class RuleFunction extends OutputModelObject {
ruleCtx.addDecls(r.scope.attributes.values());
}
globalScopesUsed = Utils.apply(r.useScopes, "getText");
ruleLabels = r.getLabelNames();
tokenLabels = r.getTokenRefs();
exceptions = Utils.nodesToStrings(r.exceptionActions);

View File

@ -1,41 +0,0 @@
/*
[The "BSD license"]
Copyright (c) 2011 Terence Parr
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.codegen.model.actions;
/** */
public class DynScopeAttrRef extends ActionChunk {
public String scope;
public String attr;
public DynScopeAttrRef(String scope, String attr) {
this.attr = attr;
this.scope = scope;
}
}

View File

@ -1,53 +0,0 @@
/*
[The "BSD license"]
Copyright (c) 2011 Terence Parr
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.codegen.model.actions;
import org.antlr.v4.codegen.model.ModelElement;
import java.util.List;
/** */
public class DynScopeAttrRef_index extends DynScopeAttrRef {
@ModelElement public List<ActionChunk> indexChunks;
public DynScopeAttrRef_index(String scope, String attr, List<ActionChunk> indexChunks) {
super(scope, attr);
this.indexChunks = indexChunks;
}
// @Override
// public List<String> getChildren() {
// final List<String> sup = super.getChildren();
// return new ArrayList<String>() {{
// if ( sup!=null ) addAll(sup);
// add("indexChunks");
// }};
// }
}

View File

@ -1,39 +0,0 @@
/*
[The "BSD license"]
Copyright (c) 2011 Terence Parr
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.codegen.model.actions;
import java.util.List;
/** */
public class DynScopeAttrRef_negIndex extends DynScopeAttrRef_index {
public DynScopeAttrRef_negIndex(String scope, String attr, List<ActionChunk> indexChunks) {
super(scope, attr, indexChunks);
}
}

View File

@ -1,39 +0,0 @@
/*
[The "BSD license"]
Copyright (c) 2011 Terence Parr
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.codegen.model.actions;
/** */
public class DynScopeRef extends ActionChunk {
public String scope;
public DynScopeRef(String scope) {
this.scope = scope;
}
}

View File

@ -1,47 +0,0 @@
/*
[The "BSD license"]
Copyright (c) 2011 Terence Parr
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.codegen.model.actions;
import org.antlr.v4.codegen.model.ModelElement;
import java.util.List;
/** */
public class SetDynScopeAttr extends ActionChunk {
public String scope;
public String attr;
@ModelElement public List<ActionChunk> rhsChunks;
public SetDynScopeAttr(String scope, String attr, List<ActionChunk> rhsChunks) {
this.scope = scope;
this.attr = attr;
this.rhsChunks = rhsChunks;
}
}

View File

@ -1,53 +0,0 @@
/*
[The "BSD license"]
Copyright (c) 2011 Terence Parr
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.codegen.model.actions;
import org.antlr.v4.codegen.model.ModelElement;
import java.util.List;
/** */
public class SetDynScopeAttr_index extends SetDynScopeAttr {
@ModelElement public List<ActionChunk> indexChunks;
public SetDynScopeAttr_index(String scope, String attr, List<ActionChunk> indexChunks, List<ActionChunk> rhsChunks) {
super(scope, attr, rhsChunks);
this.indexChunks = indexChunks;
}
// @Override
// public List<String> getChildren() {
// final List<String> sup = super.getChildren();
// return new ArrayList<String>() {{
// if ( sup!=null ) addAll(sup);
// add("indexChunks");
// }};
// }
}

View File

@ -1,39 +0,0 @@
/*
[The "BSD license"]
Copyright (c) 2011 Terence Parr
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.codegen.model.actions;
import java.util.List;
/** */
public class SetDynScopeAttr_negIndex extends SetDynScopeAttr_index {
public SetDynScopeAttr_negIndex(String scope, String attr, List<ActionChunk> indexChunks, List<ActionChunk> rhsChunks) {
super(scope, attr, indexChunks, rhsChunks);
}
}

View File

@ -424,6 +424,7 @@ PROTECTED : 'protected' ;
PUBLIC : 'public' ;
PRIVATE : 'private' ;
RETURNS : 'returns' ;
LOCALS : 'locals' ;
THROWS : 'throws' ;
CATCH : 'catch' ;
FINALLY : 'finally' ;

View File

@ -239,11 +239,6 @@ prequelConstruct
// {tree} parser.
tokensSpec
| // A declaration of a scope that may be used in multiple rules within
// the grammar spec, rather than being delcared and therefore associated
// with, a specific rule.
attrScope
| // A declaration of language target implemented constructs. All such
// action sections start with '@' and are given to the language target's
// StringTemplate group. For instance @parser::header and @lexer::header
@ -324,13 +319,6 @@ tokenSpec
| RULE_REF // INVALID! (an error alt)
;
// A declaration of a scope that may be used in multiple rules within
// the grammar spec, rather than being declared within and therefore associated
// with, a specific rule.
attrScope
: SCOPE id ACTION -> ^(SCOPE id ACTION<ActionAST>)
;
// A declaration of a language target specifc section,
// such as @header, @includes and so on. We do not verify these
// sections, they are just passed on to the language target.
@ -414,6 +402,8 @@ rule
ruleReturns?
throwsSpec?
locals?
// Now, before the rule specification itself, which is introduced
// with a COLON, we may have zero or more configuration sections.
@ -441,7 +431,7 @@ rule
exceptionGroup
-> ^( RULE<RuleAST> id DOC_COMMENT? ruleModifiers? ARG_ACTION<ActionAST>?
ruleReturns? rulePrequels? ruleBlock exceptionGroup*
ruleReturns? throwsSpec? locals? rulePrequels? ruleBlock exceptionGroup*
)
;
@ -473,12 +463,11 @@ rulePrequels
: sync (rulePrequel sync)* -> rulePrequel*
;
// An individual rule level configuration as referenced by the ruleActions
// An individual rule level configuration as referenced by the ruleActions
// rule above.
//
rulePrequel
: ruleScopeSpec
| optionsSpec
: optionsSpec
| ruleAction
;
@ -507,14 +496,8 @@ throwsSpec
: THROWS qid (COMMA qid)* -> ^(THROWS qid+)
;
// As well as supporting globally specifed scopes, ANTLR supports rule
// level scopes, which are tracked in a rule specific stack. Rule specific
// scopes are specified at this level, and globally specified scopes
// are merely referenced here.
ruleScopeSpec
: SCOPE ACTION -> ^(SCOPE ACTION)
| SCOPE id (COMMA id)* SEMI -> ^(SCOPE id+)
;
// locals [Cat x, float g]
locals : LOCALS^ ARG_ACTION<ActionAST> ;
// @ Sections are generally target language specific things
// such as local variable declarations, code to run before the

View File

@ -26,6 +26,8 @@
/** The definitive ANTLR v3 tree grammar to parse ANTLR v4 grammars.
* Parses trees created in ANTLRParser.g.
OBSOLETE; See tree visitor grammar.
*/
tree grammar ASTVerifier;
options {

View File

@ -51,45 +51,6 @@ QUALIFIED_ATTR
: '$' x=ID '.' y=ID {input.LA(1)!='('}? {delegate.qualifiedAttr($text, $x, $y);}
;
SET_DYNAMIC_SCOPE_ATTR
: '$' x=ID '::' y=ID WS? '=' expr=ATTR_VALUE_EXPR ';'
{delegate.setDynamicScopeAttr($text, $x, $y, $expr);}
;
DYNAMIC_SCOPE_ATTR
: '$' x=ID '::' y=ID {delegate.dynamicScopeAttr($text, $x, $y);}
;
/** To access deeper (than top of stack) scopes, use the notation:
*
* $x[-1]::y previous (just under top of stack)
* $x[-i]::y top of stack - i where the '-' MUST BE PRESENT;
* i.e., i cannot simply be negative without the '-' sign!
* $x[i]::y absolute index i (0..size-1)
* $x[0]::y is the absolute 0 indexed element (bottom of the stack)
*/
SET_DYNAMIC_NEGATIVE_INDEXED_SCOPE_ATTR
: '$' x=ID '[' '-' index=SCOPE_INDEX_EXPR ']' '::' y=ID
WS? '=' expr=ATTR_VALUE_EXPR ';'
{delegate.setDynamicNegativeIndexedScopeAttr($text, $x, $y, $index, $expr);}
;
DYNAMIC_NEGATIVE_INDEXED_SCOPE_ATTR
: '$' x=ID '[' '-' index=SCOPE_INDEX_EXPR ']' '::' y=ID
{delegate.dynamicNegativeIndexedScopeAttr($text, $x, $y, $index);}
;
SET_DYNAMIC_ABSOLUTE_INDEXED_SCOPE_ATTR
: '$' x=ID '[' index=SCOPE_INDEX_EXPR ']' '::' y=ID
WS? '=' expr=ATTR_VALUE_EXPR ';'
{delegate.setDynamicAbsoluteIndexedScopeAttr($text, $x, $y, $index, $expr);}
;
DYNAMIC_ABSOLUTE_INDEXED_SCOPE_ATTR
: '$' x=ID '[' index=SCOPE_INDEX_EXPR ']' '::' y=ID
{delegate.dynamicAbsoluteIndexedScopeAttr($text, $x, $y, $index);}
;
SET_ATTR
: '$' x=ID WS? '=' expr=ATTR_VALUE_EXPR ';' {delegate.setAttr($text, $x, $expr);}
;

View File

@ -38,13 +38,6 @@ public interface ActionSplitterListener {
void setAttr(String expr, Token x, Token rhs);
void attr(String expr, Token x);
void setDynamicScopeAttr(String expr, Token x, Token y, Token rhs);
void dynamicScopeAttr(String expr, Token x, Token y);
void setDynamicNegativeIndexedScopeAttr(String expr, Token x, Token y, Token index, Token rhs);
void dynamicNegativeIndexedScopeAttr(String expr, Token x, Token y, Token index);
void setDynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y, Token index, Token rhs);
void dynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y, Token index);
void templateInstance(String expr);
void indirectTemplateInstance(String expr);
void setExprAttribute(String expr); // TODO: rename

View File

@ -126,7 +126,6 @@ public void grammarOption(GrammarAST ID, String value) { }
public void ruleOption(GrammarAST ID, String value) { }
public void blockOption(GrammarAST ID, String value) { }
public void tokenAlias(GrammarAST ID, GrammarAST literal) { }
public void globalScopeDef(GrammarAST ID, ActionAST elems) { }
public void globalNamedAction(GrammarAST scope, GrammarAST ID, ActionAST action) { }
public void importGrammar(GrammarAST label, GrammarAST ID) { }
@ -192,7 +191,6 @@ prequelConstruct
: optionsSpec
| delegateGrammars
| tokensSpec
| attrScope
| action
;
@ -235,10 +233,6 @@ tokenSpec
| ID {tokenAlias($ID, null);}
;
attrScope
: ^(SCOPE ID ACTION) {if ( inContext("GRAMMAR") ) globalScopeDef($ID, (ActionAST)$ACTION);}
;
action
: ^(AT sc=ID? name=ID ACTION) {globalNamedAction($sc, $name, (ActionAST)$ACTION);}
;
@ -260,8 +254,8 @@ currentOuterAltNumber=0;
ARG_ACTION?
ret=ruleReturns?
thr=throwsSpec?
( ruleScopeSpec
| opts=optionsSpec
loc=locals?
( opts=optionsSpec
| a=ruleAction {actions.add($a.start);}
)*
{discoverRule((RuleAST)$RULE, $ID, mods, (ActionAST)$ARG_ACTION,
@ -284,7 +278,14 @@ finallyClause
: ^(FINALLY ACTION) {finallyAction((ActionAST)$ACTION);}
;
locals
: ^(LOCAlS ARG_ACTION)
;
r[int a, int b] returns [int j, float k]
:
;
ruleReturns
: ^(RETURNS ARG_ACTION)
;
@ -292,11 +293,6 @@ throwsSpec
: ^(THROWS ID+)
;
ruleScopeSpec
: ^(SCOPE ACTION)
| ^(SCOPE ID+)
;
ruleAction
: ^(AT ID ACTION)
;

View File

@ -70,6 +70,7 @@ rec_rule returns [boolean isLeftRec]
(^(ARG ARG_ACTION))?
(^(RET ARG_ACTION))?
( ^(THROWS .+) )?
( ^(LOCALS ARG_ACTION) )?
( ^(OPTIONS .*)
| ^(AT ID ACTION)
)*

View File

@ -58,16 +58,6 @@ public class ScopeParser {
*/
public static AttributeDict parseTypeList(String s) { return parse(s, ','); }
public static AttributeDict parseDynamicScope(String s) {
// ignore outer {..} if present
s = s.trim();
if ( s.startsWith("{") ) {
int lastCurly = s.lastIndexOf('}');
s = s.substring(1, lastCurly);
}
return parse(s, ';');
}
public static AttributeDict parse(String s, char separator) {
int i = 0;
int n = s.length();

View File

@ -140,9 +140,6 @@ public class AttributeChecks implements ActionSplitterListener {
public void attr(String expr, Token x) {
if ( node.resolver.resolveToAttribute(x.getText(), node)==null ) {
if ( node.resolver.resolveToDynamicScope(x.getText(), node)!=null ) {
return; // $S for scope S is ok
}
if ( node.resolver.resolvesToToken(x.getText(), node) ) {
return; // $ID for token ref or label of token
}
@ -159,51 +156,6 @@ public class AttributeChecks implements ActionSplitterListener {
}
}
public void setDynamicScopeAttr(String expr, Token x, Token y, Token rhs) {
//System.out.println("SET "+x+" :: "+y);
dynamicScopeAttr(expr, x, y);
new AttributeChecks(g, r, alt, node, rhs).examineAction();
}
public void dynamicScopeAttr(String expr, Token x, Token y) {
//System.out.println(x+" :: "+y);
AttributeDict s = node.resolver.resolveToDynamicScope(x.getText(), node);
if ( s==null ) {
errMgr.grammarError(ErrorType.UNKNOWN_DYNAMIC_SCOPE,
g.fileName, x, x.getText(), expr);
return;
}
Attribute a = s.get(y.getText());
if ( a==null ) {
errMgr.grammarError(ErrorType.UNKNOWN_DYNAMIC_SCOPE_ATTRIBUTE,
g.fileName, y, x.getText(), y.getText(), expr);
}
}
public void setDynamicNegativeIndexedScopeAttr(String expr, Token x, Token y,
Token index, Token rhs) {
setDynamicScopeAttr(expr, x, y, rhs);
new AttributeChecks(g, r, alt, node, index).examineAction();
}
public void dynamicNegativeIndexedScopeAttr(String expr, Token x, Token y,
Token index) {
dynamicScopeAttr(expr, x, y);
new AttributeChecks(g, r, alt, node, index).examineAction();
}
public void setDynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y,
Token index, Token rhs) {
setDynamicScopeAttr(expr, x, y, rhs);
new AttributeChecks(g, r, alt, node, index).examineAction();
}
public void dynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y,
Token index) {
dynamicScopeAttr(expr, x, y);
new AttributeChecks(g, r, alt, node, index).examineAction();
}
public void unknownSyntax(Token t) {
errMgr.grammarError(ErrorType.INVALID_TEMPLATE_ACTION,
g.fileName, t, t.getText());

View File

@ -45,27 +45,10 @@ public class BlankActionSplitterListener implements ActionSplitterListener {
public void attr(String expr, Token x) {
}
public void setDynamicScopeAttr(String expr, Token x, Token y, Token rhs) {
}
public void dynamicScopeAttr(String expr, Token x, Token y) {
}
public void setDynamicNegativeIndexedScopeAttr(String expr, Token x, Token y, Token index, Token rhs) {
}
public void dynamicNegativeIndexedScopeAttr(String expr, Token x, Token y, Token index) {
}
public void setDynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y, Token index, Token rhs) {
}
public void dynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y, Token index) {
}
public void templateInstance(String expr) {
}
public void indirectTemplateInstance(String expr) {
}

View File

@ -46,7 +46,6 @@ public class SymbolChecks {
SymbolCollector collector;
Map<String, Rule> nameToRuleMap = new HashMap<String, Rule>();
Set<String> tokenIDs = new HashSet<String>();
Set<String> globalScopeNames = new HashSet<String>();
Map<String, Set<String>> actionScopeToActionNames = new HashMap<String, Set<String>>();
// DoubleKeyMap<String, String, GrammarAST> namedActions =
// new DoubleKeyMap<String, String, GrammarAST>();
@ -72,7 +71,6 @@ public class SymbolChecks {
public void process() {
// methods affect fields, but no side-effects outside this object
// So, call order sensitive
checkScopeRedefinitions(collector.scopes); // sets globalScopeNames
//checkForImportedRuleIssues(collector.qualifiedRulerefs);
// done in sem pipe for now
checkForRuleConflicts(collector.rules); // sets nameToRuleMap
@ -96,11 +94,6 @@ public class SymbolChecks {
errMgr.grammarError(ErrorType.RULE_REDEFINITION,
r.g.fileName, idNode.token, r.name);
}
if ( globalScopeNames.contains(r.name) ) {
GrammarAST idNode = (GrammarAST)r.ast.getChild(0);
errMgr.grammarError(ErrorType.SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE,
r.g.fileName, idNode.token, r.name);
}
}
}
@ -133,22 +126,6 @@ public class SymbolChecks {
}
}
public void checkScopeRedefinitions(List<AttributeDict> dicts) {
if ( dicts ==null ) return;
for (int i=0; i< dicts.size(); i++) {
AttributeDict s = dicts.get(i);
//GrammarAST idNode = (GrammarAST)s.getChild(0);
if ( !globalScopeNames.contains(s.getName()) ) {
globalScopeNames.add(s.getName());
}
else {
GrammarAST idNode = (GrammarAST) s.ast.getParent().getChild(0);
errMgr.grammarError(ErrorType.SCOPE_REDEFINITION,
idNode.g.fileName, idNode.token, s.getName());
}
}
}
/** Catch:
tokens { A='a'; A; } can't redefine token type if has alias
tokens { A; A='a'; } can't redefine token type if has alias
@ -201,15 +178,11 @@ public class SymbolChecks {
}
public void checkForTokenConflicts(List<GrammarAST> tokenIDRefs) {
for (GrammarAST a : tokenIDRefs) {
Token t = a.token;
String ID = t.getText();
tokenIDs.add(ID);
if ( globalScopeNames.contains(t.getText()) ) {
errMgr.grammarError(ErrorType.SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE,
g.fileName, t, ID);
}
}
// for (GrammarAST a : tokenIDRefs) {
// Token t = a.token;
// String ID = t.getText();
// tokenIDs.add(ID);
// }
}
public void checkForUndefinedTokensInRewrite() {
@ -234,7 +207,6 @@ public class SymbolChecks {
public void checkForLabelConflicts(List<Rule> rules) {
for (Rule r : rules) {
checkForRuleArgumentAndReturnValueConflicts(r);
checkForRuleScopeAttributeConflict(r);
Map<String, LabelElementPair> labelNameSpace =
new HashMap<String, LabelElementPair>();
for (int i=1; i<=r.numberOfAlts; i++) {
@ -271,10 +243,7 @@ public class SymbolChecks {
ErrorType etype = ErrorType.INVALID;
Object arg2 = null;
String name = labelID.getText();
if ( globalScopeNames.contains(name) ) {
etype = ErrorType.SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE;
}
else if ( nameToRuleMap.containsKey(name) ) {
if ( nameToRuleMap.containsKey(name) ) {
etype = ErrorType.LABEL_CONFLICTS_WITH_RULE;
}
else if ( tokenIDs.contains(name) ) {
@ -312,33 +281,6 @@ public class SymbolChecks {
}
}
/** Check for collision of a rule-scope dynamic attribute with:
* arg, return value, rule name itself. Labels are checked elsewhere.
*/
public void checkForRuleScopeAttributeConflict(Rule r) {
if ( r.scope ==null ) return;
for (Attribute a : r.scope.attributes.values()) {
ErrorType msgID = ErrorType.INVALID;
Object arg2 = null;
String attrName = a.name;
if ( r.name.equals(attrName) ) {
msgID = ErrorType.ATTRIBUTE_CONFLICTS_WITH_RULE;
arg2 = r.name;
}
else if ( (r.retvals!=null&&r.retvals.get(attrName)!=null) ||
(r.args!=null&&r.args.get(attrName)!=null) )
{
msgID = ErrorType.ATTRIBUTE_CONFLICTS_WITH_RULE_ARG_RETVAL;
arg2 = r.name;
}
if ( msgID!=ErrorType.INVALID ) {
errMgr.grammarError(msgID,g.fileName,
r.scope.ast.token,
attrName,arg2);
}
}
}
// CAN ONLY CALL THE TWO NEXT METHODS AFTER GRAMMAR HAS RULE DEFS (see semanticpipeline)
public void checkRuleArgs(Grammar g, List<GrammarAST> rulerefs) {

View File

@ -74,15 +74,6 @@ public class SymbolCollector extends GrammarTreeVisitor {
public void process(GrammarAST ast) { visitGrammar(ast); }
@Override
public void globalScopeDef(GrammarAST ID, ActionAST elems) {
AttributeDict s = ScopeParser.parseDynamicScope(elems.getText());
s.type = AttributeDict.DictType.GLOBAL_SCOPE;
s.name = ID.getText();
s.ast = elems;
scopes.add(s);
}
@Override
public void globalNamedAction(GrammarAST scope, GrammarAST ID, ActionAST action) {
namedActions.add((GrammarAST)ID.getParent());

View File

@ -102,7 +102,6 @@ public class Alternative implements AttributeResolver {
if ( resolvesToToken(x, node) ) return true;
if ( x.equals(rule.name) ) return true; // $r for action in rule r, $r is a dict
if ( rule!=null && rule.scope!=null ) return true;
if ( rule.g.scopes.get(x)!=null ) return true;
return false;
}
@ -136,12 +135,6 @@ public class Alternative implements AttributeResolver {
return null;
}
public AttributeDict resolveToDynamicScope(String x, ActionAST node) {
Rule r = resolveToRule(x);
if ( r!=null && r.scope !=null ) return r.scope;
return rule.resolveToDynamicScope(x, node);
}
public boolean resolvesToLabel(String x, ActionAST node) {
LabelElementPair anyLabelDef = getAnyLabelDef(x);
return anyLabelDef!=null &&

View File

@ -65,5 +65,4 @@ public interface AttributeResolver {
public boolean resolvesToToken(String x, ActionAST node);
public Attribute resolveToAttribute(String x, ActionAST node);
public Attribute resolveToAttribute(String x, String y, ActionAST node);
public AttributeDict resolveToDynamicScope(String x, ActionAST node);
}

View File

@ -145,7 +145,6 @@ public class Grammar implements AttributeResolver {
* sempred index is 0..n-1 */
public LinkedHashMap<PredAST, Integer> sempreds = new LinkedHashMap<PredAST, Integer>();
public Map<String, AttributeDict> scopes = new LinkedHashMap<String, AttributeDict>();
public static final String AUTO_GENERATED_TOKEN_NAME_PREFIX = "T__";
public Grammar(Tool tool, GrammarRootAST ast) {
@ -304,8 +303,6 @@ public class Grammar implements AttributeResolver {
return getRule(ruleName);
}
public void defineScope(AttributeDict s) { scopes.put(s.getName(), s); }
/** Get list of all imports from all grammars in the delegate subtree of g.
* The grammars are in import tree preorder. Don't include ourselves
* in list as we're not a delegate of ourselves.
@ -609,10 +606,6 @@ public class Grammar implements AttributeResolver {
return null;
}
public AttributeDict resolveToDynamicScope(String x, ActionAST node) {
return scopes.get(x);
}
public boolean resolvesToLabel(String x, ActionAST node) { return false; }
public boolean resolvesToListLabel(String x, ActionAST node) { return false; }
@ -620,7 +613,7 @@ public class Grammar implements AttributeResolver {
public boolean resolvesToToken(String x, ActionAST node) { return false; }
public boolean resolvesToAttributeDict(String x, ActionAST node) {
return scopes.get(x)!=null;
return false;
}
/** Given a grammar type, what should be the default action scope?

View File

@ -29,7 +29,6 @@
package org.antlr.v4.tool;
import org.antlr.runtime.Token;
import org.antlr.v4.parse.ANTLRParser;
import org.stringtemplate.v4.misc.MultiMap;
@ -77,9 +76,6 @@ public class Rule implements AttributeResolver {
public AttributeDict retvals;
public AttributeDict scope; // scope { int i; } // TODO: remove
/** A list of scope names used by this rule */
public List<Token> useScopes;
/** In which grammar does this rule live? */
public Grammar g;
@ -221,12 +217,6 @@ public class Rule implements AttributeResolver {
}
public AttributeDict resolveToDynamicScope(String x, ActionAST node) {
Rule r = resolveToRule(x);
if ( r!=null && r.scope!=null ) return r.scope;
return g.scopes.get(x);
}
public boolean resolvesToLabel(String x, ActionAST node) {
return false;
}
@ -248,7 +238,6 @@ public class Rule implements AttributeResolver {
if ( resolvesToToken(x, node) ) return true;
if ( x.equals(name) ) return true; // $r for action in rule r, $r is a dict
if ( scope!=null ) return true;
if ( g.scopes.get(x)!=null ) return true;
return false;
}

View File

@ -18,7 +18,6 @@ grammarSpec:
<<
parser grammar P;
options {k=2; output=AST;}
scope S {int x}
tokens { A; B='33'; }
@header {foo}
a : A;
@ -26,7 +25,6 @@ grammarSpec:
->
(PARSER_GRAMMAR P
(OPTIONS (= k 2) (= output AST))
(scope S {int x})
(tokens { A (= B '33'))
(@ header {foo})
(RULES (RULE a (BLOCK (ALT A)))))
@ -36,7 +34,6 @@ grammarSpec:
@header {foo}
tokens { A; B='33'; }
options {k=2; ASTLabel=a.b.c; output=AST;}
scope S {int x}
a : A;
>>
->
@ -44,7 +41,6 @@ grammarSpec:
(@ header {foo})
(tokens { A (= B '33'))
(OPTIONS (= k 2) (= ASTLabel a.b.c) (= output AST))
(scope S {int x})
(RULES (RULE a (BLOCK (ALT A)))))
<<
@ -68,8 +64,6 @@ rule:
<<
public a[int i] returns [int y]
options {backtrack=true;}
scope {int ss;}
scope S,T;
@init {blort}
: ID ;
>>
@ -79,26 +73,20 @@ rule:
int i
(returns int y)
(OPTIONS (= backtrack true))
(scope {int ss;})
(scope S T)
(@ init {blort})
(BLOCK (ALT ID)))
<<
a[int i] returns [int y]
@init {blort}
scope {int ss;}
options {backtrack=true;}
scope S,T;
: ID;
>>
->
(RULE a int i
(returns int y)
(@ init {blort})
(scope {int ss;})
(OPTIONS (= backtrack true))
(scope S T)
(BLOCK (ALT ID)))
<<
@ -120,6 +108,21 @@ rule:
(RULE a (BLOCK (ALT ID))
(catch A a {foo}) (catch B b {fu}) (finally {bar}))
<<
a[int i]
locals [int a, float b]
: A
;
>>
-> (RULE a int i (locals int a, float b) (BLOCK (ALT A)))
<<
a[int i] throws a.b.c
: A
;
>>
-> (RULE a int i (throws a.b.c) (BLOCK (ALT A)))
block:
"( ^(A B) | ^(b C) )" -> (BLOCK (ALT ("^(" A B)) (ALT ("^(" b C)))

View File

@ -21,451 +21,467 @@ public class TestASTStructure extends org.antlr.v4.gunit.gUnitBase {
@Test public void test_grammarSpec2() throws Exception {
// gunit test on line 18
RuleReturnScope rstruct = (RuleReturnScope)execParser("grammarSpec", "\n parser grammar P;\n options {k=2; output=AST;}\n scope S {int x}\n tokens { A; B='33'; }\n @header {foo}\n a : A;\n ", 18);
RuleReturnScope rstruct = (RuleReturnScope)execParser("grammarSpec", "\n parser grammar P;\n options {k=2; output=AST;}\n tokens { A; B='33'; }\n @header {foo}\n a : A;\n ", 18);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(PARSER_GRAMMAR P (OPTIONS (= k 2) (= output AST)) (scope S {int x}) (tokens { A (= B '33')) (@ header {foo}) (RULES (RULE a (BLOCK (ALT A)))))";
Object expecting = "(PARSER_GRAMMAR P (OPTIONS (= k 2) (= output AST)) (tokens { A (= B '33')) (@ header {foo}) (RULES (RULE a (BLOCK (ALT A)))))";
assertEquals("testing rule grammarSpec", expecting, actual);
}
@Test public void test_grammarSpec3() throws Exception {
// gunit test on line 34
RuleReturnScope rstruct = (RuleReturnScope)execParser("grammarSpec", "\n parser grammar P;\n @header {foo}\n tokens { A; B='33'; }\n options {k=2; ASTLabel=a.b.c; output=AST;}\n scope S {int x}\n a : A;\n ", 34);
// gunit test on line 32
RuleReturnScope rstruct = (RuleReturnScope)execParser("grammarSpec", "\n parser grammar P;\n @header {foo}\n tokens { A; B='33'; }\n options {k=2; ASTLabel=a.b.c; output=AST;}\n a : A;\n ", 32);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(PARSER_GRAMMAR P (@ header {foo}) (tokens { A (= B '33')) (OPTIONS (= k 2) (= ASTLabel a.b.c) (= output AST)) (scope S {int x}) (RULES (RULE a (BLOCK (ALT A)))))";
Object expecting = "(PARSER_GRAMMAR P (@ header {foo}) (tokens { A (= B '33')) (OPTIONS (= k 2) (= ASTLabel a.b.c) (= output AST)) (RULES (RULE a (BLOCK (ALT A)))))";
assertEquals("testing rule grammarSpec", expecting, actual);
}
@Test public void test_grammarSpec4() throws Exception {
// gunit test on line 50
RuleReturnScope rstruct = (RuleReturnScope)execParser("grammarSpec", "\n parser grammar P;\n import A=B, C;\n a : A;\n ", 50);
// gunit test on line 46
RuleReturnScope rstruct = (RuleReturnScope)execParser("grammarSpec", "\n parser grammar P;\n import A=B, C;\n a : A;\n ", 46);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(PARSER_GRAMMAR P (import (= A B) C) (RULES (RULE a (BLOCK (ALT A)))))";
assertEquals("testing rule grammarSpec", expecting, actual);
} @Test public void test_delegateGrammars1() throws Exception {
// gunit test on line 61
RuleReturnScope rstruct = (RuleReturnScope)execParser("delegateGrammars", "import A;", 61);
// gunit test on line 57
RuleReturnScope rstruct = (RuleReturnScope)execParser("delegateGrammars", "import A;", 57);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(import A)";
assertEquals("testing rule delegateGrammars", expecting, actual);
} @Test public void test_rule1() throws Exception {
// gunit test on line 64
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "a : A<X,Y=a.b.c>;", 64);
// gunit test on line 60
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "a : A<X,Y=a.b.c>;", 60);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(RULE a (BLOCK (ALT (A (ELEMENT_OPTIONS X (= Y a.b.c))))))";
assertEquals("testing rule rule", expecting, actual);
}
@Test public void test_rule2() throws Exception {
// gunit test on line 66
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "A : B+;", 66);
// gunit test on line 62
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "A : B+;", 62);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(RULE A (BLOCK (ALT (+ (BLOCK (ALT B))))))";
assertEquals("testing rule rule", expecting, actual);
}
@Test public void test_rule3() throws Exception {
// gunit test on line 68
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "\n public a[int i] returns [int y]\n options {backtrack=true;}\n scope {int ss;}\n scope S,T;\n @init {blort}\n : ID ;\n ", 68);
// gunit test on line 64
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "\n public a[int i] returns [int y]\n options {backtrack=true;}\n @init {blort}\n : ID ;\n ", 64);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(RULE a (RULEMODIFIERS public) int i (returns int y) (OPTIONS (= backtrack true)) (scope {int ss;}) (scope S T) (@ init {blort}) (BLOCK (ALT ID)))";
Object expecting = "(RULE a (RULEMODIFIERS public) int i (returns int y) (OPTIONS (= backtrack true)) (@ init {blort}) (BLOCK (ALT ID)))";
assertEquals("testing rule rule", expecting, actual);
}
@Test public void test_rule4() throws Exception {
// gunit test on line 87
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "\n a[int i] returns [int y]\n @init {blort}\n scope {int ss;}\n options {backtrack=true;}\n scope S,T;\n : ID;\n ", 87);
// gunit test on line 79
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "\n a[int i] returns [int y]\n @init {blort}\n options {backtrack=true;}\n : ID;\n ", 79);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(RULE a int i (returns int y) (@ init {blort}) (scope {int ss;}) (OPTIONS (= backtrack true)) (scope S T) (BLOCK (ALT ID)))";
Object expecting = "(RULE a int i (returns int y) (@ init {blort}) (OPTIONS (= backtrack true)) (BLOCK (ALT ID)))";
assertEquals("testing rule rule", expecting, actual);
}
@Test public void test_rule5() throws Exception {
// gunit test on line 104
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "\n a : ID ;\n catch[A b] {foo}\n finally {bar}\n ", 104);
// gunit test on line 92
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "\n a : ID ;\n catch[A b] {foo}\n finally {bar}\n ", 92);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(RULE a (BLOCK (ALT ID)) (catch A b {foo}) (finally {bar}))";
assertEquals("testing rule rule", expecting, actual);
}
@Test public void test_rule6() throws Exception {
// gunit test on line 113
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "\n a : ID ;\n catch[A a] {foo}\n catch[B b] {fu}\n finally {bar}\n ", 113);
// gunit test on line 101
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "\n a : ID ;\n catch[A a] {foo}\n catch[B b] {fu}\n finally {bar}\n ", 101);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(RULE a (BLOCK (ALT ID)) (catch A a {foo}) (catch B b {fu}) (finally {bar}))";
assertEquals("testing rule rule", expecting, actual);
}
@Test public void test_rule7() throws Exception {
// gunit test on line 111
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "\n\ta[int i]\n\tlocals [int a, float b]\n\t\t:\tA\n\t\t;\n\t", 111);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(RULE a int i (locals int a, float b) (BLOCK (ALT A)))";
assertEquals("testing rule rule", expecting, actual);
}
@Test public void test_rule8() throws Exception {
// gunit test on line 119
RuleReturnScope rstruct = (RuleReturnScope)execParser("rule", "\n\ta[int i] throws a.b.c\n\t\t:\tA\n\t\t;\n\t", 119);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(RULE a int i (throws a.b.c) (BLOCK (ALT A)))";
assertEquals("testing rule rule", expecting, actual);
} @Test public void test_block1() throws Exception {
// gunit test on line 124
RuleReturnScope rstruct = (RuleReturnScope)execParser("block", "( ^(A B) | ^(b C) )", 124);
// gunit test on line 127
RuleReturnScope rstruct = (RuleReturnScope)execParser("block", "( ^(A B) | ^(b C) )", 127);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(BLOCK (ALT (^( A B)) (ALT (^( b C)))";
assertEquals("testing rule block", expecting, actual);
} @Test public void test_ebnf1() throws Exception {
// gunit test on line 127
RuleReturnScope rstruct = (RuleReturnScope)execParser("ebnf", "(A|B)", 127);
// gunit test on line 130
RuleReturnScope rstruct = (RuleReturnScope)execParser("ebnf", "(A|B)", 130);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(BLOCK (ALT A) (ALT B))";
assertEquals("testing rule ebnf", expecting, actual);
}
@Test public void test_ebnf2() throws Exception {
// gunit test on line 128
RuleReturnScope rstruct = (RuleReturnScope)execParser("ebnf", "(A|B)?", 128);
// gunit test on line 131
RuleReturnScope rstruct = (RuleReturnScope)execParser("ebnf", "(A|B)?", 131);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(? (BLOCK (ALT A) (ALT B)))";
assertEquals("testing rule ebnf", expecting, actual);
}
@Test public void test_ebnf3() throws Exception {
// gunit test on line 129
RuleReturnScope rstruct = (RuleReturnScope)execParser("ebnf", "(A|B)*", 129);
// gunit test on line 132
RuleReturnScope rstruct = (RuleReturnScope)execParser("ebnf", "(A|B)*", 132);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(* (BLOCK (ALT A) (ALT B)))";
assertEquals("testing rule ebnf", expecting, actual);
}
@Test public void test_ebnf4() throws Exception {
// gunit test on line 130
RuleReturnScope rstruct = (RuleReturnScope)execParser("ebnf", "(A|B)+", 130);
// gunit test on line 133
RuleReturnScope rstruct = (RuleReturnScope)execParser("ebnf", "(A|B)+", 133);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(+ (BLOCK (ALT A) (ALT B)))";
assertEquals("testing rule ebnf", expecting, actual);
} @Test public void test_alternative1() throws Exception {
// gunit test on line 133
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "x+=ID* -> $x*", 133);
// gunit test on line 136
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "x+=ID* -> $x*", 136);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT (* (BLOCK (ALT (+= x ID))))) (-> (REWRITE_SEQ (* (REWRITE_BLOCK (REWRITE_SEQ x))))))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative2() throws Exception {
// gunit test on line 138
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> ...", 138);
// gunit test on line 141
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> ...", 141);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT A) (-> ...))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative3() throws Exception {
// gunit test on line 139
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> ", 139);
// gunit test on line 142
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> ", 142);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT A) (-> EPSILON))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative4() throws Exception {
// gunit test on line 141
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> foo(a={x}, b={y})", 141);
// gunit test on line 144
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> foo(a={x}, b={y})", 144);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT A) (-> (TEMPLATE foo (ARGLIST (= a {x}) (= b {y})))))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative5() throws Exception {
// gunit test on line 146
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> template(a={x}, b={y}) <<ick>>", 146);
// gunit test on line 149
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> template(a={x}, b={y}) <<ick>>", 149);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT A) (-> (TEMPLATE (ARGLIST (= a {x}) (= b {y})) <<ick>>)))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative6() throws Exception {
// gunit test on line 151
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> ({name})()", 151);
// gunit test on line 154
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> ({name})()", 154);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT A) (-> (TEMPLATE {name})))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative7() throws Exception {
// gunit test on line 153
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> {expr}", 153);
// gunit test on line 156
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> {expr}", 156);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT A) (-> (REWRITE_SEQ {expr})))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative8() throws Exception {
// gunit test on line 155
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "\n A -> {p1}? {e1}\n -> {e2}\n ->\n ", 155);
// gunit test on line 158
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "\n A -> {p1}? {e1}\n -> {e2}\n ->\n ", 158);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT A) (-> {p1}? (REWRITE_SEQ {e1})) (-> (REWRITE_SEQ {e2})))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative9() throws Exception {
// gunit test on line 167
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> A", 167);
// gunit test on line 170
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> A", 170);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT A) (-> (REWRITE_SEQ A)))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative10() throws Exception {
// gunit test on line 169
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "a -> a", 169);
// gunit test on line 172
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "a -> a", 172);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT a) (-> (REWRITE_SEQ a)))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative11() throws Exception {
// gunit test on line 171
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "a A X? Y* -> A a ^(TOP X)? Y*", 171);
// gunit test on line 174
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "a A X? Y* -> A a ^(TOP X)? Y*", 174);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT a A (? (BLOCK (ALT X))) (* (BLOCK (ALT Y)))) (-> (REWRITE_SEQ A a (? (REWRITE_BLOCK (REWRITE_SEQ (^( TOP X)))) (* (REWRITE_BLOCK (REWRITE_SEQ Y))))))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative12() throws Exception {
// gunit test on line 179
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> A[33]", 179);
// gunit test on line 182
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> A[33]", 182);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT A) (-> (REWRITE_SEQ (A 33))))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative13() throws Exception {
// gunit test on line 181
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> 'int' ^(A A)*", 181);
// gunit test on line 184
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "A -> 'int' ^(A A)*", 184);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT A) (-> (REWRITE_SEQ 'int' (* (REWRITE_BLOCK (REWRITE_SEQ (^( A A)))))))";
assertEquals("testing rule alternative", expecting, actual);
}
@Test public void test_alternative14() throws Exception {
// gunit test on line 186
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "\n A -> {p1}? A\n -> {p2}? B\n ->\n ", 186);
// gunit test on line 189
RuleReturnScope rstruct = (RuleReturnScope)execParser("alternative", "\n A -> {p1}? A\n -> {p2}? B\n ->\n ", 189);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(ALT_REWRITE (ALT A) (-> {p1}? (REWRITE_SEQ A)) (-> {p2}? (REWRITE_SEQ B)) (-> EPSILON))";
assertEquals("testing rule alternative", expecting, actual);
} @Test public void test_element1() throws Exception {
// gunit test on line 198
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "~A", 198);
// gunit test on line 201
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "~A", 201);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(~ (SET A))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element2() throws Exception {
// gunit test on line 199
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "b+", 199);
// gunit test on line 202
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "b+", 202);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(+ (BLOCK (ALT b)))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element3() throws Exception {
// gunit test on line 200
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "(b)+", 200);
// gunit test on line 203
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "(b)+", 203);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(+ (BLOCK (ALT b)))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element4() throws Exception {
// gunit test on line 201
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "b?", 201);
// gunit test on line 204
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "b?", 204);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(? (BLOCK (ALT b)))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element5() throws Exception {
// gunit test on line 202
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "(b)?", 202);
// gunit test on line 205
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "(b)?", 205);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(? (BLOCK (ALT b)))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element6() throws Exception {
// gunit test on line 203
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "(b)*", 203);
// gunit test on line 206
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "(b)*", 206);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(* (BLOCK (ALT b)))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element7() throws Exception {
// gunit test on line 204
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "b*", 204);
// gunit test on line 207
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "b*", 207);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(* (BLOCK (ALT b)))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element8() throws Exception {
// gunit test on line 205
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "'while'*", 205);
// gunit test on line 208
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "'while'*", 208);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(* (BLOCK (ALT 'while')))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element9() throws Exception {
// gunit test on line 206
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "'a'+", 206);
// gunit test on line 209
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "'a'+", 209);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(+ (BLOCK (ALT 'a')))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element10() throws Exception {
// gunit test on line 207
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "a[3]", 207);
// gunit test on line 210
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "a[3]", 210);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(a 3)";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element11() throws Exception {
// gunit test on line 208
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "'a'..'z'+", 208);
// gunit test on line 211
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "'a'..'z'+", 211);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(+ (BLOCK (ALT (.. 'a' 'z'))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element12() throws Exception {
// gunit test on line 209
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=ID", 209);
// gunit test on line 212
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=ID", 212);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(= x ID)";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element13() throws Exception {
// gunit test on line 210
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=ID?", 210);
// gunit test on line 213
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=ID?", 213);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(? (BLOCK (ALT (= x ID))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element14() throws Exception {
// gunit test on line 211
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=ID*", 211);
// gunit test on line 214
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=ID*", 214);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(* (BLOCK (ALT (= x ID))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element15() throws Exception {
// gunit test on line 212
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=b", 212);
// gunit test on line 215
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=b", 215);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(= x b)";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element16() throws Exception {
// gunit test on line 213
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=(A|B)", 213);
// gunit test on line 216
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=(A|B)", 216);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(= x (BLOCK (ALT A) (ALT B)))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element17() throws Exception {
// gunit test on line 214
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=(A|B)^", 214);
// gunit test on line 217
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=(A|B)^", 217);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(= x (^ (BLOCK (ALT A) (ALT B))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element18() throws Exception {
// gunit test on line 215
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=~(A|B)", 215);
// gunit test on line 218
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=~(A|B)", 218);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(= x (~ (BLOCK (ALT A) (ALT B))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element19() throws Exception {
// gunit test on line 216
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x+=~(A|B)", 216);
// gunit test on line 219
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x+=~(A|B)", 219);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(+= x (~ (BLOCK (ALT A) (ALT B))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element20() throws Exception {
// gunit test on line 217
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x+=~(A|B)+", 217);
// gunit test on line 220
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x+=~(A|B)+", 220);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(+ (BLOCK (ALT (+= x (~ (BLOCK (ALT A) (ALT B)))))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element21() throws Exception {
// gunit test on line 218
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=b+", 218);
// gunit test on line 221
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=b+", 221);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(+ (BLOCK (ALT (= x b))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element22() throws Exception {
// gunit test on line 219
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x+=ID*", 219);
// gunit test on line 222
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x+=ID*", 222);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(* (BLOCK (ALT (+= x ID))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element23() throws Exception {
// gunit test on line 220
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x+='int'*", 220);
// gunit test on line 223
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x+='int'*", 223);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(* (BLOCK (ALT (+= x 'int'))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element24() throws Exception {
// gunit test on line 221
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x+=b+", 221);
// gunit test on line 224
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x+=b+", 224);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(+ (BLOCK (ALT (+= x b))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element25() throws Exception {
// gunit test on line 222
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "('*'^)*", 222);
// gunit test on line 225
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "('*'^)*", 225);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(* (BLOCK (ALT (^ '*'))))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element26() throws Exception {
// gunit test on line 223
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "({blort} 'x')*", 223);
// gunit test on line 226
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "({blort} 'x')*", 226);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(* (BLOCK (ALT {blort} 'x')))";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element27() throws Exception {
// gunit test on line 224
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "A!", 224);
// gunit test on line 227
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "A!", 227);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(! A)";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element28() throws Exception {
// gunit test on line 225
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "A^", 225);
// gunit test on line 228
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "A^", 228);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(^ A)";
assertEquals("testing rule element", expecting, actual);
}
@Test public void test_element29() throws Exception {
// gunit test on line 226
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=A^", 226);
// gunit test on line 229
RuleReturnScope rstruct = (RuleReturnScope)execParser("element", "x=A^", 229);
Object actual = ((Tree)rstruct.getTree()).toStringTree();
Object expecting = "(= x (^ A))";
assertEquals("testing rule element", expecting, actual);

View File

@ -20,22 +20,6 @@ public class TestScopeParsing extends BaseTest {
"i,j, k", "{i=null i, j=null j, k=null k}",
};
String[] scopePairs = {
"int i;", "{i=int i}",
"int[] i; int j[];", "{i=int[] i, j=int [] j}",
"Map<A,B>[] i; int j[];", "{i=Map<A,B>[] i, j=int [] j}",
"int i = 34+a[3]; int j[] = new int[34];",
"{i=int i= 34+a[3], j=int [] j= new int[34]}",
"char *foo32[] = {1,2,3};", "{foo32=char *[] foo32= {1,2,3}}",
" int i; int c; int k; ", "{i=int i, c=int c, k=int k}",
" { int i; int c; int k; }", "{i=int i, c=int c, k=int k}",
// python/ruby style
"i", "{i=null i}",
" i ; j ;", "{i=null i, j=null j}",
"i; j; k;", "{i=null i, j=null j, k=null k}",
};
@Test public void testArgs() {
for (int i = 0; i < argPairs.length; i+=2) {
String input = argPairs[i];
@ -44,13 +28,4 @@ public class TestScopeParsing extends BaseTest {
assertEquals(expected, actual);
}
}
@Test public void testScopes() {
for (int i = 0; i < scopePairs.length; i+=2) {
String input = scopePairs[i];
String expected = scopePairs[i+1];
String actual = ScopeParser.parseDynamicScope(input).attributes.toString();
assertEquals(expected, actual);
}
}
}