forked from jasder/antlr
Added check for labels with different token types.
Spaces -> Tabs.
This commit is contained in:
parent
50646a6da8
commit
d5dda9f998
|
@ -43,6 +43,7 @@ import org.antlr.v4.tool.LabelElementPair;
|
||||||
import org.antlr.v4.tool.LexerGrammar;
|
import org.antlr.v4.tool.LexerGrammar;
|
||||||
import org.antlr.v4.tool.Rule;
|
import org.antlr.v4.tool.Rule;
|
||||||
import org.antlr.v4.tool.ast.GrammarAST;
|
import org.antlr.v4.tool.ast.GrammarAST;
|
||||||
|
import org.antlr.v4.tool.LabelType;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -115,8 +116,7 @@ public class SymbolChecks {
|
||||||
nameNode = (GrammarAST) ampersandAST.getChild(0);
|
nameNode = (GrammarAST) ampersandAST.getChild(0);
|
||||||
if (ampersandAST.getChildCount() == 2) {
|
if (ampersandAST.getChildCount() == 2) {
|
||||||
name = nameNode.getText();
|
name = nameNode.getText();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
scope = nameNode.getText();
|
scope = nameNode.getText();
|
||||||
name = ampersandAST.getChild(1).getText();
|
name = ampersandAST.getChild(1).getText();
|
||||||
}
|
}
|
||||||
|
@ -127,8 +127,7 @@ public class SymbolChecks {
|
||||||
}
|
}
|
||||||
if (!scopeActions.contains(name)) {
|
if (!scopeActions.contains(name)) {
|
||||||
scopeActions.add(name);
|
scopeActions.add(name);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
errMgr.grammarError(ErrorType.ACTION_REDEFINITION,
|
errMgr.grammarError(ErrorType.ACTION_REDEFINITION,
|
||||||
g.fileName, nameNode.token, name);
|
g.fileName, nameNode.token, name);
|
||||||
}
|
}
|
||||||
|
@ -173,9 +172,7 @@ public class SymbolChecks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkForTypeMismatch(LabelElementPair prevLabelPair,
|
void checkForTypeMismatch(LabelElementPair prevLabelPair, LabelElementPair labelPair) {
|
||||||
LabelElementPair labelPair)
|
|
||||||
{
|
|
||||||
// label already defined; if same type, no problem
|
// label already defined; if same type, no problem
|
||||||
if (prevLabelPair.type != labelPair.type) {
|
if (prevLabelPair.type != labelPair.type) {
|
||||||
String typeMismatchExpr = labelPair.type + "!=" + prevLabelPair.type;
|
String typeMismatchExpr = labelPair.type + "!=" + prevLabelPair.type;
|
||||||
|
@ -186,6 +183,19 @@ public class SymbolChecks {
|
||||||
labelPair.label.getText(),
|
labelPair.label.getText(),
|
||||||
typeMismatchExpr);
|
typeMismatchExpr);
|
||||||
}
|
}
|
||||||
|
if (!prevLabelPair.element.getText().equals(labelPair.element.getText()) &&
|
||||||
|
(prevLabelPair.type.equals(LabelType.RULE_LABEL) || prevLabelPair.type.equals(LabelType.RULE_LIST_LABEL)) &&
|
||||||
|
(labelPair.type.equals(LabelType.RULE_LABEL) || labelPair.type.equals(LabelType.RULE_LIST_LABEL))) {
|
||||||
|
|
||||||
|
String prevLabelOp = prevLabelPair.type.equals(LabelType.RULE_LIST_LABEL) ? "+=" : "=";
|
||||||
|
String labelOp = labelPair.type.equals(LabelType.RULE_LIST_LABEL) ? "+=" : "=";
|
||||||
|
errMgr.grammarError(
|
||||||
|
ErrorType.LABEL_TYPE_CONFLICT,
|
||||||
|
g.fileName,
|
||||||
|
labelPair.label.token,
|
||||||
|
labelPair.label.getText() + labelOp + labelPair.element.getText(),
|
||||||
|
prevLabelPair.label.getText() + prevLabelOp + prevLabelPair.element.getText());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkForLabelConflict(Rule r, GrammarAST labelID) {
|
public void checkForLabelConflict(Rule r, GrammarAST labelID) {
|
||||||
|
|
Loading…
Reference in New Issue