Merge branch 'fix-several-bugs' of git://github.com/sharwell/antlr4

This commit is contained in:
Terence Parr 2012-11-18 16:19:30 -08:00
commit 80f7c35a7c
4 changed files with 28 additions and 17 deletions

View File

@ -433,10 +433,16 @@ public class Tool {
public boolean checkForRuleIssues(final Grammar g) {
// check for redefined rules
GrammarAST RULES = (GrammarAST)g.ast.getFirstChildWithType(ANTLRParser.RULES);
List<RuleAST> rules = (List<RuleAST>)RULES.getChildren();
List<?> rules = (List<?>)RULES.getChildren();
if (rules == null) {
rules = Collections.emptyList();
}
final Map<String, RuleAST> ruleToAST = new HashMap<String, RuleAST>();
for (RuleAST r : rules) {
GrammarAST ID = (GrammarAST)r.getChild(0);
for (Object r : rules) {
RuleAST ruleAST = (RuleAST)r;
GrammarAST ID = (GrammarAST)ruleAST.getChild(0);
String ruleName = ID.getText();
RuleAST prev = ruleToAST.get(ruleName);
if ( prev !=null ) {
@ -446,10 +452,10 @@ public class Tool {
ID.getToken(),
ruleName,
prevChild.getToken().getLine());
r.dead = true;
ruleAST.dead = true;
continue;
}
ruleToAST.put(ruleName, r);
ruleToAST.put(ruleName, ruleAST);
}
// check for undefined rules
@ -457,6 +463,11 @@ public class Tool {
public boolean undefined = false;
@Override
public void tokenRef(TerminalAST ref) {
if ("EOF".equals(ref.getText())) {
// this is a special predefined reference
return;
}
if ( g.isLexer() ) ruleRef(ref, null);
}

View File

@ -298,15 +298,16 @@ ARG_ACTION
//
ACTION
: NESTED_ACTION
('?' {$type = SEMPRED;} )?
( '=>' // v3 gated sempred
{
Token t = new CommonToken(input, state.type, state.channel, state.tokenStartCharIndex, getCharIndex()-1);
t.setLine(state.tokenStartLine);
t.setText(state.text);
t.setCharPositionInLine(state.tokenStartCharPositionInLine);
grammarError(ErrorType.V3_GATED_SEMPRED, t);
}
( '?' {$type = SEMPRED;}
( (WSNLCHARS* '=>') => WSNLCHARS* '=>' // v3 gated sempred
{
Token t = new CommonToken(input, state.type, state.channel, state.tokenStartCharIndex, getCharIndex()-1);
t.setLine(state.tokenStartLine);
t.setText(state.text);
t.setCharPositionInLine(state.tokenStartCharPositionInLine);
grammarError(ErrorType.V3_GATED_SEMPRED, t);
}
)?
)?
;

View File

@ -347,8 +347,7 @@ public class BasicSemanticChecks extends GrammarTreeVisitor {
boolean outerMostAlt = blk.parent.getType() == RULE;
Tree rule = tree.getAncestor(RULE);
String fileName = tree.getToken().getInputStream().getSourceName();
if ( !outerMostAlt || tree.getChildIndex() != alt.getChildCount()-1 ||
blk.getChildCount()>1 )
if ( !outerMostAlt || blk.getChildCount()>1 )
{
ErrorType e = ErrorType.LEXER_COMMAND_PLACEMENT_ISSUE;
if ( tree.getType() == ACTION ) e = ErrorType.LEXER_ACTION_PLACEMENT_ISSUE;

View File

@ -151,7 +151,7 @@ public class SemanticPipeline {
void assignLexerTokenTypes(Grammar g, List<GrammarAST> tokensDefs) {
Grammar G = g.getOutermostGrammar(); // put in root, even if imported
for (GrammarAST def : tokensDefs) {
if ( def.getType()== ANTLRParser.ID ) G.defineTokenName(def.getText());
if ( def.getType()== ANTLRParser.TOKEN_REF ) G.defineTokenName(def.getText());
}
/* Define token types for nonfragment rules which do not include a 'type(...)'