ANTLR Parser für ASP Statements implementieren

This commit is contained in:
JanUlrich 2018-03-13 00:24:40 +01:00
parent dff72b0c97
commit 123f94aea7
11 changed files with 1205 additions and 4 deletions

15
pom.xml
View File

@ -71,6 +71,21 @@
</arguments>
</configuration>
</execution>
<execution>
<id>aspParser</id>
<goals>
<goal>antlr4</goal>
</goals>
<configuration>
<sourceDirectory>src/de/dhbwstuttgart/sat/asp/parser/antlr/</sourceDirectory>
<outputDirectory>src/de/dhbwstuttgart/sat/asp/parser/antlr/</outputDirectory>
<arguments>
<argument>-package</argument>
<argument>de.dhbwstuttgart.sat.asp.parser.antlr</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>

View File

@ -36,7 +36,8 @@ public class Clingo {
"/home/janulrich/Sync/HiwiJob/ResearchPapers/MasterarbeitStadelmeier/asp/clingo-5.2.1-linux-x86_64/clingo";
List<String> commands = new ArrayList<>();
commands.add(pathToClingo);
commands.add("--outf=2"); //use JSON-Output
//commands.add("--outf=2"); //use JSON-Output
commands.add("--outf=1"); //use JSON-Output
for(File file : input){
commands.add(file.getPath());
}

View File

@ -6,9 +6,17 @@ import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.sat.asp.ASPStringConverter;
import de.dhbwstuttgart.sat.asp.model.ASPRule;
import de.dhbwstuttgart.sat.asp.parser.antlr.UnifyResultBaseListener;
import de.dhbwstuttgart.sat.asp.parser.antlr.UnifyResultLexer;
import de.dhbwstuttgart.sat.asp.parser.antlr.UnifyResultListener;
import de.dhbwstuttgart.sat.asp.parser.antlr.UnifyResultParser;
import de.dhbwstuttgart.sat.asp.parser.model.ParsedType;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.result.*;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import javax.json.Json;
import javax.json.JsonArray;
@ -17,6 +25,7 @@ import java.io.StringReader;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Ablauf:
@ -26,7 +35,7 @@ import java.util.regex.Pattern;
* TODO: Überlegen welche Informationen noch nach der Unifizierung gebraucht werden
* -> Eigentlich nur die korrekten Namen der Typen und TPHs
*/
public class ASPParser {
public class ASPParser extends UnifyResultBaseListener {
private final Collection<TypePlaceholder> originalTPHs;
private ResultSet resultSet;
private Map<String, ParsedType> types = new HashMap<>();
@ -42,7 +51,58 @@ public class ASPParser {
return new ASPParser(toParse, oldPlaceholders).resultSet;
}
@Override
public void enterParameter(UnifyResultParser.ParameterContext ctx) {
}
@Override
public void enterEquals(UnifyResultParser.EqualsContext ctx) {
List<String> parameterList = ctx.parameterList().value().stream().map(v -> v.getText()).collect(Collectors.toList());
if(parameterList.size()<2)throw new DebugException("Fehler in Regex");
String ls = parameterList.get(0);
String rs = parameterList.get(1);
/*
RefTypeOrTPHOrWildcardOrGeneric lsType = this.getType(ls);
RefTypeOrTPHOrWildcardOrGeneric rsType = this.getType(rs);
if(lsType instanceof TypePlaceholder && rsType instanceof RefType)
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder) lsType, rsType);
else if(lsType instanceof TypePlaceholder && rsType instanceof TypePlaceholder)
return new PairTPHEqualTPH((TypePlaceholder)lsType, (TypePlaceholder)rsType);
else throw new NotImplementedException();
*/
}
@Override
public void enterSmaller(UnifyResultParser.SmallerContext ctx) {
}
@Override
public void enterTypeVar(UnifyResultParser.TypeVarContext ctx) {
}
@Override
public void enterType(UnifyResultParser.TypeContext ctx) {
super.enterType(ctx);
}
/*
private List<String> parsedRule;
private List<String> parseRule(String rule){
UnifyResultLexer lexer = new UnifyResultLexer(CharStreams.fromString(rule));
UnifyResultParser.AspruleContext parseTree = new UnifyResultParser(new CommonTokenStream(lexer)).asprule();
parsedRule = new ArrayList<>();
new ParseTreeWalker().walk(this, parseTree);
return parsedRule;
}
@Override
public void enterAsprule(UnifyResultParser.AspruleContext ctx) {
super.enterAsprule(ctx);
for(int i = 0; i< ctx.getChildCount();i++){
parsedRule.add(ctx.getChild(i).getText());
}
}
*/
private ASPParser(String toParse, Collection<TypePlaceholder> oldPlaceholders){
this.originalTPHs = oldPlaceholders;
JsonObject jsonResult = Json.createReader(new StringReader(toParse)).readObject();

View File

@ -0,0 +1,37 @@
grammar UnifyResult;
answer : 'ANSWER' (resultSetRule '.')*;
resultSetRule :
parameter
| equals
| smaller
| typeVar
| type
| otherRule
;
parameterList : '(' value (',' value)* ')';
value : NAME
| resultSetRule ;
parameter : PARAMLIST_NAME parameterList;
equals : EQUALS_NAME parameterList;
smaller : SMALLER_NAME parameterList;
typeVar : TYPEVAR_NAME parameterList;
type : TYPE_NAME parameterList;
otherRule : NAME parameterList;
//TODO: Es sollte Regeln für das Result set geben, welche sich nicht mit den anderen überdecken, dann auch nur diese im Result ausgeben
PARAMLIST_NAME : 'param';
EQUALS_NAME : 'equals';
SMALLER_NAME : 'smaller';
TYPEVAR_NAME : 'typeVar';
TYPE_NAME : 'type';
NAME : [a-zA-Z0-9_]+;
WS : [ \t\r\n\u000C]+ -> skip
;
LINE_COMMENT
: '%' ~[\r\n]* -> skip
;

View File

@ -0,0 +1,23 @@
T__0=1
T__1=2
T__2=3
T__3=4
T__4=5
PARAMLIST_NAME=6
EQUALS_NAME=7
SMALLER_NAME=8
TYPEVAR_NAME=9
TYPE_NAME=10
NAME=11
WS=12
LINE_COMMENT=13
'ANSWER'=1
'.'=2
'('=3
','=4
')'=5
'param'=6
'equals'=7
'smaller'=8
'typeVar'=9
'type'=10

View File

@ -0,0 +1,159 @@
// Generated from UnifyResult.g4 by ANTLR 4.7
package de.dhbwstuttgart.sat.asp.parser.antlr;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link UnifyResultListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
public class UnifyResultBaseListener implements UnifyResultListener {
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterAnswer(UnifyResultParser.AnswerContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitAnswer(UnifyResultParser.AnswerContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterResultSetRule(UnifyResultParser.ResultSetRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitResultSetRule(UnifyResultParser.ResultSetRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterParameterList(UnifyResultParser.ParameterListContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitParameterList(UnifyResultParser.ParameterListContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterValue(UnifyResultParser.ValueContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitValue(UnifyResultParser.ValueContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterParameter(UnifyResultParser.ParameterContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitParameter(UnifyResultParser.ParameterContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEquals(UnifyResultParser.EqualsContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEquals(UnifyResultParser.EqualsContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterSmaller(UnifyResultParser.SmallerContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitSmaller(UnifyResultParser.SmallerContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterTypeVar(UnifyResultParser.TypeVarContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitTypeVar(UnifyResultParser.TypeVarContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterType(UnifyResultParser.TypeContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitType(UnifyResultParser.TypeContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterOtherRule(UnifyResultParser.OtherRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitOtherRule(UnifyResultParser.OtherRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitEveryRule(ParserRuleContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitTerminal(TerminalNode node) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void visitErrorNode(ErrorNode node) { }
}

View File

@ -0,0 +1,134 @@
// Generated from UnifyResult.g4 by ANTLR 4.7
package de.dhbwstuttgart.sat.asp.parser.antlr;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class UnifyResultLexer extends Lexer {
static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, PARAMLIST_NAME=6, EQUALS_NAME=7,
SMALLER_NAME=8, TYPEVAR_NAME=9, TYPE_NAME=10, NAME=11, WS=12, LINE_COMMENT=13;
public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
public static String[] modeNames = {
"DEFAULT_MODE"
};
public static final String[] ruleNames = {
"T__0", "T__1", "T__2", "T__3", "T__4", "PARAMLIST_NAME", "EQUALS_NAME",
"SMALLER_NAME", "TYPEVAR_NAME", "TYPE_NAME", "NAME", "WS", "LINE_COMMENT"
};
private static final String[] _LITERAL_NAMES = {
null, "'ANSWER'", "'.'", "'('", "','", "')'", "'param'", "'equals'", "'smaller'",
"'typeVar'", "'type'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, null, null, null, null, null, "PARAMLIST_NAME", "EQUALS_NAME", "SMALLER_NAME",
"TYPEVAR_NAME", "TYPE_NAME", "NAME", "WS", "LINE_COMMENT"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
public UnifyResultLexer(CharStream input) {
super(input);
_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@Override
public String getGrammarFileName() { return "UnifyResult.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public String[] getChannelNames() { return channelNames; }
@Override
public String[] getModeNames() { return modeNames; }
@Override
public ATN getATN() { return _ATN; }
public static final String _serializedATN =
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\17c\b\1\4\2\t\2\4"+
"\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t"+
"\13\4\f\t\f\4\r\t\r\4\16\t\16\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\3\3\3\3\4"+
"\3\4\3\5\3\5\3\6\3\6\3\7\3\7\3\7\3\7\3\7\3\7\3\b\3\b\3\b\3\b\3\b\3\b\3"+
"\b\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\13"+
"\3\13\3\13\3\13\3\13\3\f\6\fP\n\f\r\f\16\fQ\3\r\6\rU\n\r\r\r\16\rV\3\r"+
"\3\r\3\16\3\16\7\16]\n\16\f\16\16\16`\13\16\3\16\3\16\2\2\17\3\3\5\4\7"+
"\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17\3\2\5\6\2\62;C\\"+
"aac|\5\2\13\f\16\17\"\"\4\2\f\f\17\17\2e\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3"+
"\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2"+
"\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\3\35"+
"\3\2\2\2\5$\3\2\2\2\7&\3\2\2\2\t(\3\2\2\2\13*\3\2\2\2\r,\3\2\2\2\17\62"+
"\3\2\2\2\219\3\2\2\2\23A\3\2\2\2\25I\3\2\2\2\27O\3\2\2\2\31T\3\2\2\2\33"+
"Z\3\2\2\2\35\36\7C\2\2\36\37\7P\2\2\37 \7U\2\2 !\7Y\2\2!\"\7G\2\2\"#\7"+
"T\2\2#\4\3\2\2\2$%\7\60\2\2%\6\3\2\2\2&\'\7*\2\2\'\b\3\2\2\2()\7.\2\2"+
")\n\3\2\2\2*+\7+\2\2+\f\3\2\2\2,-\7r\2\2-.\7c\2\2./\7t\2\2/\60\7c\2\2"+
"\60\61\7o\2\2\61\16\3\2\2\2\62\63\7g\2\2\63\64\7s\2\2\64\65\7w\2\2\65"+
"\66\7c\2\2\66\67\7n\2\2\678\7u\2\28\20\3\2\2\29:\7u\2\2:;\7o\2\2;<\7c"+
"\2\2<=\7n\2\2=>\7n\2\2>?\7g\2\2?@\7t\2\2@\22\3\2\2\2AB\7v\2\2BC\7{\2\2"+
"CD\7r\2\2DE\7g\2\2EF\7X\2\2FG\7c\2\2GH\7t\2\2H\24\3\2\2\2IJ\7v\2\2JK\7"+
"{\2\2KL\7r\2\2LM\7g\2\2M\26\3\2\2\2NP\t\2\2\2ON\3\2\2\2PQ\3\2\2\2QO\3"+
"\2\2\2QR\3\2\2\2R\30\3\2\2\2SU\t\3\2\2TS\3\2\2\2UV\3\2\2\2VT\3\2\2\2V"+
"W\3\2\2\2WX\3\2\2\2XY\b\r\2\2Y\32\3\2\2\2Z^\7\'\2\2[]\n\4\2\2\\[\3\2\2"+
"\2]`\3\2\2\2^\\\3\2\2\2^_\3\2\2\2_a\3\2\2\2`^\3\2\2\2ab\b\16\2\2b\34\3"+
"\2\2\2\6\2QV^\3\b\2\2";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -0,0 +1,23 @@
T__0=1
T__1=2
T__2=3
T__3=4
T__4=5
PARAMLIST_NAME=6
EQUALS_NAME=7
SMALLER_NAME=8
TYPEVAR_NAME=9
TYPE_NAME=10
NAME=11
WS=12
LINE_COMMENT=13
'ANSWER'=1
'.'=2
'('=3
','=4
')'=5
'param'=6
'equals'=7
'smaller'=8
'typeVar'=9
'type'=10

View File

@ -0,0 +1,110 @@
// Generated from UnifyResult.g4 by ANTLR 4.7
package de.dhbwstuttgart.sat.asp.parser.antlr;
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link UnifyResultParser}.
*/
public interface UnifyResultListener extends ParseTreeListener {
/**
* Enter a parse tree produced by {@link UnifyResultParser#answer}.
* @param ctx the parse tree
*/
void enterAnswer(UnifyResultParser.AnswerContext ctx);
/**
* Exit a parse tree produced by {@link UnifyResultParser#answer}.
* @param ctx the parse tree
*/
void exitAnswer(UnifyResultParser.AnswerContext ctx);
/**
* Enter a parse tree produced by {@link UnifyResultParser#resultSetRule}.
* @param ctx the parse tree
*/
void enterResultSetRule(UnifyResultParser.ResultSetRuleContext ctx);
/**
* Exit a parse tree produced by {@link UnifyResultParser#resultSetRule}.
* @param ctx the parse tree
*/
void exitResultSetRule(UnifyResultParser.ResultSetRuleContext ctx);
/**
* Enter a parse tree produced by {@link UnifyResultParser#parameterList}.
* @param ctx the parse tree
*/
void enterParameterList(UnifyResultParser.ParameterListContext ctx);
/**
* Exit a parse tree produced by {@link UnifyResultParser#parameterList}.
* @param ctx the parse tree
*/
void exitParameterList(UnifyResultParser.ParameterListContext ctx);
/**
* Enter a parse tree produced by {@link UnifyResultParser#value}.
* @param ctx the parse tree
*/
void enterValue(UnifyResultParser.ValueContext ctx);
/**
* Exit a parse tree produced by {@link UnifyResultParser#value}.
* @param ctx the parse tree
*/
void exitValue(UnifyResultParser.ValueContext ctx);
/**
* Enter a parse tree produced by {@link UnifyResultParser#parameter}.
* @param ctx the parse tree
*/
void enterParameter(UnifyResultParser.ParameterContext ctx);
/**
* Exit a parse tree produced by {@link UnifyResultParser#parameter}.
* @param ctx the parse tree
*/
void exitParameter(UnifyResultParser.ParameterContext ctx);
/**
* Enter a parse tree produced by {@link UnifyResultParser#equals}.
* @param ctx the parse tree
*/
void enterEquals(UnifyResultParser.EqualsContext ctx);
/**
* Exit a parse tree produced by {@link UnifyResultParser#equals}.
* @param ctx the parse tree
*/
void exitEquals(UnifyResultParser.EqualsContext ctx);
/**
* Enter a parse tree produced by {@link UnifyResultParser#smaller}.
* @param ctx the parse tree
*/
void enterSmaller(UnifyResultParser.SmallerContext ctx);
/**
* Exit a parse tree produced by {@link UnifyResultParser#smaller}.
* @param ctx the parse tree
*/
void exitSmaller(UnifyResultParser.SmallerContext ctx);
/**
* Enter a parse tree produced by {@link UnifyResultParser#typeVar}.
* @param ctx the parse tree
*/
void enterTypeVar(UnifyResultParser.TypeVarContext ctx);
/**
* Exit a parse tree produced by {@link UnifyResultParser#typeVar}.
* @param ctx the parse tree
*/
void exitTypeVar(UnifyResultParser.TypeVarContext ctx);
/**
* Enter a parse tree produced by {@link UnifyResultParser#type}.
* @param ctx the parse tree
*/
void enterType(UnifyResultParser.TypeContext ctx);
/**
* Exit a parse tree produced by {@link UnifyResultParser#type}.
* @param ctx the parse tree
*/
void exitType(UnifyResultParser.TypeContext ctx);
/**
* Enter a parse tree produced by {@link UnifyResultParser#otherRule}.
* @param ctx the parse tree
*/
void enterOtherRule(UnifyResultParser.OtherRuleContext ctx);
/**
* Exit a parse tree produced by {@link UnifyResultParser#otherRule}.
* @param ctx the parse tree
*/
void exitOtherRule(UnifyResultParser.OtherRuleContext ctx);
}

View File

@ -0,0 +1,639 @@
// Generated from UnifyResult.g4 by ANTLR 4.7
package de.dhbwstuttgart.sat.asp.parser.antlr;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class UnifyResultParser extends Parser {
static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, PARAMLIST_NAME=6, EQUALS_NAME=7,
SMALLER_NAME=8, TYPEVAR_NAME=9, TYPE_NAME=10, NAME=11, WS=12, LINE_COMMENT=13;
public static final int
RULE_answer = 0, RULE_resultSetRule = 1, RULE_parameterList = 2, RULE_value = 3,
RULE_parameter = 4, RULE_equals = 5, RULE_smaller = 6, RULE_typeVar = 7,
RULE_type = 8, RULE_otherRule = 9;
public static final String[] ruleNames = {
"answer", "resultSetRule", "parameterList", "value", "parameter", "equals",
"smaller", "typeVar", "type", "otherRule"
};
private static final String[] _LITERAL_NAMES = {
null, "'ANSWER'", "'.'", "'('", "','", "')'", "'param'", "'equals'", "'smaller'",
"'typeVar'", "'type'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, null, null, null, null, null, "PARAMLIST_NAME", "EQUALS_NAME", "SMALLER_NAME",
"TYPEVAR_NAME", "TYPE_NAME", "NAME", "WS", "LINE_COMMENT"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "UnifyResult.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public UnifyResultParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
public static class AnswerContext extends ParserRuleContext {
public List<ResultSetRuleContext> resultSetRule() {
return getRuleContexts(ResultSetRuleContext.class);
}
public ResultSetRuleContext resultSetRule(int i) {
return getRuleContext(ResultSetRuleContext.class,i);
}
public AnswerContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_answer; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterAnswer(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitAnswer(this);
}
}
public final AnswerContext answer() throws RecognitionException {
AnswerContext _localctx = new AnswerContext(_ctx, getState());
enterRule(_localctx, 0, RULE_answer);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(20);
match(T__0);
setState(26);
_errHandler.sync(this);
_la = _input.LA(1);
while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << PARAMLIST_NAME) | (1L << EQUALS_NAME) | (1L << SMALLER_NAME) | (1L << TYPEVAR_NAME) | (1L << TYPE_NAME) | (1L << NAME))) != 0)) {
{
{
setState(21);
resultSetRule();
setState(22);
match(T__1);
}
}
setState(28);
_errHandler.sync(this);
_la = _input.LA(1);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class ResultSetRuleContext extends ParserRuleContext {
public ParameterContext parameter() {
return getRuleContext(ParameterContext.class,0);
}
public EqualsContext equals() {
return getRuleContext(EqualsContext.class,0);
}
public SmallerContext smaller() {
return getRuleContext(SmallerContext.class,0);
}
public TypeVarContext typeVar() {
return getRuleContext(TypeVarContext.class,0);
}
public TypeContext type() {
return getRuleContext(TypeContext.class,0);
}
public OtherRuleContext otherRule() {
return getRuleContext(OtherRuleContext.class,0);
}
public ResultSetRuleContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_resultSetRule; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterResultSetRule(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitResultSetRule(this);
}
}
public final ResultSetRuleContext resultSetRule() throws RecognitionException {
ResultSetRuleContext _localctx = new ResultSetRuleContext(_ctx, getState());
enterRule(_localctx, 2, RULE_resultSetRule);
try {
setState(35);
_errHandler.sync(this);
switch (_input.LA(1)) {
case PARAMLIST_NAME:
enterOuterAlt(_localctx, 1);
{
setState(29);
parameter();
}
break;
case EQUALS_NAME:
enterOuterAlt(_localctx, 2);
{
setState(30);
equals();
}
break;
case SMALLER_NAME:
enterOuterAlt(_localctx, 3);
{
setState(31);
smaller();
}
break;
case TYPEVAR_NAME:
enterOuterAlt(_localctx, 4);
{
setState(32);
typeVar();
}
break;
case TYPE_NAME:
enterOuterAlt(_localctx, 5);
{
setState(33);
type();
}
break;
case NAME:
enterOuterAlt(_localctx, 6);
{
setState(34);
otherRule();
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class ParameterListContext extends ParserRuleContext {
public List<ValueContext> value() {
return getRuleContexts(ValueContext.class);
}
public ValueContext value(int i) {
return getRuleContext(ValueContext.class,i);
}
public ParameterListContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_parameterList; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterParameterList(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitParameterList(this);
}
}
public final ParameterListContext parameterList() throws RecognitionException {
ParameterListContext _localctx = new ParameterListContext(_ctx, getState());
enterRule(_localctx, 4, RULE_parameterList);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(37);
match(T__2);
setState(38);
value();
setState(43);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==T__3) {
{
{
setState(39);
match(T__3);
setState(40);
value();
}
}
setState(45);
_errHandler.sync(this);
_la = _input.LA(1);
}
setState(46);
match(T__4);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class ValueContext extends ParserRuleContext {
public TerminalNode NAME() { return getToken(UnifyResultParser.NAME, 0); }
public ResultSetRuleContext resultSetRule() {
return getRuleContext(ResultSetRuleContext.class,0);
}
public ValueContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_value; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterValue(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitValue(this);
}
}
public final ValueContext value() throws RecognitionException {
ValueContext _localctx = new ValueContext(_ctx, getState());
enterRule(_localctx, 6, RULE_value);
try {
setState(50);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
setState(48);
match(NAME);
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
setState(49);
resultSetRule();
}
break;
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class ParameterContext extends ParserRuleContext {
public TerminalNode PARAMLIST_NAME() { return getToken(UnifyResultParser.PARAMLIST_NAME, 0); }
public ParameterListContext parameterList() {
return getRuleContext(ParameterListContext.class,0);
}
public ParameterContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_parameter; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterParameter(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitParameter(this);
}
}
public final ParameterContext parameter() throws RecognitionException {
ParameterContext _localctx = new ParameterContext(_ctx, getState());
enterRule(_localctx, 8, RULE_parameter);
try {
enterOuterAlt(_localctx, 1);
{
setState(52);
match(PARAMLIST_NAME);
setState(53);
parameterList();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class EqualsContext extends ParserRuleContext {
public TerminalNode EQUALS_NAME() { return getToken(UnifyResultParser.EQUALS_NAME, 0); }
public ParameterListContext parameterList() {
return getRuleContext(ParameterListContext.class,0);
}
public EqualsContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_equals; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterEquals(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitEquals(this);
}
}
public final EqualsContext equals() throws RecognitionException {
EqualsContext _localctx = new EqualsContext(_ctx, getState());
enterRule(_localctx, 10, RULE_equals);
try {
enterOuterAlt(_localctx, 1);
{
setState(55);
match(EQUALS_NAME);
setState(56);
parameterList();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class SmallerContext extends ParserRuleContext {
public TerminalNode SMALLER_NAME() { return getToken(UnifyResultParser.SMALLER_NAME, 0); }
public ParameterListContext parameterList() {
return getRuleContext(ParameterListContext.class,0);
}
public SmallerContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_smaller; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterSmaller(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitSmaller(this);
}
}
public final SmallerContext smaller() throws RecognitionException {
SmallerContext _localctx = new SmallerContext(_ctx, getState());
enterRule(_localctx, 12, RULE_smaller);
try {
enterOuterAlt(_localctx, 1);
{
setState(58);
match(SMALLER_NAME);
setState(59);
parameterList();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class TypeVarContext extends ParserRuleContext {
public TerminalNode TYPEVAR_NAME() { return getToken(UnifyResultParser.TYPEVAR_NAME, 0); }
public ParameterListContext parameterList() {
return getRuleContext(ParameterListContext.class,0);
}
public TypeVarContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_typeVar; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterTypeVar(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitTypeVar(this);
}
}
public final TypeVarContext typeVar() throws RecognitionException {
TypeVarContext _localctx = new TypeVarContext(_ctx, getState());
enterRule(_localctx, 14, RULE_typeVar);
try {
enterOuterAlt(_localctx, 1);
{
setState(61);
match(TYPEVAR_NAME);
setState(62);
parameterList();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class TypeContext extends ParserRuleContext {
public TerminalNode TYPE_NAME() { return getToken(UnifyResultParser.TYPE_NAME, 0); }
public ParameterListContext parameterList() {
return getRuleContext(ParameterListContext.class,0);
}
public TypeContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_type; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterType(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitType(this);
}
}
public final TypeContext type() throws RecognitionException {
TypeContext _localctx = new TypeContext(_ctx, getState());
enterRule(_localctx, 16, RULE_type);
try {
enterOuterAlt(_localctx, 1);
{
setState(64);
match(TYPE_NAME);
setState(65);
parameterList();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class OtherRuleContext extends ParserRuleContext {
public TerminalNode NAME() { return getToken(UnifyResultParser.NAME, 0); }
public ParameterListContext parameterList() {
return getRuleContext(ParameterListContext.class,0);
}
public OtherRuleContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_otherRule; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).enterOtherRule(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof UnifyResultListener ) ((UnifyResultListener)listener).exitOtherRule(this);
}
}
public final OtherRuleContext otherRule() throws RecognitionException {
OtherRuleContext _localctx = new OtherRuleContext(_ctx, getState());
enterRule(_localctx, 18, RULE_otherRule);
try {
enterOuterAlt(_localctx, 1);
{
setState(67);
match(NAME);
setState(68);
parameterList();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\17I\4\2\t\2\4\3\t"+
"\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\3"+
"\2\3\2\3\2\3\2\7\2\33\n\2\f\2\16\2\36\13\2\3\3\3\3\3\3\3\3\3\3\3\3\5\3"+
"&\n\3\3\4\3\4\3\4\3\4\7\4,\n\4\f\4\16\4/\13\4\3\4\3\4\3\5\3\5\5\5\65\n"+
"\5\3\6\3\6\3\6\3\7\3\7\3\7\3\b\3\b\3\b\3\t\3\t\3\t\3\n\3\n\3\n\3\13\3"+
"\13\3\13\3\13\2\2\f\2\4\6\b\n\f\16\20\22\24\2\2\2F\2\26\3\2\2\2\4%\3\2"+
"\2\2\6\'\3\2\2\2\b\64\3\2\2\2\n\66\3\2\2\2\f9\3\2\2\2\16<\3\2\2\2\20?"+
"\3\2\2\2\22B\3\2\2\2\24E\3\2\2\2\26\34\7\3\2\2\27\30\5\4\3\2\30\31\7\4"+
"\2\2\31\33\3\2\2\2\32\27\3\2\2\2\33\36\3\2\2\2\34\32\3\2\2\2\34\35\3\2"+
"\2\2\35\3\3\2\2\2\36\34\3\2\2\2\37&\5\n\6\2 &\5\f\7\2!&\5\16\b\2\"&\5"+
"\20\t\2#&\5\22\n\2$&\5\24\13\2%\37\3\2\2\2% \3\2\2\2%!\3\2\2\2%\"\3\2"+
"\2\2%#\3\2\2\2%$\3\2\2\2&\5\3\2\2\2\'(\7\5\2\2(-\5\b\5\2)*\7\6\2\2*,\5"+
"\b\5\2+)\3\2\2\2,/\3\2\2\2-+\3\2\2\2-.\3\2\2\2.\60\3\2\2\2/-\3\2\2\2\60"+
"\61\7\7\2\2\61\7\3\2\2\2\62\65\7\r\2\2\63\65\5\4\3\2\64\62\3\2\2\2\64"+
"\63\3\2\2\2\65\t\3\2\2\2\66\67\7\b\2\2\678\5\6\4\28\13\3\2\2\29:\7\t\2"+
"\2:;\5\6\4\2;\r\3\2\2\2<=\7\n\2\2=>\5\6\4\2>\17\3\2\2\2?@\7\13\2\2@A\5"+
"\6\4\2A\21\3\2\2\2BC\7\f\2\2CD\5\6\4\2D\23\3\2\2\2EF\7\r\2\2FG\5\6\4\2"+
"G\25\3\2\2\2\6\34%-\64";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -28,8 +28,8 @@ public class UnifyWithoutWildcards {
@Test
public void adapt() throws InterruptedException, IOException, ClassNotFoundException {
ConstraintSet<Pair> testSet = new ConstraintSet<>();
List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()),TypePlaceholder.fresh(new NullToken()));
List<RefTypeOrTPHOrWildcardOrGeneric> list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
List<RefTypeOrTPHOrWildcardOrGeneric> list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()),TypePlaceholder.fresh(new NullToken()));
RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Matrix"), list1, new NullToken());
RefType t2 = new RefType(new JavaClassName("java.util.HashMap"), list2, new NullToken());
testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));