commit
2c6738041b
|
@ -1,6 +1,8 @@
|
|||
package org.antlr.v4.gunit;
|
||||
|
||||
import org.antlr.runtime.*;
|
||||
import org.antlr.runtime.ANTLRFileStream;
|
||||
import org.antlr.runtime.CommonTokenStream;
|
||||
import org.antlr.runtime.RuleReturnScope;
|
||||
import org.antlr.runtime.tree.BufferedTreeNodeStream;
|
||||
import org.antlr.runtime.tree.CommonTree;
|
||||
import org.antlr.runtime.tree.CommonTreeNodeStream;
|
||||
|
@ -8,17 +10,19 @@ import org.antlr.stringtemplate.AutoIndentWriter;
|
|||
import org.antlr.stringtemplate.StringTemplate;
|
||||
import org.antlr.stringtemplate.StringTemplateGroup;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Gen {
|
||||
// TODO: don't hardcode
|
||||
public static final String TEMPLATE_FILE =
|
||||
"/Users/parrt/antlr/code/antlr4/main/gunit/resources/org/antlr/v4/gunit/jUnit.stg";
|
||||
"/Users/parrt/antlr/code/antlr4/gunit/resources/org/antlr/v4/gunit/jUnit.stg";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if ( args.length==0 ) System.exit(0);
|
||||
if ( args.length==0 ) {help(); System.exit(0);}
|
||||
String outputDirName = ".";
|
||||
String fileName = args[0];
|
||||
if ( args[0].equals("-o") ) {
|
||||
|
|
|
@ -49,7 +49,7 @@ public class Interval {
|
|||
/** Interval objects are used readonly so share all with the
|
||||
* same single value a==b up to some max size. Use an array as a perfect hash.
|
||||
* Return shared object for 0..INTERVAL_POOL_MAX_VALUE or a new
|
||||
* Interval object with a..a in it. On Java.g, 218623 IntervalSets
|
||||
* Interval object with a..a in it. On Java.g4, 218623 IntervalSets
|
||||
* have a..a (set with 1 element).
|
||||
*/
|
||||
public static Interval of(int a, int b) {
|
||||
|
|
|
@ -53,6 +53,7 @@ import java.lang.reflect.Method;
|
|||
* [-print]
|
||||
* [-tokens] [-gui] [-ps file.ps]
|
||||
* [-trace]
|
||||
* [-diagnostics]
|
||||
* [input-filename]
|
||||
*/
|
||||
public class TestRig {
|
||||
|
@ -65,10 +66,12 @@ public class TestRig {
|
|||
String psFile = null;
|
||||
boolean showTokens = false;
|
||||
boolean trace = false;
|
||||
boolean diagnostics = false;
|
||||
String encoding = null;
|
||||
if ( args.length < 2 ) {
|
||||
System.err.println("java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName" +
|
||||
" [-tokens] [-print] [-gui] [-ps file.ps] [-encoding encodingname] [-trace]"+
|
||||
" [-tokens] [-print] [-gui] [-ps file.ps] [-encoding encodingname]" +
|
||||
" [-trace] [-diagnostics]"+
|
||||
" [input-filename]");
|
||||
return;
|
||||
}
|
||||
|
@ -96,6 +99,9 @@ public class TestRig {
|
|||
else if ( arg.equals("-trace") ) {
|
||||
trace = true;
|
||||
}
|
||||
else if ( arg.equals("-diagnostics") ) {
|
||||
diagnostics = true;
|
||||
}
|
||||
else if ( arg.equals("-encoding") ) {
|
||||
if ( i>=args.length ) {
|
||||
System.err.println("missing encoding on -encoding");
|
||||
|
@ -155,7 +161,7 @@ public class TestRig {
|
|||
Constructor<Parser> parserCtor = parserClass.getConstructor(TokenStream.class);
|
||||
Parser parser = parserCtor.newInstance(tokens);
|
||||
|
||||
parser.addErrorListener(new DiagnosticErrorListener());
|
||||
if ( diagnostics ) parser.addErrorListener(new DiagnosticErrorListener());
|
||||
|
||||
if ( printTree || gui || psFile!=null ) {
|
||||
parser.setBuildParseTree(true);
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.antlr.v4.runtime.atn.ParserATNSimulator;
|
|||
import java.io.File;
|
||||
|
||||
/** Parse a java file or directory of java files using the generated parser
|
||||
* ANTLR builds from java.g
|
||||
* ANTLR builds from java.g4
|
||||
*/
|
||||
class TestJava {
|
||||
public static long lexerTime = 0;
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.antlr.v4.runtime.atn.ParserATNSimulator;
|
|||
import java.io.File;
|
||||
|
||||
/** Parse a java file or directory of java files using the generated parser
|
||||
* ANTLR builds from java.g
|
||||
* ANTLR builds from java.g4
|
||||
*/
|
||||
class TestYang {
|
||||
public static long lexerTime = 0;
|
||||
|
|
|
@ -70,6 +70,7 @@ import java.io.StringWriter;
|
|||
import java.io.Writer;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
@ -77,6 +78,12 @@ import java.util.List;
|
|||
public class Tool {
|
||||
public String VERSION = "4.0-"+new Date();
|
||||
|
||||
public static final String GRAMMAR_EXTENSION = ".g4";
|
||||
public static final String LEGACY_GRAMMAR_EXTENSION = ".g";
|
||||
|
||||
public static final List<String> ALL_GRAMMAR_EXTENSIONS =
|
||||
Collections.unmodifiableList(Arrays.asList(GRAMMAR_EXTENSION, LEGACY_GRAMMAR_EXTENSION));
|
||||
|
||||
public static enum OptionArgType { NONE, STRING } // NONE implies boolean
|
||||
public static class Option {
|
||||
String fieldName;
|
||||
|
@ -384,16 +391,31 @@ public class Tool {
|
|||
return null;
|
||||
}
|
||||
|
||||
/** Try current dir then dir of g then lib dir */
|
||||
public GrammarRootAST loadImportedGrammar(Grammar g, String fileName) throws IOException {
|
||||
g.tool.log("grammar", "load "+fileName + " from " + g.fileName);
|
||||
File importedFile = getImportedGrammarFile(g, fileName);
|
||||
/**
|
||||
* Try current dir then dir of g then lib dir
|
||||
* @param g
|
||||
* @param name The imported grammar name.
|
||||
*/
|
||||
public Grammar loadImportedGrammar(Grammar g, String name) throws IOException {
|
||||
g.tool.log("grammar", "load " + name + " from " + g.fileName);
|
||||
File importedFile = null;
|
||||
for (String extension : ALL_GRAMMAR_EXTENSIONS) {
|
||||
importedFile = getImportedGrammarFile(g, name + extension);
|
||||
if (importedFile != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( importedFile==null ) {
|
||||
errMgr.toolError(ErrorType.CANNOT_FIND_IMPORTED_FILE, fileName, g.fileName);
|
||||
errMgr.toolError(ErrorType.CANNOT_FIND_IMPORTED_GRAMMAR, name, g.fileName);
|
||||
return null;
|
||||
}
|
||||
|
||||
ANTLRFileStream in = new ANTLRFileStream(importedFile.getAbsolutePath());
|
||||
return load(in);
|
||||
GrammarRootAST root = load(in);
|
||||
Grammar imported = createGrammar(root);
|
||||
imported.fileName = importedFile.getAbsolutePath();
|
||||
return imported;
|
||||
}
|
||||
|
||||
public GrammarRootAST loadFromString(String grammar) {
|
||||
|
@ -449,13 +471,13 @@ public class Tool {
|
|||
* files. If the outputDir set by -o is not present it will be created.
|
||||
* The final filename is sensitive to the output directory and
|
||||
* the directory where the grammar file was found. If -o is /tmp
|
||||
* and the original grammar file was foo/t.g then output files
|
||||
* and the original grammar file was foo/t.g4 then output files
|
||||
* go in /tmp/foo.
|
||||
*
|
||||
* The output dir -o spec takes precedence if it's absolute.
|
||||
* E.g., if the grammar file dir is absolute the output dir is given
|
||||
* precendence. "-o /tmp /usr/lib/t.g" results in "/tmp/T.java" as
|
||||
* output (assuming t.g holds T.java).
|
||||
* precendence. "-o /tmp /usr/lib/t.g4" results in "/tmp/T.java" as
|
||||
* output (assuming t.g4 holds T.java).
|
||||
*
|
||||
* If no -o is specified, then just write to the directory where the
|
||||
* grammar file was found.
|
||||
|
@ -467,7 +489,7 @@ public class Tool {
|
|||
return new StringWriter();
|
||||
}
|
||||
// output directory is a function of where the grammar file lives
|
||||
// for subdir/T.g, you get subdir here. Well, depends on -o etc...
|
||||
// for subdir/T.g4, you get subdir here. Well, depends on -o etc...
|
||||
// But, if this is a .tokens file, then we force the output to
|
||||
// be the base output directory (or current directory if there is not a -o)
|
||||
//
|
||||
|
@ -533,9 +555,9 @@ public class Tool {
|
|||
fileDirectory = fileNameWithPath.substring(0, fileNameWithPath.lastIndexOf(File.separatorChar));
|
||||
}
|
||||
if ( haveOutputDir ) {
|
||||
// -o /tmp /var/lib/t.g => /tmp/T.java
|
||||
// -o subdir/output /usr/lib/t.g => subdir/output/T.java
|
||||
// -o . /usr/lib/t.g => ./T.java
|
||||
// -o /tmp /var/lib/t.g4 => /tmp/T.java
|
||||
// -o subdir/output /usr/lib/t.g4 => subdir/output/T.java
|
||||
// -o . /usr/lib/t.g4 => ./T.java
|
||||
if (fileDirectory != null &&
|
||||
(new File(fileDirectory).isAbsolute() ||
|
||||
fileDirectory.startsWith("~"))) { // isAbsolute doesn't count this :(
|
||||
|
@ -543,7 +565,7 @@ public class Tool {
|
|||
outputDir = new File(outputDirectory);
|
||||
}
|
||||
else {
|
||||
// -o /tmp subdir/t.g => /tmp/subdir/t.g
|
||||
// -o /tmp subdir/t.g4 => /tmp/subdir/t.g4
|
||||
if (fileDirectory != null) {
|
||||
outputDir = new File(outputDirectory, fileDirectory);
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ public class CodeGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
/** Generate TParser.java and TLexer.java from T.g if combined, else
|
||||
/** Generate TParser.java and TLexer.java from T.g4 if combined, else
|
||||
* just use T.java as output regardless of type.
|
||||
*/
|
||||
public String getRecognizerFileName() {
|
||||
|
|
|
@ -128,17 +128,18 @@ outerAlternative returns [boolean isLeftRec]
|
|||
{otherAlt((AltAST)$start, currentOuterAltNumber);}
|
||||
;
|
||||
|
||||
binary
|
||||
: ^( ALT recurse (op=token)+ {setTokenPrec($op.t, currentOuterAltNumber);} recurse ACTION? )
|
||||
// (ALT (= a e) (= op (SET '*' '/')) (= b e) {}) (ALT INT {}) (ALT '(' (= x e) ')' {})
|
||||
binaryMultipleOp
|
||||
: ^( ALT recurse bops recurse ACTION? )
|
||||
;
|
||||
|
||||
binaryMultipleOp
|
||||
: ^( ALT recurse
|
||||
( ^( BLOCK ( ^( ALT (op=token)+ {setTokenPrec($op.t, currentOuterAltNumber);} ) )+ )
|
||||
bops: ^(ASSIGN ID bops)
|
||||
| ^( BLOCK ( ^( ALT (op=token)+ {setTokenPrec($op.t, currentOuterAltNumber);} ) )+ )
|
||||
| ^(SET (op=token)+ {setTokenPrec($op.t, currentOuterAltNumber);})
|
||||
)
|
||||
recurse ACTION?
|
||||
)
|
||||
;
|
||||
|
||||
binary
|
||||
: ^( ALT recurse (op=token)+ {setTokenPrec($op.t, currentOuterAltNumber);} recurse ACTION? )
|
||||
;
|
||||
|
||||
ternary
|
||||
|
|
|
@ -137,7 +137,7 @@ public class TokenVocabParser {
|
|||
}
|
||||
|
||||
/** Return a File descriptor for vocab file. Look in library or
|
||||
* in -o output path. antlr -o foo T.g U.g where U needs T.tokens
|
||||
* in -o output path. antlr -o foo T.g4 U.g4 where U needs T.tokens
|
||||
* won't work unless we look in foo too. If we do not find the
|
||||
* file in the lib directory then must assume that the .tokens file
|
||||
* is going to be generated as part of this build and we have defined
|
||||
|
|
|
@ -129,7 +129,7 @@ public enum ErrorType {
|
|||
//TOKEN_VOCAB_IN_DELEGATE(, "tokenVocab option ignored in imported grammar <arg>", ErrorSeverity.ERROR),
|
||||
OPTIONS_IN_DELEGATE(109, "options ignored in imported grammar <arg>", ErrorSeverity.WARNING),
|
||||
// TOKEN_ALIAS_IN_DELEGATE(, "can't assign string to token name <arg> to string in imported grammar <arg2>", ErrorSeverity.ERROR),
|
||||
CANNOT_FIND_IMPORTED_FILE(110, "can't find or load grammar <arg> from <arg2>", ErrorSeverity.ERROR),
|
||||
CANNOT_FIND_IMPORTED_GRAMMAR(110, "can't find or load grammar <arg> from <arg2>", ErrorSeverity.ERROR),
|
||||
INVALID_IMPORT(111, "<arg.typeString> grammar <arg.name> cannot import <arg2.typeString> grammar <arg2.name>", ErrorSeverity.ERROR),
|
||||
IMPORTED_TOKENS_RULE_EMPTY(112, "", ErrorSeverity.ERROR),
|
||||
IMPORT_NAME_CLASH(113, "<arg.typeString> grammar <arg.name> and imported <arg2.typeString> grammar <arg2.name> both generate <arg2.recognizerName>", ErrorSeverity.ERROR),
|
||||
|
@ -149,7 +149,7 @@ public enum ErrorType {
|
|||
|
||||
// Dependency sorting errors
|
||||
//
|
||||
/** t1.g -> t2.g -> t3.g ->t1.g */
|
||||
/** t1.g4 -> t2.g4 -> t3.g4 ->t1.g4 */
|
||||
CIRCULAR_DEPENDENCY(130, "your grammars contain a circular dependency and cannot be sorted into a valid build order", ErrorSeverity.ERROR),
|
||||
|
||||
// Simple informational messages
|
||||
|
|
|
@ -49,11 +49,24 @@ import org.antlr.v4.runtime.misc.IntSet;
|
|||
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||
import org.antlr.v4.runtime.misc.NotNull;
|
||||
import org.antlr.v4.runtime.misc.Nullable;
|
||||
import org.antlr.v4.tool.ast.*;
|
||||
import org.antlr.v4.tool.ast.ActionAST;
|
||||
import org.antlr.v4.tool.ast.GrammarAST;
|
||||
import org.antlr.v4.tool.ast.GrammarASTErrorNode;
|
||||
import org.antlr.v4.tool.ast.GrammarASTWithOptions;
|
||||
import org.antlr.v4.tool.ast.GrammarRootAST;
|
||||
import org.antlr.v4.tool.ast.PredAST;
|
||||
import org.antlr.v4.tool.ast.TerminalAST;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Grammar implements AttributeResolver {
|
||||
public static final String GRAMMAR_FROM_STRING_NAME = "<string>";
|
||||
|
@ -232,20 +245,17 @@ public class Grammar implements AttributeResolver {
|
|||
importedGrammarName = t.getText();
|
||||
tool.log("grammar", "import " + t.getText());
|
||||
}
|
||||
GrammarAST grammarAST = null;
|
||||
Grammar g;
|
||||
try {
|
||||
grammarAST = tool.loadImportedGrammar(this, importedGrammarName + ".g");
|
||||
g = tool.loadImportedGrammar(this, importedGrammarName);
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
tool.errMgr.toolError(ErrorType.CANNOT_FIND_IMPORTED_FILE, ioe, importedGrammarName+".g");
|
||||
tool.errMgr.toolError(ErrorType.CANNOT_FIND_IMPORTED_GRAMMAR, ioe,
|
||||
importedGrammarName);
|
||||
continue;
|
||||
}
|
||||
// did it come back as error node or missing?
|
||||
if ( grammarAST==null || grammarAST instanceof GrammarASTErrorNode) return;
|
||||
GrammarRootAST ast = (GrammarRootAST)grammarAST;
|
||||
Grammar g = tool.createGrammar(ast);
|
||||
File f = tool.getImportedGrammarFile(this, importedGrammarName+".g");
|
||||
g.fileName = f.getAbsolutePath();
|
||||
if ( g == null ) continue;
|
||||
g.parent = this;
|
||||
importedGrammars.add(g);
|
||||
g.loadImportedGrammars(); // recursively pursue any imports in this import
|
||||
|
|
|
@ -649,9 +649,9 @@ public abstract class BaseTest {
|
|||
int semi = line.lastIndexOf(';');
|
||||
if ( grIndex>=0 && semi>=0 ) {
|
||||
int space = line.indexOf(' ', grIndex);
|
||||
fileName = line.substring(space+1, semi)+".g";
|
||||
fileName = line.substring(space+1, semi)+Tool.GRAMMAR_EXTENSION;
|
||||
}
|
||||
if ( fileName.length()==".g".length() ) fileName = "<string>";
|
||||
if ( fileName.length()==Tool.GRAMMAR_EXTENSION.length() ) fileName = "<string>";
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"d : ;\n";
|
||||
|
||||
String[] membersChecks = {
|
||||
"$a", "error(29): A.g:2:11: unknown attribute reference a in $a\n",
|
||||
"$a.y", "error(29): A.g:2:11: unknown attribute reference a in $a.y\n",
|
||||
"$a", "error(29): A.g4:2:11: unknown attribute reference a in $a\n",
|
||||
"$a.y", "error(29): A.g4:2:11: unknown attribute reference a in $a.y\n",
|
||||
};
|
||||
|
||||
String[] initChecks = {
|
||||
|
@ -36,8 +36,8 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"$lab.e", "",
|
||||
"$ids", "",
|
||||
|
||||
"$c", "error(29): A.g:4:8: unknown attribute reference c in $c\n",
|
||||
"$a.q", "error(31): A.g:4:10: unknown attribute q for rule a in $a.q\n",
|
||||
"$c", "error(29): A.g4:4:8: unknown attribute reference c in $c\n",
|
||||
"$a.q", "error(31): A.g4:4:10: unknown attribute q for rule a in $a.q\n",
|
||||
};
|
||||
|
||||
String[] inlineChecks = {
|
||||
|
@ -58,19 +58,19 @@ public class TestAttributeChecks extends BaseTest {
|
|||
};
|
||||
|
||||
String[] bad_inlineChecks = {
|
||||
"$lab", "error(33): A.g:6:4: missing attribute access on rule reference lab in $lab\n",
|
||||
"$q", "error(29): A.g:6:4: unknown attribute reference q in $q\n",
|
||||
"$q.y", "error(29): A.g:6:4: unknown attribute reference q in $q.y\n",
|
||||
"$q = 3", "error(29): A.g:6:4: unknown attribute reference q in $q\n",
|
||||
"$q = 3;", "error(29): A.g:6:4: unknown attribute reference q in $q = 3;\n",
|
||||
"$q.y = 3;", "error(29): A.g:6:4: unknown attribute reference q in $q.y = 3;\n",
|
||||
"$q = $blort;", "error(29): A.g:6:4: unknown attribute reference q in $q = $blort;\n" +
|
||||
"error(29): A.g:6:9: unknown attribute reference blort in $blort\n",
|
||||
"$a.ick", "error(31): A.g:6:6: unknown attribute ick for rule a in $a.ick\n",
|
||||
"$a.ick = 3;", "error(31): A.g:6:6: unknown attribute ick for rule a in $a.ick = 3;\n",
|
||||
"$b.d", "error(30): A.g:6:6: cannot access rule d's parameter: $b.d\n", // can't see rule ref's arg
|
||||
"$d.text", "error(29): A.g:6:4: unknown attribute reference d in $d.text\n", // valid rule, but no ref
|
||||
"$lab.d", "error(30): A.g:6:8: cannot access rule d's parameter: $lab.d\n",
|
||||
"$lab", "error(33): A.g4:6:4: missing attribute access on rule reference lab in $lab\n",
|
||||
"$q", "error(29): A.g4:6:4: unknown attribute reference q in $q\n",
|
||||
"$q.y", "error(29): A.g4:6:4: unknown attribute reference q in $q.y\n",
|
||||
"$q = 3", "error(29): A.g4:6:4: unknown attribute reference q in $q\n",
|
||||
"$q = 3;", "error(29): A.g4:6:4: unknown attribute reference q in $q = 3;\n",
|
||||
"$q.y = 3;", "error(29): A.g4:6:4: unknown attribute reference q in $q.y = 3;\n",
|
||||
"$q = $blort;", "error(29): A.g4:6:4: unknown attribute reference q in $q = $blort;\n" +
|
||||
"error(29): A.g4:6:9: unknown attribute reference blort in $blort\n",
|
||||
"$a.ick", "error(31): A.g4:6:6: unknown attribute ick for rule a in $a.ick\n",
|
||||
"$a.ick = 3;", "error(31): A.g4:6:6: unknown attribute ick for rule a in $a.ick = 3;\n",
|
||||
"$b.d", "error(30): A.g4:6:6: cannot access rule d's parameter: $b.d\n", // can't see rule ref's arg
|
||||
"$d.text", "error(29): A.g4:6:4: unknown attribute reference d in $d.text\n", // valid rule, but no ref
|
||||
"$lab.d", "error(30): A.g4:6:8: cannot access rule d's parameter: $lab.d\n",
|
||||
};
|
||||
|
||||
String[] finallyChecks = {
|
||||
|
@ -84,20 +84,20 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"$id.text", "",
|
||||
"$ids", "",
|
||||
|
||||
"$lab", "error(33): A.g:9:14: missing attribute access on rule reference lab in $lab\n",
|
||||
"$q", "error(29): A.g:9:14: unknown attribute reference q in $q\n",
|
||||
"$q.y", "error(29): A.g:9:14: unknown attribute reference q in $q.y\n",
|
||||
"$q = 3", "error(29): A.g:9:14: unknown attribute reference q in $q\n",
|
||||
"$q = 3;", "error(29): A.g:9:14: unknown attribute reference q in $q = 3;\n",
|
||||
"$q.y = 3;", "error(29): A.g:9:14: unknown attribute reference q in $q.y = 3;\n",
|
||||
"$q = $blort;", "error(29): A.g:9:14: unknown attribute reference q in $q = $blort;\n" +
|
||||
"error(29): A.g:9:19: unknown attribute reference blort in $blort\n",
|
||||
"$a.ick", "error(31): A.g:9:16: unknown attribute ick for rule a in $a.ick\n",
|
||||
"$a.ick = 3;", "error(31): A.g:9:16: unknown attribute ick for rule a in $a.ick = 3;\n",
|
||||
"$b.e", "error(29): A.g:9:14: unknown attribute reference b in $b.e\n", // can't see rule refs outside alts
|
||||
"$b.d", "error(29): A.g:9:14: unknown attribute reference b in $b.d\n",
|
||||
"$c.text", "error(29): A.g:9:14: unknown attribute reference c in $c.text\n",
|
||||
"$lab.d", "error(30): A.g:9:18: cannot access rule d's parameter: $lab.d\n",
|
||||
"$lab", "error(33): A.g4:9:14: missing attribute access on rule reference lab in $lab\n",
|
||||
"$q", "error(29): A.g4:9:14: unknown attribute reference q in $q\n",
|
||||
"$q.y", "error(29): A.g4:9:14: unknown attribute reference q in $q.y\n",
|
||||
"$q = 3", "error(29): A.g4:9:14: unknown attribute reference q in $q\n",
|
||||
"$q = 3;", "error(29): A.g4:9:14: unknown attribute reference q in $q = 3;\n",
|
||||
"$q.y = 3;", "error(29): A.g4:9:14: unknown attribute reference q in $q.y = 3;\n",
|
||||
"$q = $blort;", "error(29): A.g4:9:14: unknown attribute reference q in $q = $blort;\n" +
|
||||
"error(29): A.g4:9:19: unknown attribute reference blort in $blort\n",
|
||||
"$a.ick", "error(31): A.g4:9:16: unknown attribute ick for rule a in $a.ick\n",
|
||||
"$a.ick = 3;", "error(31): A.g4:9:16: unknown attribute ick for rule a in $a.ick = 3;\n",
|
||||
"$b.e", "error(29): A.g4:9:14: unknown attribute reference b in $b.e\n", // can't see rule refs outside alts
|
||||
"$b.d", "error(29): A.g4:9:14: unknown attribute reference b in $b.d\n",
|
||||
"$c.text", "error(29): A.g4:9:14: unknown attribute reference c in $c.text\n",
|
||||
"$lab.d", "error(30): A.g4:9:18: cannot access rule d's parameter: $lab.d\n",
|
||||
};
|
||||
|
||||
String[] dynMembersChecks = {
|
||||
|
@ -105,11 +105,11 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"$S::i", "",
|
||||
"$S::i=$S::i", "",
|
||||
|
||||
"$b::f", "error(54): A.g:3:1: unknown dynamic scope: b in $b::f\n",
|
||||
"$S::j", "error(55): A.g:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
|
||||
"$S::j = 3;", "error(55): A.g:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
|
||||
"$S::j = $S::k;", "error(55): A.g:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
|
||||
"error(55): A.g:3:12: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
|
||||
"$b::f", "error(54): A.g4:3:1: unknown dynamic scope: b in $b::f\n",
|
||||
"$S::j", "error(55): A.g4:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
|
||||
"$S::j = 3;", "error(55): A.g4:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
|
||||
"$S::j = $S::k;", "error(55): A.g4:3:4: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
|
||||
"error(55): A.g4:3:12: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
|
||||
};
|
||||
|
||||
String[] dynInitChecks = {
|
||||
|
@ -122,10 +122,10 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"$a::z", "",
|
||||
"$S", "",
|
||||
|
||||
"$S::j", "error(55): A.g:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
|
||||
"$S::j = 3;", "error(55): A.g:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
|
||||
"$S::j = $S::k;", "error(55): A.g:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
|
||||
"error(55): A.g:8:19: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
|
||||
"$S::j", "error(55): A.g4:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
|
||||
"$S::j = 3;", "error(55): A.g4:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
|
||||
"$S::j = $S::k;", "error(55): A.g4:8:11: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
|
||||
"error(55): A.g4:8:19: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
|
||||
};
|
||||
|
||||
String[] dynInlineChecks = {
|
||||
|
@ -138,27 +138,27 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"$S::i=$S::i", "",
|
||||
"$a::z", "",
|
||||
|
||||
"$S::j", "error(55): A.g:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
|
||||
"$S::j = 3;", "error(55): A.g:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
|
||||
"$S::j = $S::k;", "error(55): A.g:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
|
||||
"error(55): A.g:10:15: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
|
||||
"$Q[-1]::y", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[-1]::y\n",
|
||||
"$Q[-i]::y", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[-i]::y\n",
|
||||
"$Q[i]::y", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[i]::y\n",
|
||||
"$Q[0]::y", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[0]::y\n",
|
||||
"$Q[-1]::y = 23;", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[-1]::y = 23;\n",
|
||||
"$Q[-i]::y = 23;", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[-i]::y = 23;\n",
|
||||
"$Q[i]::y = 23;", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[i]::y = 23;\n",
|
||||
"$Q[0]::y = 23;", "error(54): A.g:10:4: unknown dynamic scope: Q in $Q[0]::y = 23;\n",
|
||||
"$S[-1]::y", "error(55): A.g:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y\n",
|
||||
"$S[-i]::y", "error(55): A.g:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y\n",
|
||||
"$S[i]::y", "error(55): A.g:10:10: unknown dynamically-scoped attribute for scope S: y in $S[i]::y\n",
|
||||
"$S[0]::y", "error(55): A.g:10:10: unknown dynamically-scoped attribute for scope S: y in $S[0]::y\n",
|
||||
"$S[-1]::y = 23;", "error(55): A.g:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y = 23;\n",
|
||||
"$S[-i]::y = 23;", "error(55): A.g:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y = 23;\n",
|
||||
"$S[i]::y = 23;", "error(55): A.g:10:10: unknown dynamically-scoped attribute for scope S: y in $S[i]::y = 23;\n",
|
||||
"$S[0]::y = 23;", "error(55): A.g:10:10: unknown dynamically-scoped attribute for scope S: y in $S[0]::y = 23;\n",
|
||||
"$S[$S::y]::i", "error(55): A.g:10:10: unknown dynamically-scoped attribute for scope S: y in $S::y\n"
|
||||
"$S::j", "error(55): A.g4:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
|
||||
"$S::j = 3;", "error(55): A.g4:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
|
||||
"$S::j = $S::k;", "error(55): A.g4:10:7: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
|
||||
"error(55): A.g4:10:15: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
|
||||
"$Q[-1]::y", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[-1]::y\n",
|
||||
"$Q[-i]::y", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[-i]::y\n",
|
||||
"$Q[i]::y", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[i]::y\n",
|
||||
"$Q[0]::y", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[0]::y\n",
|
||||
"$Q[-1]::y = 23;", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[-1]::y = 23;\n",
|
||||
"$Q[-i]::y = 23;", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[-i]::y = 23;\n",
|
||||
"$Q[i]::y = 23;", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[i]::y = 23;\n",
|
||||
"$Q[0]::y = 23;", "error(54): A.g4:10:4: unknown dynamic scope: Q in $Q[0]::y = 23;\n",
|
||||
"$S[-1]::y", "error(55): A.g4:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y\n",
|
||||
"$S[-i]::y", "error(55): A.g4:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y\n",
|
||||
"$S[i]::y", "error(55): A.g4:10:10: unknown dynamically-scoped attribute for scope S: y in $S[i]::y\n",
|
||||
"$S[0]::y", "error(55): A.g4:10:10: unknown dynamically-scoped attribute for scope S: y in $S[0]::y\n",
|
||||
"$S[-1]::y = 23;", "error(55): A.g4:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y = 23;\n",
|
||||
"$S[-i]::y = 23;", "error(55): A.g4:10:11: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y = 23;\n",
|
||||
"$S[i]::y = 23;", "error(55): A.g4:10:10: unknown dynamically-scoped attribute for scope S: y in $S[i]::y = 23;\n",
|
||||
"$S[0]::y = 23;", "error(55): A.g4:10:10: unknown dynamically-scoped attribute for scope S: y in $S[0]::y = 23;\n",
|
||||
"$S[$S::y]::i", "error(55): A.g4:10:10: unknown dynamically-scoped attribute for scope S: y in $S::y\n"
|
||||
};
|
||||
|
||||
String[] dynFinallyChecks = {
|
||||
|
@ -171,10 +171,10 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"$S::i=$S::i", "",
|
||||
"$a::z", "",
|
||||
|
||||
"$S::j", "error(55): A.g:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
|
||||
"$S::j = 3;", "error(55): A.g:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
|
||||
"$S::j = $S::k;", "error(55): A.g:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
|
||||
"error(55): A.g:12:25: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
|
||||
"$S::j", "error(55): A.g4:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j\n",
|
||||
"$S::j = 3;", "error(55): A.g4:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;\n",
|
||||
"$S::j = $S::k;", "error(55): A.g4:12:17: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
|
||||
"error(55): A.g4:12:25: unknown dynamically-scoped attribute for scope S: k in $S::k\n",
|
||||
};
|
||||
|
||||
@Test public void testMembersActions() throws RecognitionException {
|
||||
|
|
|
@ -50,18 +50,18 @@ public class TestBasicSemanticErrors extends BaseTest {
|
|||
"b : ( options { ick=bar; greedy=true; } : ID )+ ;\n" +
|
||||
"c : ID<blue> ID<x=y> ;",
|
||||
// YIELDS
|
||||
"warning(48): U.g:2:10: illegal option foo\n" +
|
||||
"warning(48): U.g:2:19: illegal option k\n" +
|
||||
"error(26): U.g:4:8: token names must start with an uppercase letter: f\n" +
|
||||
"error(25): U.g:4:8: can't assign string value to token name f in non-combined grammar\n" +
|
||||
"error(25): U.g:5:8: can't assign string value to token name S in non-combined grammar\n" +
|
||||
"warning(48): U.g:8:10: illegal option x\n" +
|
||||
"error(20): U.g:8:0: repeated grammar prequel spec (option, token, or import); please merge\n" +
|
||||
"error(20): U.g:7:0: repeated grammar prequel spec (option, token, or import); please merge\n" +
|
||||
"warning(48): U.g:11:10: illegal option blech\n" +
|
||||
"warning(48): U.g:11:21: illegal option greedy\n" +
|
||||
"warning(48): U.g:14:16: illegal option ick\n" +
|
||||
"warning(48): U.g:15:16: illegal option x\n",
|
||||
"warning(48): U.g4:2:10: illegal option foo\n" +
|
||||
"warning(48): U.g4:2:19: illegal option k\n" +
|
||||
"error(26): U.g4:4:8: token names must start with an uppercase letter: f\n" +
|
||||
"error(25): U.g4:4:8: can't assign string value to token name f in non-combined grammar\n" +
|
||||
"error(25): U.g4:5:8: can't assign string value to token name S in non-combined grammar\n" +
|
||||
"warning(48): U.g4:8:10: illegal option x\n" +
|
||||
"error(20): U.g4:8:0: repeated grammar prequel spec (option, token, or import); please merge\n" +
|
||||
"error(20): U.g4:7:0: repeated grammar prequel spec (option, token, or import); please merge\n" +
|
||||
"warning(48): U.g4:11:10: illegal option blech\n" +
|
||||
"warning(48): U.g4:11:21: illegal option greedy\n" +
|
||||
"warning(48): U.g4:14:16: illegal option ick\n" +
|
||||
"warning(48): U.g4:15:16: illegal option x\n",
|
||||
};
|
||||
|
||||
@Test public void testU() { super.testErrors(U, false); }
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"parser grammar S;\n" +
|
||||
"a : B . C ;\n"; // not qualified ID
|
||||
mkdir(tmpdir);
|
||||
Grammar g = new Grammar(tmpdir + "/S.g", grammar);
|
||||
Grammar g = new Grammar(tmpdir + "/S.g4", grammar);
|
||||
g.name = "S";
|
||||
|
||||
ErrorQueue equeue = new ErrorQueue();
|
||||
|
@ -61,14 +61,14 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"parser grammar S;\n" +
|
||||
"a : B {System.out.println(\"S.a\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"s : a ;\n" +
|
||||
"B : 'b' ;" + // defines B from inherited token space
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"s", "b", debug);
|
||||
assertEquals("S.a\n", found);
|
||||
}
|
||||
|
@ -78,13 +78,13 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"parser grammar S;\n" +
|
||||
"a : '=' 'a' {System.out.println(\"S.a\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"s : a ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"s", "=a", debug);
|
||||
assertEquals("S.a\n", found);
|
||||
}
|
||||
|
@ -97,14 +97,14 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"parser grammar S;\n" +
|
||||
"a[int x] returns [int y] : B {System.out.print(\"S.a\"); $y=1000;} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"s : label=a[3] {System.out.println($label.y);} ;\n" +
|
||||
"B : 'b' ;" + // defines B from inherited token space
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"s", "b", debug);
|
||||
assertEquals("S.a1000\n", found);
|
||||
}
|
||||
|
@ -117,14 +117,14 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"parser grammar S;\n" +
|
||||
"a : B {System.out.print(\"S.a\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"s : a {System.out.println($a.text);} ;\n" +
|
||||
"B : 'b' ;" + // defines B from inherited token space
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"s", "b", debug);
|
||||
assertEquals("S.ab\n", found);
|
||||
}
|
||||
|
@ -137,13 +137,13 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"}\n" +
|
||||
"a : B ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" + // uses no rules from the import
|
||||
"import S;\n" +
|
||||
"s : 'b' {foo();} ;\n" + // gS is import pointer
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"s", "b", debug);
|
||||
assertEquals("foo\n", found);
|
||||
}
|
||||
|
@ -154,18 +154,18 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"a : b {System.out.println(\"S.a\");} ;\n" +
|
||||
"b : B ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String slave2 =
|
||||
"parser grammar T;\n" +
|
||||
"a : B {System.out.println(\"T.a\");} ;\n"; // hidden by S.a
|
||||
writeFile(tmpdir, "T.g", slave2);
|
||||
writeFile(tmpdir, "T.g4", slave2);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S,T;\n" +
|
||||
"s : a ;\n" +
|
||||
"B : 'b' ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"s", "b", debug);
|
||||
assertEquals("S.a\n", found);
|
||||
}
|
||||
|
@ -176,13 +176,13 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"tokens { A; B; C; }\n" +
|
||||
"x : A {System.out.println(\"S.x\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String slave2 =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C; B; A; }\n" + // reverse order
|
||||
"y : A {System.out.println(\"T.y\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "T.g", slave2);
|
||||
writeFile(tmpdir, "T.g4", slave2);
|
||||
// The lexer will create rules to match letters a, b, c.
|
||||
// The associated token types A, B, C must have the same value
|
||||
// and all import'd parsers. Since ANTLR regenerates all imports
|
||||
|
@ -202,7 +202,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"A : 'a' ;\n" +
|
||||
"C : 'c' ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"s", "aa", debug);
|
||||
assertEquals("S.x\n" +
|
||||
"T.y\n", found);
|
||||
|
@ -215,13 +215,13 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"tokens { A; B; C; }\n" +
|
||||
"x : A {System.out.println(\"S.x\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String slave2 =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { C; B; A; }\n" + // reverse order
|
||||
"y : A {System.out.println(\"T.y\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "T.g", slave2);
|
||||
writeFile(tmpdir, "T.g4", slave2);
|
||||
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
|
@ -231,8 +231,8 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"A : 'a' ;\n" +
|
||||
"C : 'c' ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
writeFile(tmpdir, "M.g", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue);
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
|
||||
|
||||
String expectedTokenIDToTypeMap = "{EOF=-1, B=3, A=4, C=5, WS=6}";
|
||||
String expectedStringLiteralToTypeMap = "{'c'=5, 'a'=4, 'b'=3}";
|
||||
|
@ -244,7 +244,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
|
||||
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
|
||||
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"s", "aa", debug);
|
||||
assertEquals("S.x\n" +
|
||||
"T.y\n", found);
|
||||
|
@ -260,18 +260,18 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"INT : '0'..'9'+ ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"s : x INT ;\n";
|
||||
writeFile(tmpdir, "M.g", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue);
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
|
||||
|
||||
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
|
||||
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"s", "x 34 9", debug);
|
||||
assertEquals("S.x\n", found);
|
||||
}
|
||||
|
@ -284,15 +284,15 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"tokens { A='a'; }\n" +
|
||||
"x : A {System.out.println(\"S.x\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"s : x ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
writeFile(tmpdir, "M.g", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue);
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
|
||||
|
||||
Object expectedArg = "S";
|
||||
ErrorType expectedMsgID = ErrorType.OPTIONS_IN_DELEGATE;
|
||||
|
@ -310,15 +310,15 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"parser grammar S;\n" +
|
||||
"options {toke\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"s : x ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
writeFile(tmpdir, "M.g", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue);
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
|
||||
|
||||
assertEquals(ErrorType.SYNTAX_ERROR, equeue.errors.get(0).errorType);
|
||||
}
|
||||
|
@ -329,13 +329,13 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"a : b {System.out.println(\"S.a\");} ;\n" +
|
||||
"b : B ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"b : 'b'|'c' ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"a", "c", debug);
|
||||
assertEquals("S.a\n", found);
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
" ;\n" +
|
||||
"init : '=' INT ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "JavaDecl.g", slave);
|
||||
writeFile(tmpdir, "JavaDecl.g4", slave);
|
||||
String master =
|
||||
"grammar Java;\n" +
|
||||
"import JavaDecl;\n" +
|
||||
|
@ -360,7 +360,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"INT : '0'..'9'+ ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
// for float to work in decl, type must be overridden
|
||||
String found = execParser("Java.g", master, "JavaParser", "JavaLexer",
|
||||
String found = execParser("Java.g4", master, "JavaParser", "JavaLexer",
|
||||
"prog", "float x = 3;", debug);
|
||||
assertEquals("JavaDecl: floatx=3;\n", found);
|
||||
}
|
||||
|
@ -371,20 +371,20 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"a : b {System.out.println(\"S.a\");} ;\n" +
|
||||
"b : B ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
|
||||
String slave2 =
|
||||
"parser grammar T;\n" +
|
||||
"tokens { A='x'; }\n" +
|
||||
"b : B {System.out.println(\"T.b\");} ;\n";
|
||||
writeFile(tmpdir, "T.g", slave2);
|
||||
writeFile(tmpdir, "T.g4", slave2);
|
||||
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S, T;\n" +
|
||||
"b : 'b'|'c' {System.out.println(\"M.b\");}|B|A ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"a", "c", debug);
|
||||
assertEquals("M.b\n" +
|
||||
"S.a\n", found);
|
||||
|
@ -397,7 +397,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"A : 'a' {System.out.println(\"S.A\");} ;\n" +
|
||||
"C : 'c' ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"lexer grammar M;\n" +
|
||||
"import S;\n" +
|
||||
|
@ -409,7 +409,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"[@1,1:1='b',<3>,1:1]\n" +
|
||||
"[@2,2:2='c',<6>,1:2]\n" +
|
||||
"[@3,3:2='<EOF>',<-1>,1:3]\n";
|
||||
String found = execLexer("M.g", master, "M", "abc", debug);
|
||||
String found = execLexer("M.g4", master, "M", "abc", debug);
|
||||
assertEquals(expecting, found);
|
||||
}
|
||||
|
||||
|
@ -419,13 +419,13 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"A : 'a' {System.out.println(\"S.A\");} ;\n" +
|
||||
"B : 'b' {System.out.println(\"S.B\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"lexer grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"A : 'a' B {System.out.println(\"M.A\");} ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
String found = execLexer("M.g", master, "M", "ab", debug);
|
||||
String found = execLexer("M.g4", master, "M", "ab", debug);
|
||||
assertEquals("M.A\n" +
|
||||
"[@0,0:1='ab',<3>,1:0]\n" +
|
||||
"[@1,2:1='<EOF>',<-1>,1:2]\n", found);
|
||||
|
@ -440,14 +440,14 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"lexer grammar S;\n" +
|
||||
"ID : 'a'..'z'+ ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"a : A {System.out.println(\"M.a: \"+$A);} ;\n" +
|
||||
"A : 'abc' {System.out.println(\"M.A\");} ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
String found = execParser("M.g", master, "MParser", "MLexer",
|
||||
String found = execParser("M.g4", master, "MParser", "MLexer",
|
||||
"a", "abc", debug);
|
||||
|
||||
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
|
||||
|
@ -464,20 +464,20 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"parser grammar T;\n" +
|
||||
"a : T ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "T.g", slave);
|
||||
writeFile(tmpdir, "T.g4", slave);
|
||||
String slave2 =
|
||||
"parser grammar S;\n" +
|
||||
"import T;\n" +
|
||||
"a : S ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave2);
|
||||
writeFile(tmpdir, "S.g4", slave2);
|
||||
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"a : M ;\n" ;
|
||||
writeFile(tmpdir, "M.g", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue);
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
|
||||
|
||||
String expectedTokenIDToTypeMap = "{EOF=-1, M=3}"; // S and T aren't imported; overridden
|
||||
String expectedStringLiteralToTypeMap = "{}";
|
||||
|
@ -492,7 +492,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
|
||||
|
||||
boolean ok =
|
||||
rawGenerateAndBuildRecognizer("M.g", master, "MParser", null);
|
||||
rawGenerateAndBuildRecognizer("M.g4", master, "MParser", null);
|
||||
boolean expecting = true; // should be ok
|
||||
assertEquals(expecting, ok);
|
||||
}
|
||||
|
@ -503,37 +503,37 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"parser grammar T;\n" +
|
||||
"x : T ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "T.g", slave);
|
||||
writeFile(tmpdir, "T.g4", slave);
|
||||
slave =
|
||||
"parser grammar S;\n" +
|
||||
"import T;\n" +
|
||||
"y : S ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
|
||||
slave =
|
||||
"parser grammar C;\n" +
|
||||
"i : C ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "C.g", slave);
|
||||
writeFile(tmpdir, "C.g4", slave);
|
||||
slave =
|
||||
"parser grammar B;\n" +
|
||||
"j : B ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "B.g", slave);
|
||||
writeFile(tmpdir, "B.g4", slave);
|
||||
slave =
|
||||
"parser grammar A;\n" +
|
||||
"import B,C;\n" +
|
||||
"k : A ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "A.g", slave);
|
||||
writeFile(tmpdir, "A.g4", slave);
|
||||
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S,A;\n" +
|
||||
"a : M ;\n" ;
|
||||
writeFile(tmpdir, "M.g", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue);
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
|
||||
|
||||
assertEquals(equeue.errors.toString(), "[]");
|
||||
assertEquals(equeue.warnings.toString(), "[]");
|
||||
|
@ -548,7 +548,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
realElements(g.typeToTokenList).toString());
|
||||
|
||||
boolean ok =
|
||||
rawGenerateAndBuildRecognizer("M.g", master, "MParser", null);
|
||||
rawGenerateAndBuildRecognizer("M.g4", master, "MParser", null);
|
||||
boolean expecting = true; // should be ok
|
||||
assertEquals(expecting, ok);
|
||||
}
|
||||
|
@ -559,20 +559,20 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"parser grammar T;\n" +
|
||||
"x : T ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "T.g", slave);
|
||||
writeFile(tmpdir, "T.g4", slave);
|
||||
String slave2 =
|
||||
"parser grammar S;\n" + // A, B, C token type order
|
||||
"import T;\n" +
|
||||
"a : S ;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave2);
|
||||
writeFile(tmpdir, "S.g4", slave2);
|
||||
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
"a : M x ;\n" ; // x MUST BE VISIBLE TO M
|
||||
writeFile(tmpdir, "M.g", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g", master, equeue);
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
Grammar g = new Grammar(tmpdir+"/M.g4", master, equeue);
|
||||
|
||||
String expectedTokenIDToTypeMap = "{EOF=-1, M=3, T=4}";
|
||||
String expectedStringLiteralToTypeMap = "{}";
|
||||
|
@ -597,29 +597,29 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"T3: '3';\n" +
|
||||
"T4: '4';\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "L.g", gstr);
|
||||
writeFile(tmpdir, "L.g4", gstr);
|
||||
gstr =
|
||||
"parser grammar G1;\n" +
|
||||
"s: a | b;\n" +
|
||||
"a: T1;\n" +
|
||||
"b: T2;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "G1.g", gstr);
|
||||
writeFile(tmpdir, "G1.g4", gstr);
|
||||
|
||||
gstr =
|
||||
"parser grammar G2;\n" +
|
||||
"import G1;\n" +
|
||||
"a: T3;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "G2.g", gstr);
|
||||
writeFile(tmpdir, "G2.g4", gstr);
|
||||
String G3str =
|
||||
"grammar G3;\n" +
|
||||
"import G2;\n" +
|
||||
"b: T4;\n" ;
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "G3.g", G3str);
|
||||
writeFile(tmpdir, "G3.g4", G3str);
|
||||
|
||||
Grammar g = new Grammar(tmpdir+"/G3.g", G3str, equeue);
|
||||
Grammar g = new Grammar(tmpdir+"/G3.g4", G3str, equeue);
|
||||
|
||||
String expectedTokenIDToTypeMap = "{EOF=-1, T4=3, T3=4}";
|
||||
String expectedStringLiteralToTypeMap = "{}";
|
||||
|
@ -634,7 +634,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
|
||||
|
||||
boolean ok =
|
||||
rawGenerateAndBuildRecognizer("G3.g", G3str, "G3Parser", null);
|
||||
rawGenerateAndBuildRecognizer("G3.g4", G3str, "G3Parser", null);
|
||||
boolean expecting = true; // should be ok
|
||||
assertEquals(expecting, ok);
|
||||
}
|
||||
|
@ -644,7 +644,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"parser grammar S;\n" +
|
||||
"a : B {System.out.print(\"S.a\");} ;\n";
|
||||
mkdir(tmpdir);
|
||||
writeFile(tmpdir, "S.g", slave);
|
||||
writeFile(tmpdir, "S.g4", slave);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import S;\n" +
|
||||
|
@ -653,7 +653,7 @@ public class TestCompositeGrammars extends BaseTest {
|
|||
"s : a ;\n" +
|
||||
"B : 'b' ;" + // defines B from inherited token space
|
||||
"WS : (' '|'\\n') {skip();} ;\n" ;
|
||||
boolean ok = antlr("M.g", "M.g", master);
|
||||
boolean ok = antlr("M.g4", "M.g4", master);
|
||||
boolean expecting = true; // should be ok
|
||||
assertEquals(expecting, ok);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
" : ID | ID {;} ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n"+
|
||||
"WS : (' '|'\\t'|'\\n')+ {skip();} ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"abc", true);
|
||||
String expecting =
|
||||
"Decision 0:\n" +
|
||||
|
@ -70,7 +70,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
"ID : 'a'..'z'+ ;\n"+
|
||||
"INT : '0'..'9'+ ;\n"+
|
||||
"WS : (' '|'\\t'|'\\n')+ {skip();} ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"$ 34 abc", true);
|
||||
String expecting =
|
||||
"Decision 1:\n" +
|
||||
|
@ -81,7 +81,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
"line 1:2 reportContextSensitivity d=1, input='34'\n",
|
||||
this.stderrDuringParse);
|
||||
|
||||
result = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"@ 34 abc", true);
|
||||
expecting =
|
||||
"Decision 1:\n" +
|
||||
|
@ -104,7 +104,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
"ID : 'a'..'z'+ ;\n"+
|
||||
"INT : '0'..'9'+ ;\n"+
|
||||
"WS : (' '|'\\t'|'\\n')+ {skip();} ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"$ 34 abc @ 34 abc", true);
|
||||
String expecting =
|
||||
"Decision 2:\n" +
|
||||
|
@ -131,7 +131,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
"ID : 'a'..'z'+ ;\n"+
|
||||
"WS : (' '|'\\t'|'\\n')+ {skip();} ;\n";
|
||||
String input = "{ if x then return }";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
String expecting =
|
||||
"Decision 1:\n" +
|
||||
|
@ -141,7 +141,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
|
||||
input =
|
||||
"{ if x then if y then return else foo }";
|
||||
result = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
expecting =
|
||||
"Decision 1:\n" +
|
||||
|
@ -153,7 +153,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
this.stderrDuringParse);
|
||||
|
||||
input = "{ if x then return else foo }";
|
||||
result = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
expecting =
|
||||
"Decision 1:\n" +
|
||||
|
@ -170,7 +170,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
this.stderrDuringParse);
|
||||
|
||||
input = "{ if x then return else foo }";
|
||||
result = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
expecting =
|
||||
"Decision 1:\n" +
|
||||
|
@ -183,7 +183,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
input =
|
||||
"{ if x then return else foo\n" +
|
||||
"if x then if y then return else foo }";
|
||||
result = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
expecting =
|
||||
"Decision 1:\n" +
|
||||
|
@ -199,7 +199,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
input =
|
||||
"{ if x then return else foo\n" +
|
||||
"if x then if y then return else foo }";
|
||||
result = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
result = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
expecting =
|
||||
"Decision 1:\n" +
|
||||
|
@ -235,7 +235,7 @@ public class TestFullContextParsing extends BaseTest {
|
|||
"ID : [a-z]+ ;\n" +
|
||||
"";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "prog", "a(i)<-x", true);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "prog", "a(i)<-x", true);
|
||||
assertEquals("pass.\n", found);
|
||||
|
||||
String expecting =
|
||||
|
|
|
@ -15,17 +15,17 @@ public class TestLeftRecursion extends BaseTest {
|
|||
" ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"s", "x", debug);
|
||||
String expecting = "(s (a x))\n";
|
||||
assertEquals(expecting, found);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"s", "x y", debug);
|
||||
expecting = "(s (a (a x) y))\n";
|
||||
assertEquals(expecting, found);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"s", "x y z", debug);
|
||||
expecting = "(s (a (a (a x) y) z))\n";
|
||||
assertEquals(expecting, found);
|
||||
|
@ -40,7 +40,7 @@ public class TestLeftRecursion extends BaseTest {
|
|||
" ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"s", "x y z", debug);
|
||||
String expecting = "(s (a (a (a x) y) z))\n";
|
||||
assertEquals(expecting, found);
|
||||
|
@ -228,6 +228,24 @@ public class TestLeftRecursion extends BaseTest {
|
|||
runTests(grammar, tests, "s");
|
||||
}
|
||||
|
||||
@Test public void testLabelsOnOpSubrule() throws Exception {
|
||||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"s @after {System.out.println($ctx.toStringTree(this));} : e ;\n" +
|
||||
"e : a=e op=('*'|'/') b=e {}\n" +
|
||||
" | INT {}\n" +
|
||||
" | '(' x=e ')' {}\n" +
|
||||
" ;\n" +
|
||||
"INT : '0'..'9'+ ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
String[] tests = {
|
||||
"4", "(s (e 4))",
|
||||
"1*2/3", "(s (e (e (e 1) * (e 2)) / (e 3)))",
|
||||
"(1/2)*3", "(s (e (e ( (e (e 1) / (e 2)) )) * (e 3)))",
|
||||
};
|
||||
runTests(grammar, tests, "s");
|
||||
}
|
||||
|
||||
@Test public void testReturnValueAndActionsAndLabels() throws Exception {
|
||||
String grammar =
|
||||
"grammar T;\n" +
|
||||
|
@ -338,7 +356,7 @@ public class TestLeftRecursion extends BaseTest {
|
|||
}
|
||||
|
||||
public void runTests(String grammar, String[] tests, String startRule) {
|
||||
rawGenerateAndBuildRecognizer("T.g", grammar, "TParser", "TLexer");
|
||||
rawGenerateAndBuildRecognizer("T.g4", grammar, "TParser", "TLexer");
|
||||
writeRecognizerAndCompile("TParser",
|
||||
"TLexer",
|
||||
startRule,
|
||||
|
|
|
@ -37,7 +37,7 @@ public class TestLexerErrors extends BaseTest {
|
|||
String grammar =
|
||||
"lexer grammar L;\n" +
|
||||
"A : 'a' 'b' ;\n";
|
||||
String tokens = execLexer("L.g", grammar, "L", "x");
|
||||
String tokens = execLexer("L.g4", grammar, "L", "x");
|
||||
String expectingTokens =
|
||||
"[@0,1:0='<EOF>',<-1>,1:1]\n";
|
||||
assertEquals(expectingTokens, tokens);
|
||||
|
@ -50,7 +50,7 @@ public class TestLexerErrors extends BaseTest {
|
|||
String grammar =
|
||||
"lexer grammar L;\n" +
|
||||
"A : 'a' 'b' ;\n";
|
||||
String tokens = execLexer("L.g", grammar, "L", "abx");
|
||||
String tokens = execLexer("L.g4", grammar, "L", "abx");
|
||||
String expectingTokens =
|
||||
"[@0,0:1='ab',<3>,1:0]\n" +
|
||||
"[@1,3:2='<EOF>',<-1>,1:3]\n";
|
||||
|
@ -64,7 +64,7 @@ public class TestLexerErrors extends BaseTest {
|
|||
String grammar =
|
||||
"lexer grammar L;\n" +
|
||||
"A : 'a' 'b' ;\n";
|
||||
String tokens = execLexer("L.g", grammar, "L", "ax");
|
||||
String tokens = execLexer("L.g4", grammar, "L", "ax");
|
||||
String expectingTokens =
|
||||
"[@0,2:1='<EOF>',<-1>,1:2]\n";
|
||||
assertEquals(expectingTokens, tokens);
|
||||
|
@ -77,7 +77,7 @@ public class TestLexerErrors extends BaseTest {
|
|||
String grammar =
|
||||
"lexer grammar L;\n" +
|
||||
"A : 'a' 'b' ;\n";
|
||||
String tokens = execLexer("L.g", grammar, "L", "abax");
|
||||
String tokens = execLexer("L.g4", grammar, "L", "abax");
|
||||
String expectingTokens =
|
||||
"[@0,0:1='ab',<3>,1:0]\n" +
|
||||
"[@1,4:3='<EOF>',<-1>,1:4]\n";
|
||||
|
@ -95,7 +95,7 @@ public class TestLexerErrors extends BaseTest {
|
|||
// The first ab caches the DFA then abx goes through the DFA but
|
||||
// into the ATN for the x, which fails. Must go back into DFA
|
||||
// and return to previous dfa accept state
|
||||
String tokens = execLexer("L.g", grammar, "L", "ababx");
|
||||
String tokens = execLexer("L.g4", grammar, "L", "ababx");
|
||||
String expectingTokens =
|
||||
"[@0,0:1='ab',<3>,1:0]\n" +
|
||||
"[@1,2:3='ab',<3>,1:2]\n" +
|
||||
|
@ -116,7 +116,7 @@ public class TestLexerErrors extends BaseTest {
|
|||
// into the ATN for the c. It marks that hasn't except state
|
||||
// and then keeps going in the ATN. It fails on the x, but
|
||||
// uses the previous accepted in the ATN not DFA
|
||||
String tokens = execLexer("L.g", grammar, "L", "ababcx");
|
||||
String tokens = execLexer("L.g4", grammar, "L", "ababcx");
|
||||
String expectingTokens =
|
||||
"[@0,0:1='ab',<3>,1:0]\n" +
|
||||
"[@1,2:4='abc',<4>,1:2]\n" +
|
||||
|
@ -131,7 +131,7 @@ public class TestLexerErrors extends BaseTest {
|
|||
String grammar =
|
||||
"lexer grammar L;\n" +
|
||||
"A : 'abc' ;\n";
|
||||
String tokens = execLexer("L.g", grammar, "L", "abx");
|
||||
String tokens = execLexer("L.g4", grammar, "L", "abx");
|
||||
String expectingTokens =
|
||||
"[@0,3:2='<EOF>',<-1>,1:3]\n";
|
||||
assertEquals(expectingTokens, tokens);
|
||||
|
@ -155,7 +155,7 @@ public class TestLexerErrors extends BaseTest {
|
|||
"primary : ID;\n" +
|
||||
"ID : [a-z]+;\n" +
|
||||
"\n";
|
||||
String result = execLexer("T.g", grammar, "TLexer", "x : x", false);
|
||||
String result = execLexer("T.g4", grammar, "TLexer", "x : x", false);
|
||||
String expecting =
|
||||
"[@0,0:0='x',<5>,1:0]\n" +
|
||||
"[@1,2:2=':',<4>,1:2]\n" +
|
||||
|
|
|
@ -7,7 +7,7 @@ public class TestLexerExec extends BaseTest {
|
|||
String grammar =
|
||||
"lexer grammar L;\n"+
|
||||
"QUOTE : '\"' ;\n"; // make sure this compiles
|
||||
String found = execLexer("L.g", grammar, "L", "\"");
|
||||
String found = execLexer("L.g4", grammar, "L", "\"");
|
||||
String expecting =
|
||||
"[@0,0:0='\"',<3>,1:0]\n" +
|
||||
"[@1,1:0='<EOF>',<-1>,1:1]\n";
|
||||
|
@ -20,7 +20,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"A : '-' I ;\n" +
|
||||
"I : '0'..'9'+ ;\n"+
|
||||
"WS : (' '|'\\n') {skip();} ;";
|
||||
String found = execLexer("L.g", grammar, "L", "34 -21 3");
|
||||
String found = execLexer("L.g4", grammar, "L", "34 -21 3");
|
||||
String expecting =
|
||||
"[@0,0:1='34',<4>,1:0]\n" +
|
||||
"[@1,3:5='-21',<3>,1:3]\n" +
|
||||
|
@ -34,7 +34,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
|
||||
"WS : (' '|'\\n') {skip();} ;";
|
||||
String found = execLexer("L.g", grammar, "L", "34 34");
|
||||
String found = execLexer("L.g4", grammar, "L", "34 34");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"I\n" +
|
||||
|
@ -49,7 +49,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
|
||||
"WS : (' '|'\\n') -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "34 34");
|
||||
String found = execLexer("L.g4", grammar, "L", "34 34");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"I\n" +
|
||||
|
@ -64,7 +64,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
|
||||
"WS : '#' -> more ;";
|
||||
String found = execLexer("L.g", grammar, "L", "34#10");
|
||||
String found = execLexer("L.g4", grammar, "L", "34#10");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"I\n" +
|
||||
|
@ -79,7 +79,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
|
||||
"HASH : '#' -> type(HASH) ;";
|
||||
String found = execLexer("L.g", grammar, "L", "34#");
|
||||
String found = execLexer("L.g4", grammar, "L", "34#");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"[@0,0:1='34',<3>,1:0]\n" +
|
||||
|
@ -93,7 +93,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
|
||||
"HASH : '#' -> type(HASH), skip, more ;";
|
||||
String found = execLexer("L.g", grammar, "L", "34#11");
|
||||
String found = execLexer("L.g4", grammar, "L", "34#11");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"I\n" +
|
||||
|
@ -111,7 +111,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"mode STRING_MODE;\n"+
|
||||
"STRING : '\"' {popMode();} ;\n"+
|
||||
"ANY : . {more();} ;\n";
|
||||
String found = execLexer("L.g", grammar, "L", "\"abc\" \"ab\"");
|
||||
String found = execLexer("L.g4", grammar, "L", "\"abc\" \"ab\"");
|
||||
String expecting =
|
||||
"[@0,0:4='\"abc\"',<5>,1:0]\n" +
|
||||
"[@1,6:9='\"ab\"',<5>,1:6]\n" +
|
||||
|
@ -127,7 +127,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"mode STRING_MODE;\n"+
|
||||
"STRING : '\"' -> popMode ;\n"+
|
||||
"ANY : . -> more ;\n";
|
||||
String found = execLexer("L.g", grammar, "L", "\"abc\" \"ab\"");
|
||||
String found = execLexer("L.g4", grammar, "L", "\"abc\" \"ab\"");
|
||||
String expecting =
|
||||
"[@0,0:4='\"abc\"',<5>,1:0]\n" +
|
||||
"[@1,6:9='\"ab\"',<5>,1:6]\n" +
|
||||
|
@ -143,7 +143,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"mode STRING_MODE;\n"+
|
||||
"STRING : '\"' -> mode(DEFAULT_MODE) ;\n"+
|
||||
"ANY : . -> more ;\n";
|
||||
String found = execLexer("L.g", grammar, "L", "\"abc\" \"ab\"");
|
||||
String found = execLexer("L.g4", grammar, "L", "\"abc\" \"ab\"");
|
||||
String expecting =
|
||||
"[@0,0:4='\"abc\"',<5>,1:0]\n" +
|
||||
"[@1,6:9='\"ab\"',<5>,1:6]\n" +
|
||||
|
@ -157,7 +157,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"KEND : 'end' ;\n" + // has priority
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\n')+ ;";
|
||||
String found = execLexer("L.g", grammar, "L", "end eend ending a");
|
||||
String found = execLexer("L.g4", grammar, "L", "end eend ending a");
|
||||
String expecting =
|
||||
"[@0,0:2='end',<3>,1:0]\n" +
|
||||
"[@1,3:3=' ',<5>,1:3]\n" +
|
||||
|
@ -180,7 +180,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"ID : 'a'..'z'+ ;\n" +
|
||||
"fragment HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;\n" +
|
||||
"WS : (' '|'\n')+ ;";
|
||||
String found = execLexer("L.g", grammar, "L", "x 0 1 a.b a.l");
|
||||
String found = execLexer("L.g4", grammar, "L", "x 0 1 a.b a.l");
|
||||
String expecting =
|
||||
"[@0,0:0='x',<7>,1:0]\n" +
|
||||
"[@1,1:1=' ',<8>,1:1]\n" +
|
||||
|
@ -205,7 +205,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n" +
|
||||
"DONE : EOF ;\n" +
|
||||
"A : 'a';\n";
|
||||
String found = execLexer("L.g", grammar, "L", "");
|
||||
String found = execLexer("L.g4", grammar, "L", "");
|
||||
String expecting =
|
||||
"[@0,0:-1='<EOF>',<3>,1:0]\n" +
|
||||
"[@1,0:-1='<EOF>',<-1>,1:0]\n";
|
||||
|
@ -218,12 +218,12 @@ public class TestLexerExec extends BaseTest {
|
|||
"A : 'a' EOF ;\n"+
|
||||
"B : 'a';\n"+
|
||||
"C : 'c';\n";
|
||||
String found = execLexer("L.g", grammar, "L", "");
|
||||
String found = execLexer("L.g4", grammar, "L", "");
|
||||
String expecting =
|
||||
"[@0,0:-1='<EOF>',<-1>,1:0]\n";
|
||||
assertEquals(expecting, found);
|
||||
|
||||
found = execLexer("L.g", grammar, "L", "a");
|
||||
found = execLexer("L.g4", grammar, "L", "a");
|
||||
expecting =
|
||||
"[@0,0:0='a',<3>,1:0]\n" +
|
||||
"[@1,1:0='<EOF>',<-1>,1:1]\n";
|
||||
|
@ -235,7 +235,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
|
||||
"WS : [ \\n\\u000D] -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "34\r\n 34");
|
||||
String found = execLexer("L.g4", grammar, "L", "34\r\n 34");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"I\n" +
|
||||
|
@ -250,7 +250,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"I : '0'..'9'+ {System.out.println(\"I\");} ;\n"+
|
||||
"WS : [ \\n\\u000D]+ -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "34\r\n 34");
|
||||
String found = execLexer("L.g4", grammar, "L", "34\r\n 34");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"I\n" +
|
||||
|
@ -265,7 +265,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"I : ~[ab \n] ~[ \ncd]* {System.out.println(\"I\");} ;\n"+
|
||||
"WS : [ \\n\\u000D]+ -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "xaf");
|
||||
String found = execLexer("L.g4", grammar, "L", "xaf");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"[@0,0:2='xaf',<3>,1:0]\n" +
|
||||
|
@ -278,7 +278,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"I : (~[ab \n]|'a') {System.out.println(\"I\");} ;\n"+
|
||||
"WS : [ \\n\\u000D]+ -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "a x");
|
||||
String found = execLexer("L.g4", grammar, "L", "a x");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"I\n" +
|
||||
|
@ -294,7 +294,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"I : [0-9]+ {System.out.println(\"I\");} ;\n"+
|
||||
"ID : [a-zA-Z] [a-zA-Z0-9]* {System.out.println(\"ID\");} ;\n"+
|
||||
"WS : [ \\n\\u0009\r]+ -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "34\r 34 a2 abc \n ");
|
||||
String found = execLexer("L.g4", grammar, "L", "34\r 34 a2 abc \n ");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"I\n" +
|
||||
|
@ -313,7 +313,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"I : [0-]+ {System.out.println(\"I\");} ;\n"+
|
||||
"WS : [ \\n\\u000D]+ -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "00\r\n");
|
||||
String found = execLexer("L.g4", grammar, "L", "00\r\n");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"[@0,0:1='00',<3>,1:0]\n" +
|
||||
|
@ -326,7 +326,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"I : [0-9]+ {System.out.println(\"I\");} ;\n"+
|
||||
"WS : [ \\u]+ -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "34 ");
|
||||
String found = execLexer("L.g4", grammar, "L", "34 ");
|
||||
String expecting =
|
||||
"I\n" +
|
||||
"[@0,0:1='34',<3>,1:0]\n" +
|
||||
|
@ -339,7 +339,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"DASHBRACK : [\\-\\]]+ {System.out.println(\"DASHBRACK\");} ;\n"+
|
||||
"WS : [ \\u]+ -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "- ] ");
|
||||
String found = execLexer("L.g4", grammar, "L", "- ] ");
|
||||
String expecting =
|
||||
"DASHBRACK\n" +
|
||||
"DASHBRACK\n" +
|
||||
|
@ -354,7 +354,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"A : [z-a9]+ {System.out.println(\"A\");} ;\n"+
|
||||
"WS : [ \\u]+ -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "9");
|
||||
String found = execLexer("L.g4", grammar, "L", "9");
|
||||
String expecting =
|
||||
"A\n" +
|
||||
"[@0,0:0='9',<3>,1:0]\n" +
|
||||
|
@ -367,7 +367,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"A : [\"a-z]+ {System.out.println(\"A\");} ;\n"+
|
||||
"WS : [ \n\t]+ -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "b\"a");
|
||||
String found = execLexer("L.g4", grammar, "L", "b\"a");
|
||||
String expecting =
|
||||
"A\n" +
|
||||
"[@0,0:2='b\"a',<3>,1:0]\n" +
|
||||
|
@ -380,7 +380,7 @@ public class TestLexerExec extends BaseTest {
|
|||
"lexer grammar L;\n"+
|
||||
"A : [\"\\\\ab]+ {System.out.println(\"A\");} ;\n"+
|
||||
"WS : [ \n\t]+ -> skip ;";
|
||||
String found = execLexer("L.g", grammar, "L", "b\"\\a");
|
||||
String found = execLexer("L.g4", grammar, "L", "b\"\\a");
|
||||
String expecting =
|
||||
"A\n" +
|
||||
"[@0,0:3='b\"\\a',<3>,1:0]\n" +
|
||||
|
|
|
@ -28,7 +28,7 @@ public class TestListeners extends BaseTest {
|
|||
"INT : [0-9]+ ;\n" +
|
||||
"ID : [a-z]+ ;\n" +
|
||||
"WS : [ \\t\\n]+ -> skip ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "1 2", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "1 2", false);
|
||||
String expecting = "(a 1 2)\n" +
|
||||
"1\n" +
|
||||
"2\n";
|
||||
|
@ -61,13 +61,13 @@ public class TestListeners extends BaseTest {
|
|||
"INT : [0-9]+ ;\n" +
|
||||
"ID : [a-z]+ ;\n" +
|
||||
"WS : [ \\t\\n]+ -> skip ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "1 2", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "1 2", false);
|
||||
String expecting =
|
||||
"(a 1 2)\n" +
|
||||
"1 2 [1, 2]\n";
|
||||
assertEquals(expecting, result);
|
||||
|
||||
result = execParser("T.g", grammar, "TParser", "TLexer", "s", "abc", false);
|
||||
result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "abc", false);
|
||||
expecting = "(a abc)\n" +
|
||||
"[@0,0:2='abc',<6>,1:0]\n";
|
||||
assertEquals(expecting, result);
|
||||
|
@ -103,12 +103,12 @@ public class TestListeners extends BaseTest {
|
|||
"INT : [0-9]+ ;\n" +
|
||||
"ID : [a-z]+ ;\n" +
|
||||
"WS : [ \\t\\n]+ -> skip ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "1 2", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "1 2", false);
|
||||
String expecting = "(a (b 1) (b 2))\n" +
|
||||
"1 2 1\n";
|
||||
assertEquals(expecting, result);
|
||||
|
||||
result = execParser("T.g", grammar, "TParser", "TLexer", "s", "abc", false);
|
||||
result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "abc", false);
|
||||
expecting = "(a (b abc))\n" +
|
||||
"abc\n";
|
||||
assertEquals(expecting, result);
|
||||
|
@ -145,7 +145,7 @@ public class TestListeners extends BaseTest {
|
|||
"ADD : '+' ;\n" +
|
||||
"INT : [0-9]+ ;\n" +
|
||||
"WS : [ \\t\\n]+ -> skip ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "1+2*3", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "1+2*3", false);
|
||||
String expecting =
|
||||
"(e (e 1) + (e (e 2) * (e 3)))\n" +
|
||||
"1\n" +
|
||||
|
@ -186,7 +186,7 @@ public class TestListeners extends BaseTest {
|
|||
"ADD : '+' ;\n" +
|
||||
"INT : [0-9]+ ;\n" +
|
||||
"WS : [ \\t\\n]+ -> skip ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "1(2,3)", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "1(2,3)", false);
|
||||
String expecting =
|
||||
"(e (e 1) ( (eList (e 2) , (e 3)) ))\n" +
|
||||
"1\n" +
|
||||
|
|
|
@ -40,14 +40,14 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"INT : '0'..'9'+ ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n')+ {skip();} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x", true);
|
||||
assertEquals("x\n" +
|
||||
"Decision 0:\n" +
|
||||
"s0-ID->:s1=>2\n", found);
|
||||
assertEquals(null, this.stderrDuringParse);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"34 x", true);
|
||||
assertEquals("34x\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -63,7 +63,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"INT : '0'..'9'+ ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n')+ {skip();} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x", true);
|
||||
assertEquals("x\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -80,7 +80,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"INT : '0'..'9'+ ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n')+ {skip();} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x", true);
|
||||
assertEquals("alt 1\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -91,7 +91,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"s0-ID->:s1=>2\n", found);
|
||||
assertEquals(null, this.stderrDuringParse);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"34", true);
|
||||
assertEquals("alt 2\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -102,7 +102,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"s0-INT->:s1=>2\n", found);
|
||||
assertEquals(null, this.stderrDuringParse);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"34 x", true);
|
||||
assertEquals("alt 1\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -125,7 +125,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"INT : '0'..'9'+ ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n')+ {skip();} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"2 3 x", true);
|
||||
assertEquals("alt 1\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -139,7 +139,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"s0-ID->:s2=>2\n", found);
|
||||
assertEquals(null, this.stderrDuringParse);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"2 3", true);
|
||||
assertEquals("alt 2\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -151,7 +151,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"s0-INT->:s1=>2\n", found);
|
||||
assertEquals("line 1:0 no viable alternative at input '2'\n", this.stderrDuringParse);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"a b c 3", true);
|
||||
assertEquals("alt 2\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -176,14 +176,14 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"INT : '0'..'9'+ ;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n')+ {skip();} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x", true);
|
||||
assertEquals("alt 1\n" +
|
||||
"Decision 0:\n" +
|
||||
"s0-ID->:s1=>1\n", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"34", true);
|
||||
assertEquals("alt 1\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -204,14 +204,14 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"WS : (' '|'\\n')+ {skip();} ;\n";
|
||||
String input =
|
||||
"{ }";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("{}\n" +
|
||||
"Decision 0:\n" +
|
||||
"s0-'}'->:s1=>2\n", found);
|
||||
input =
|
||||
"{a b { }";
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("{ab{}\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -220,7 +220,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"s0-ID->:s1=>1\n", found);
|
||||
input =
|
||||
"{ } a 2 { }"; // FAILS to match since it terminates loop at first { }
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("", found); // should not print output; resync kills rest of input til '}' then returns normally
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"WS : (' '|'\\n')+ {skip();} ;\n";
|
||||
String input =
|
||||
"if ( x=34 ) { } ;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("if(x=34){};\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -249,7 +249,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"s3-'}'->:s4=>2\n", found);
|
||||
input =
|
||||
"if ( ))) ) { } ;";
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("if()))){};\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -259,7 +259,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"s3-'}'->:s4=>2\n", found);
|
||||
input =
|
||||
"if (() { } a 2) { } ;"; // The first { } should match block so should stop
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("", found); // should not finish to print output
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"WS : (' '|'\\n')+ {skip();} ;\n";
|
||||
String input =
|
||||
"if ( x=34 ) { {return a} b 34 } ;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("if(x=34){{returna}b34};\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -302,7 +302,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
|
||||
input =
|
||||
"if ( ()) ) { {return a} b 34 } ;";
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("if(())){{returna}b34};\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -344,7 +344,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
String input =
|
||||
"x=1; a=b;";
|
||||
String found = null;
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("x=1;a=b;\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -356,7 +356,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"s5-EOF->:s6=>2\n", found);
|
||||
input =
|
||||
"if ( 1 ) { x=3; { return 4; } } return 99; abc=def;";
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("if(1){x=3;{return4;}}return99;abc=def;\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -369,7 +369,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"s6-EOF->:s7=>2\n", found);
|
||||
input =
|
||||
"x=1; a=3;"; // FAILS to match since it can't match last element
|
||||
execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
// can't match EOF to ID '=' '3' ';'
|
||||
assertEquals("line 1:9 no viable alternative at input '<EOF>'\n",
|
||||
|
@ -377,7 +377,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
|
||||
input =
|
||||
"x=1; a=b; z=3;"; // FAILS to match since it can't match last element
|
||||
execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("line 1:14 no viable alternative at input '<EOF>'\n",
|
||||
this.stderrDuringParse);
|
||||
|
@ -406,7 +406,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
String input =
|
||||
"x=1; a=b; x=y;";
|
||||
String found = null;
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("x=1;a=b;\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -417,7 +417,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"s4-';'->:s5=>2\n", found); // ignores x=1 that follows first a=b assignment
|
||||
input =
|
||||
"if ( 1 ) { x=3; { return 4; } } return 99; abc=def;";
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("if(1){x=3;{return4;}}return99;abc=def;\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -429,14 +429,14 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"s5-';'->:s6=>2\n", found);
|
||||
input =
|
||||
"x=1; a=3;"; // FAILS to match since it can't match either stat
|
||||
execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
// can't match EOF to ID '=' '0' ';'
|
||||
assertEquals("line 1:9 no viable alternative at input '<EOF>'\n",
|
||||
this.stderrDuringParse);
|
||||
input =
|
||||
"x=1; a=b; z=3;"; // stops at a=b; ignores z=3;
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
input, true);
|
||||
assertEquals("x=1;a=b;\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -461,7 +461,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = null;
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"<a>foo</a>", true);
|
||||
assertEquals("<a>foo</a>\n" +
|
||||
"Decision 1:\n" +
|
||||
|
@ -489,7 +489,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"line 1:7 reportAmbiguity d=2: ambigAlts={1..2}, input='/'\n",
|
||||
this.stderrDuringParse);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"<a></a>", true);
|
||||
assertEquals("<a></a>\n" +
|
||||
"Decision 1:\n" +
|
||||
|
@ -508,7 +508,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
"Decision 3:\n" +
|
||||
"s0-'>'->:s2=>2\n" +
|
||||
"s0-ID->:s1=>1\n", found);
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"</b><a src=\"abc\", width=32>", true);
|
||||
assertEquals("</b><asrc=\"abc\",width=32>\n" +
|
||||
"Decision 1:\n" +
|
||||
|
@ -556,7 +556,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
|
||||
String found = null;
|
||||
System.out.println(grammar);
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
",=foo <a x= 3>32skidoo<a><img>", true);
|
||||
assertEquals("<ax=3>\n" +
|
||||
"<a>\n" +
|
||||
|
@ -582,7 +582,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
assertEquals(null,
|
||||
this.stderrDuringParse);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x x<a>", true);
|
||||
assertEquals("<a>\n" +
|
||||
"Decision 0:\n" +
|
||||
|
@ -599,7 +599,7 @@ public class TestNonGreedyLoops extends BaseTest {
|
|||
// gets line 1:3 no viable alternative at input '>'. Why??
|
||||
// oH! it sees .+ and figures it matches > so <> predicts tag CORRECT!
|
||||
// Seeing '.' in a lookahead prediction can be misleading!!
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x <><a>", true);
|
||||
assertEquals("<\n" +
|
||||
"<a>\n" +
|
||||
|
|
|
@ -37,7 +37,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' 'b' ;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aa", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aa", false);
|
||||
String expecting = "line 1:1 mismatched input 'a' expecting 'b'\n";
|
||||
String result = stderrDuringParse;
|
||||
assertEquals(expecting, result);
|
||||
|
@ -47,7 +47,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' 'b' ;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aab", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aab", false);
|
||||
String expecting = "line 1:1 extraneous input 'a' expecting 'b'\n";
|
||||
String result = stderrDuringParse;
|
||||
assertEquals(expecting, result);
|
||||
|
@ -57,7 +57,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' ('b'|'c') ;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aab", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aab", false);
|
||||
String expecting = "line 1:1 extraneous input 'a' expecting {'b', 'c'}\n";
|
||||
String result = stderrDuringParse;
|
||||
assertEquals(expecting, result);
|
||||
|
@ -67,7 +67,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' 'b' 'c' ;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "ac", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ac", false);
|
||||
String expecting = "line 1:1 missing 'b' at 'c'\n";
|
||||
String result = stderrDuringParse;
|
||||
assertEquals(expecting, result);
|
||||
|
@ -77,7 +77,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' x='b' {System.out.println(\"conjured=\"+$x);} 'c' ;";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "a", "ac", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ac", false);
|
||||
String expecting = "conjured=[@-1,-1:-1='<missing 'b'>',<3>,1:1]\n";
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' ('b'|'c') 'd' ;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "ad", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ad", false);
|
||||
String expecting = "line 1:1 missing {'b', 'c'} at 'd'\n";
|
||||
String result = stderrDuringParse;
|
||||
assertEquals(expecting, result);
|
||||
|
@ -96,7 +96,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' x=('b'|'c') {System.out.println(\"conjured=\"+$x);} 'd' ;";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "a", "ad", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ad", false);
|
||||
String expecting = "conjured=[@-1,-1:-1='<missing 'b'>',<3>,1:1]\n";
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class TestParseErrors extends BaseTest {
|
|||
" | 'a' 'c'" +
|
||||
";\n" +
|
||||
"q : 'e' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "ae", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ae", false);
|
||||
String expecting = "line 1:1 no viable alternative at input 'ae'\n";
|
||||
String result = stderrDuringParse;
|
||||
assertEquals(expecting, result);
|
||||
|
@ -122,7 +122,7 @@ public class TestParseErrors extends BaseTest {
|
|||
" ;\n" +
|
||||
"q : 'e' ;\n";
|
||||
System.out.println(grammar);
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "abe", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abe", false);
|
||||
String expecting = "line 1:2 no viable alternative at input 'abe'\n";
|
||||
String result = stderrDuringParse;
|
||||
assertEquals(expecting, result);
|
||||
|
@ -135,7 +135,7 @@ public class TestParseErrors extends BaseTest {
|
|||
" | 'a'+ 'c'" +
|
||||
";\n" +
|
||||
"q : 'e' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aaae", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aaae", false);
|
||||
String expecting = "line 1:3 no viable alternative at input 'aaae'\n";
|
||||
String result = stderrDuringParse;
|
||||
assertEquals(expecting, result);
|
||||
|
@ -145,7 +145,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' 'b'*;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aabc", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aabc", false);
|
||||
String expecting = "line 1:1 extraneous input 'a' expecting {<EOF>, 'b'}\n" +
|
||||
"line 1:3 token recognition error at: 'c'\n";
|
||||
String result = stderrDuringParse;
|
||||
|
@ -157,7 +157,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' 'b'* 'c';";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aacabc", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aacabc", false);
|
||||
String expecting =
|
||||
"line 1:1 extraneous input 'a' expecting {'b', 'c'}\n";
|
||||
String result = stderrDuringParse;
|
||||
|
@ -168,7 +168,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' 'b'* 'c' ;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "ababbc", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ababbc", false);
|
||||
String expecting = "line 1:2 extraneous input 'a' expecting {'b', 'c'}\n";
|
||||
String result = stderrDuringParse;
|
||||
assertEquals(expecting, result);
|
||||
|
@ -178,7 +178,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' 'b'* 'c' ;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "abaaababc", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abaaababc", false);
|
||||
String expecting =
|
||||
"line 1:2 extraneous input 'a' expecting {'b', 'c'}\n" +
|
||||
"line 1:6 extraneous input 'a' expecting {'b', 'c'}\n";
|
||||
|
@ -192,7 +192,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' ('b'|'z'{;})*;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aabc", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aabc", false);
|
||||
String expecting = "line 1:1 extraneous input 'a' expecting {<EOF>, 'b', 'z'}\n" +
|
||||
"line 1:3 token recognition error at: 'c'\n";
|
||||
String result = stderrDuringParse;
|
||||
|
@ -204,7 +204,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' ('b'|'z'{;})* 'c';";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "aacabc", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "aacabc", false);
|
||||
String expecting =
|
||||
"line 1:1 extraneous input 'a' expecting {'b', 'z', 'c'}\n";
|
||||
String result = stderrDuringParse;
|
||||
|
@ -215,7 +215,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' ('b'|'z'{;})* 'c' ;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "ababbc", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "ababbc", false);
|
||||
String expecting = "line 1:2 extraneous input 'a' expecting {'b', 'z', 'c'}\n";
|
||||
String result = stderrDuringParse;
|
||||
assertEquals(expecting, result);
|
||||
|
@ -225,7 +225,7 @@ public class TestParseErrors extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : 'a' ('b'|'z'{;})* 'c' ;";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a", "abaaababc", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a", "abaaababc", false);
|
||||
String expecting =
|
||||
"line 1:2 extraneous input 'a' expecting {'b', 'z', 'c'}\n" +
|
||||
"line 1:6 extraneous input 'a' expecting {'b', 'z', 'c'}\n";
|
||||
|
@ -249,7 +249,7 @@ public class TestParseErrors extends BaseTest {
|
|||
"@init\n" +
|
||||
"{ System.out.println(getExpectedTokens().toString(tokenNames)); }\n" +
|
||||
" : ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "start", "dog and software", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "start", "dog and software", false);
|
||||
String expecting = "{'hardware', 'software'}\n";
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ public class TestParseErrors extends BaseTest {
|
|||
"primary : ID;\n" +
|
||||
"ID : [a-z]+;\n" +
|
||||
"\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "start", "x:x", true);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "start", "x:x", true);
|
||||
String expecting = "";
|
||||
assertEquals(expecting, result);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
|
|
@ -11,7 +11,7 @@ public class TestParseTrees extends BaseTest {
|
|||
"@after {System.out.println($r.ctx.toStringTree(this));}\n" +
|
||||
" :r=a ;\n" +
|
||||
"a : 'x' {System.out.println(getRuleInvocationStack());} ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "x", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "x", false);
|
||||
String expecting = "[a, s]\n(a x)\n";
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class TestParseTrees extends BaseTest {
|
|||
" :r=a ;\n" +
|
||||
"a : 'x' 'y'\n" +
|
||||
" ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "xy", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "xy", false);
|
||||
String expecting = "(a x y)\n";
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class TestParseTrees extends BaseTest {
|
|||
" :r=a ;\n" +
|
||||
"a : 'x' | 'y'\n" +
|
||||
" ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "y", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "y", false);
|
||||
String expecting = "(a y)\n";
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class TestParseTrees extends BaseTest {
|
|||
" :r=a ;\n" +
|
||||
"a : ('x' | 'y')* 'z'\n" +
|
||||
" ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "xyyxyxz", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "xyyxyxz", false);
|
||||
String expecting = "(a x y y x y x z)\n";
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class TestParseTrees extends BaseTest {
|
|||
"a : b 'x'\n" +
|
||||
" ;\n" +
|
||||
"b : 'y' ;\n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "yx", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "yx", false);
|
||||
String expecting = "(a (b y) x)\n";
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ public class TestParseTrees extends BaseTest {
|
|||
"a : 'x' 'y'\n" +
|
||||
" ;\n" +
|
||||
"Z : 'z'; \n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "xzy", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "xzy", false);
|
||||
String expecting = "(a x z y)\n"; // ERRORs not shown. z is colored red in tree view
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ public class TestParseTrees extends BaseTest {
|
|||
"a : 'x' | 'y'\n" +
|
||||
" ;\n" +
|
||||
"Z : 'z'; \n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "z", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "z", false);
|
||||
String expecting = "(a z)\n";
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public class TestParseTrees extends BaseTest {
|
|||
"a : 'x' 'y'* '!'\n" +
|
||||
" ;\n" +
|
||||
"Z : 'z'; \n";
|
||||
String result = execParser("T.g", grammar, "TParser", "TLexer", "s", "xzyy!", false);
|
||||
String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", "xzyy!", false);
|
||||
String expecting = "(a x z y y !)\n";
|
||||
assertEquals(expecting, result);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TestParserExec extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"abc 34", false);
|
||||
assertEquals("", found);
|
||||
assertEquals(null, stderrDuringParse);
|
||||
|
@ -57,7 +57,7 @@ public class TestParserExec extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"abc 34", false);
|
||||
assertEquals("abc34\n", found);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public class TestParserExec extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"34", false);
|
||||
assertEquals("alt 2\n", found);
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class TestParserExec extends BaseTest {
|
|||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"a b c", false);
|
||||
assertEquals("abc\n", found);
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ public class TestParserExec extends BaseTest {
|
|||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"a b c", false);
|
||||
assertEquals("abc\n", found);
|
||||
}
|
||||
|
@ -109,10 +109,10 @@ public class TestParserExec extends BaseTest {
|
|||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"", false);
|
||||
assertEquals("\n", found);
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"a b c", false);
|
||||
assertEquals("abc\n", found);
|
||||
}
|
||||
|
@ -125,10 +125,10 @@ public class TestParserExec extends BaseTest {
|
|||
"ID : 'a'..'z'+ ;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"", false);
|
||||
assertEquals("\n", found);
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"a b c", false);
|
||||
assertEquals("abc\n", found);
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ public class TestParserExec extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"a 34 c", false);
|
||||
assertEquals("a34c\n", found);
|
||||
}
|
||||
|
@ -154,10 +154,10 @@ public class TestParserExec extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"", false);
|
||||
assertEquals("\n", found);
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "a",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"a 34 c", false);
|
||||
assertEquals("a34c\n", found);
|
||||
}
|
||||
|
@ -175,19 +175,19 @@ public class TestParserExec extends BaseTest {
|
|||
"a : 'a' s ('b' s)?;\n"
|
||||
;
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s", "x", false);
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "x", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s", "axbx", false);
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "axbx", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s", "ax", false);
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "ax", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer", "s", "aaxbx", false);
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer", "s", "aaxbx", false);
|
||||
assertEquals("", found);
|
||||
assertNull(this.stderrDuringParse);
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ public class TestParserExec extends BaseTest {
|
|||
"WS : (' ' | '\\t')+ -> skip;\n"
|
||||
;
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "stmt",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "stmt",
|
||||
"if x if x a else b", true);
|
||||
String expecting = "";
|
||||
assertEquals(expecting, found);
|
||||
|
|
|
@ -78,8 +78,8 @@ public class TestPerformance extends BaseTest {
|
|||
private static final boolean RECURSIVE = true;
|
||||
|
||||
/**
|
||||
* True to use the Java grammar with expressions in the v4 left-recursive syntax (Java-LR.g). False to use
|
||||
* the standard grammar (Java.g). In either case, the grammar is renamed in the temporary directory to Java.g
|
||||
* True to use the Java grammar with expressions in the v4 left-recursive syntax (Java-LR.g4). False to use
|
||||
* the standard grammar (Java.g4). In either case, the grammar is renamed in the temporary directory to Java.g4
|
||||
* before compiling.
|
||||
*/
|
||||
private static final boolean USE_LR_GRAMMAR = true;
|
||||
|
@ -421,8 +421,8 @@ public class TestPerformance extends BaseTest {
|
|||
}
|
||||
|
||||
protected void compileJavaParser(boolean leftRecursive) throws IOException {
|
||||
String grammarFileName = "Java.g";
|
||||
String sourceName = leftRecursive ? "Java-LR.g" : "Java.g";
|
||||
String grammarFileName = "Java.g4";
|
||||
String sourceName = leftRecursive ? "Java-LR.g4" : "Java.g4";
|
||||
String body = load(sourceName, null);
|
||||
@SuppressWarnings({"ConstantConditions"})
|
||||
List<String> extraOptions = new ArrayList<String>();
|
||||
|
|
|
@ -11,7 +11,7 @@ public class TestSemPredEvalLexer extends BaseTest {
|
|||
"E2 : {true}? 'enum' ;\n" + // winner not E1 or ID
|
||||
"ID : 'a'..'z'+ ;\n"+
|
||||
"WS : (' '|'\\n') {skip();} ;";
|
||||
String found = execLexer("L.g", grammar, "L", "enum abc", true);
|
||||
String found = execLexer("L.g4", grammar, "L", "enum abc", true);
|
||||
String expecting =
|
||||
"[@0,0:3='enum',<4>,1:0]\n" +
|
||||
"[@1,5:7='abc',<5>,1:5]\n" +
|
||||
|
@ -26,7 +26,7 @@ public class TestSemPredEvalLexer extends BaseTest {
|
|||
"E2 : 'enum' {true}? ;\n" + // winner not E1 or ID
|
||||
"ID : 'a'..'z'+ ;\n"+
|
||||
"WS : (' '|'\\n') {skip();} ;";
|
||||
String found = execLexer("L.g", grammar, "L", "enum abc enum", true);
|
||||
String found = execLexer("L.g4", grammar, "L", "enum abc enum", true);
|
||||
String expecting =
|
||||
"[@0,0:3='enum',<4>,1:0]\n" +
|
||||
"[@1,5:7='abc',<5>,1:5]\n" +
|
||||
|
@ -50,7 +50,7 @@ public class TestSemPredEvalLexer extends BaseTest {
|
|||
"B : {int n=0;} ({n<=2}? DIGIT {n++})+ ;\n" +
|
||||
"fragment DIGIT : '0'..'9' ;\n"+
|
||||
"WS : (' '|'\\n') {skip();} ;";
|
||||
String found = execLexer("L.g", grammar, "L", "1234 56", true);
|
||||
String found = execLexer("L.g4", grammar, "L", "1234 56", true);
|
||||
String expecting =
|
||||
"[@0,0:3='enum',<4>,1:0]\n" +
|
||||
"[@1,5:7='abc',<5>,1:5]\n" +
|
||||
|
|
|
@ -45,7 +45,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"3 4 x", false);
|
||||
String expecting =
|
||||
"alt 2\n" +
|
||||
|
@ -70,7 +70,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x ; y", false);
|
||||
String expecting = "";
|
||||
assertEquals(expecting, found);
|
||||
|
@ -95,7 +95,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x y 3", false);
|
||||
String expecting =
|
||||
"alt 2\n" +
|
||||
|
@ -120,7 +120,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x y", false);
|
||||
String expecting =
|
||||
"alt 1\n" +
|
||||
|
@ -147,7 +147,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x; y", true);
|
||||
String expecting =
|
||||
"alt 1\n" +
|
||||
|
@ -180,7 +180,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"34; x; y", true);
|
||||
String expecting =
|
||||
"alt 1\n" +
|
||||
|
@ -208,7 +208,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"y 3 x 4", false);
|
||||
String expecting =
|
||||
"alt 2\n" +
|
||||
|
@ -229,7 +229,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"y 3 x 4", false);
|
||||
String expecting = "line 1:0 no viable alternative at input 'y'\n";
|
||||
String result = stderrDuringParse;
|
||||
|
@ -247,7 +247,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x x y", false);
|
||||
String expecting =
|
||||
"alt 2\n" +
|
||||
|
@ -272,7 +272,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x 4", false);
|
||||
String expecting =
|
||||
"alt 1\n";
|
||||
|
@ -295,7 +295,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x x y", false);
|
||||
String expecting =
|
||||
"alt 1\n" +
|
||||
|
@ -321,7 +321,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"x x y", false);
|
||||
String expecting =
|
||||
"i=1\n" +
|
||||
|
@ -352,7 +352,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"a b", false);
|
||||
String expecting =
|
||||
"alt 2\n" +
|
||||
|
@ -382,7 +382,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"a b", false);
|
||||
String expecting =
|
||||
"";
|
||||
|
@ -403,7 +403,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"a;", false);
|
||||
String expecting =
|
||||
"alt 2\n";
|
||||
|
@ -423,7 +423,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"a;", false);
|
||||
String expecting =
|
||||
"alt 2\n";
|
||||
|
@ -447,7 +447,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"a!", false);
|
||||
String expecting =
|
||||
"eval=true\n" + // now we are parsing
|
||||
|
@ -473,7 +473,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"a!", false);
|
||||
String expecting =
|
||||
"eval=true\n" +
|
||||
|
@ -500,7 +500,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
"INT : '0'..'9'+;\n" +
|
||||
"WS : (' '|'\\n') {skip();} ;\n";
|
||||
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer", "s",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "s",
|
||||
"a!", false);
|
||||
String expecting =
|
||||
"eval=true\n" +
|
||||
|
|
|
@ -46,7 +46,7 @@ public class TestSets extends BaseTest {
|
|||
"fragment A : '1' | '2';\n" +
|
||||
"fragment B : '3' '4';\n" +
|
||||
"C : A | B;\n";
|
||||
String found = execParser("P.g", grammar, "PParser", "PLexer",
|
||||
String found = execParser("P.g4", grammar, "PParser", "PLexer",
|
||||
"a", "34", debug);
|
||||
assertEquals("34\n", found);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : t=('x'|'y') {System.out.println($t.text);} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "x", debug);
|
||||
assertEquals("x\n", found);
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : t=~('x'|'y') 'z' {System.out.println($t.text);} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "zz", debug);
|
||||
assertEquals("z\n", found);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : ~'x' 'z' {System.out.println(_input);} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "zz", debug);
|
||||
assertEquals("zz\n", found);
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : t=~'x' 'z' {System.out.println($t.text);} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "zz", debug);
|
||||
assertEquals("z\n", found);
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a @after {System.out.println(_input);} : 'a' | 'b' |'c' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "b", debug);
|
||||
assertEquals("b\n", found);
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ public class TestSets extends BaseTest {
|
|||
"grammar T;\n" +
|
||||
"a : A {System.out.println($A.text);} ;\n" +
|
||||
"A : ~'b' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "x", debug);
|
||||
assertEquals("x\n", found);
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ public class TestSets extends BaseTest {
|
|||
"grammar T;\n" +
|
||||
"a : A? 'c' {System.out.println(_input);} ;\n" +
|
||||
"A : 'b' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "bc", debug);
|
||||
assertEquals("bc\n", found);
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class TestSets extends BaseTest {
|
|||
"grammar T;\n" +
|
||||
"a : A {System.out.println(_input);} ;\n" +
|
||||
"A : 'b'? 'c' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "bc", debug);
|
||||
assertEquals("bc\n", found);
|
||||
}
|
||||
|
@ -131,10 +131,10 @@ public class TestSets extends BaseTest {
|
|||
"grammar T;\n" +
|
||||
"a : A {System.out.println(_input);} ;\n" +
|
||||
"A : 'b'* 'c' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "bbbbc", debug);
|
||||
assertEquals("bbbbc\n", found);
|
||||
found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "c", debug);
|
||||
assertEquals("c\n", found);
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class TestSets extends BaseTest {
|
|||
"grammar T;\n" +
|
||||
"a : A {System.out.println(_input);} ;\n" +
|
||||
"A : 'b'+ 'c' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "bbbbc", debug);
|
||||
assertEquals("bbbbc\n", found);
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : ('a'|'b')? 'c' {System.out.println(_input);} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "ac", debug);
|
||||
assertEquals("ac\n", found);
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : ('a'|'b')* 'c' {System.out.println(_input);} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "abaac", debug);
|
||||
assertEquals("abaac\n", found);
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ public class TestSets extends BaseTest {
|
|||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : ('a'|'b')+ 'c' {System.out.println(_input);} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "abaac", debug);
|
||||
assertEquals("abaac\n", found);
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ public class TestSets extends BaseTest {
|
|||
"grammar T;\n" +
|
||||
"a : A {System.out.println(_input);} ;\n" +
|
||||
"A : ('a'|'b')? 'c' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "ac", debug);
|
||||
assertEquals("ac\n", found);
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ public class TestSets extends BaseTest {
|
|||
"grammar T;\n" +
|
||||
"a : A {System.out.println(_input);} ;\n" +
|
||||
"A : ('a'|'b')* 'c' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "abaac", debug);
|
||||
assertEquals("abaac\n", found);
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ public class TestSets extends BaseTest {
|
|||
"grammar T;\n" +
|
||||
"a : A {System.out.println(_input);} ;\n" +
|
||||
"A : ('a'|'b')+ 'c' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "abaac", debug);
|
||||
assertEquals("abaac\n", found);
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ public class TestSets extends BaseTest {
|
|||
"grammar T;\n" +
|
||||
"a : A {System.out.println($A.text);} ;\n" +
|
||||
"A : ~('b'|'c') ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "x", debug);
|
||||
assertEquals("x\n", found);
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ public class TestSets extends BaseTest {
|
|||
"grammar T;\n" +
|
||||
"a : A {System.out.println($A.text);} ;\n" +
|
||||
"A : h=~('b'|'c') ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "x", debug);
|
||||
assertEquals("x\n", found);
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ public class TestSets extends BaseTest {
|
|||
"a : A {System.out.println($A.text);} ;\n" +
|
||||
"A : ~('a'|B) ;\n" +
|
||||
"B : 'b' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "x", debug);
|
||||
assertEquals("x\n", found);
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ public class TestSets extends BaseTest {
|
|||
"a : A {System.out.println($A.text);} ;\n" +
|
||||
"A : ~('a'|B) ;\n" +
|
||||
"B : 'b'|'c' ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "x", debug);
|
||||
assertEquals("x\n", found);
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ public class TestSets extends BaseTest {
|
|||
"A : ('a'|B) ;\n" +
|
||||
"fragment\n" +
|
||||
"B : ~('a'|'c') ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "x", debug);
|
||||
assertEquals("x\n", found);
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ public class TestSets extends BaseTest {
|
|||
"B : ~('a'|C) ;\n" +
|
||||
"fragment\n" +
|
||||
"C : 'c'|'d' ;\n ";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "x", debug);
|
||||
assertEquals("x\n", found);
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ public class TestSets extends BaseTest {
|
|||
"a : (A {System.out.println($A.text);})+ ;\n" +
|
||||
"A : [AaBb] ;\n" +
|
||||
"WS : (' '|'\\n')+ {skip();} ;\n";
|
||||
String found = execParser("T.g", grammar, "TParser", "TLexer",
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer",
|
||||
"a", "A a B b", debug);
|
||||
assertEquals("A\n" +
|
||||
"a\n" +
|
||||
|
|
|
@ -20,15 +20,15 @@ public class TestSymbolIssues extends BaseTest {
|
|||
"\n" +
|
||||
"ID : 'a'..'z'+ ID ;",
|
||||
// YIELDS
|
||||
"warning(48): A.g:2:10: illegal option opt\n" +
|
||||
"warning(48): A.g:2:21: illegal option k\n" +
|
||||
"error(59): A.g:7:1: redefinition of header action\n" +
|
||||
"warning(51): A.g:2:10: illegal option opt\n" +
|
||||
"error(19): A.g:11:0: rule a redefinition\n" +
|
||||
"error(60): A.g:5:1: redefinition of members action\n" +
|
||||
"error(47): A.g:9:37: rule b has no defined parameters\n" +
|
||||
"error(24): A.g:9:43: reference to undefined rule: q\n" +
|
||||
"error(46): A.g:10:31: missing parameter(s) on rule reference: a\n"
|
||||
"warning(48): A.g4:2:10: illegal option opt\n" +
|
||||
"warning(48): A.g4:2:21: illegal option k\n" +
|
||||
"error(59): A.g4:7:1: redefinition of header action\n" +
|
||||
"warning(51): A.g4:2:10: illegal option opt\n" +
|
||||
"error(19): A.g4:11:0: rule a redefinition\n" +
|
||||
"error(60): A.g4:5:1: redefinition of members action\n" +
|
||||
"error(47): A.g4:9:37: rule b has no defined parameters\n" +
|
||||
"error(24): A.g4:9:43: reference to undefined rule: q\n" +
|
||||
"error(46): A.g4:10:31: missing parameter(s) on rule reference: a\n"
|
||||
};
|
||||
|
||||
static String[] B = {
|
||||
|
@ -42,11 +42,11 @@ public class TestSymbolIssues extends BaseTest {
|
|||
"\n" +
|
||||
"s : FOO ;",
|
||||
// YIELDS
|
||||
"error(25): B.g:2:9: can't assign string value to token name X in non-combined grammar\n" +
|
||||
"error(35): B.g:4:4: label s conflicts with rule with same name\n" +
|
||||
"error(35): B.g:4:9: label b conflicts with rule with same name\n" +
|
||||
"error(36): B.g:4:15: label X conflicts with token with same name\n" +
|
||||
"error(40): B.g:6:9: label x type mismatch with previous definition: TOKEN_LIST_LABEL!=TOKEN_LABEL\n"
|
||||
"error(25): B.g4:2:9: can't assign string value to token name X in non-combined grammar\n" +
|
||||
"error(35): B.g4:4:4: label s conflicts with rule with same name\n" +
|
||||
"error(35): B.g4:4:9: label b conflicts with rule with same name\n" +
|
||||
"error(36): B.g4:4:15: label X conflicts with token with same name\n" +
|
||||
"error(40): B.g4:6:9: label x type mismatch with previous definition: TOKEN_LIST_LABEL!=TOKEN_LABEL\n"
|
||||
};
|
||||
|
||||
static String[] D = {
|
||||
|
@ -61,8 +61,8 @@ public class TestSymbolIssues extends BaseTest {
|
|||
" : ID ;",
|
||||
|
||||
// YIELDS
|
||||
"error(37): D.g:3:21: label j conflicts with rule a's return value or parameter with same name\n" +
|
||||
"error(41): D.g:5:0: rule b's argument i conflicts a return value with same name\n"
|
||||
"error(37): D.g4:3:21: label j conflicts with rule a's return value or parameter with same name\n" +
|
||||
"error(41): D.g4:5:0: rule b's argument i conflicts a return value with same name\n"
|
||||
};
|
||||
|
||||
static String[] E = {
|
||||
|
@ -78,10 +78,10 @@ public class TestSymbolIssues extends BaseTest {
|
|||
"a : A ;\n",
|
||||
|
||||
// YIELDS
|
||||
"error(73): E.g:4:8: cannot redefine B; token name already defined\n" +
|
||||
"error(73): E.g:5:4: cannot redefine C; token name already defined\n" +
|
||||
"error(73): E.g:6:8: cannot redefine D; token name already defined\n" +
|
||||
"error(72): E.g:7:8: cannot alias X='e'; string already assigned to E\n"
|
||||
"error(73): E.g4:4:8: cannot redefine B; token name already defined\n" +
|
||||
"error(73): E.g4:5:4: cannot redefine C; token name already defined\n" +
|
||||
"error(73): E.g4:6:8: cannot redefine D; token name already defined\n" +
|
||||
"error(72): E.g4:7:8: cannot alias X='e'; string already assigned to E\n"
|
||||
};
|
||||
|
||||
@Test public void testA() { super.testErrors(A, false); }
|
||||
|
|
|
@ -136,7 +136,7 @@ public class TestTokenTypeAssignment extends BaseTest {
|
|||
"A : 'a' ;\n" +
|
||||
"B : '}' ;\n"+
|
||||
"WS : (' '|'\\n') {skip();} ;";
|
||||
String found = execParser("P.g", grammar, "PParser", "PLexer",
|
||||
String found = execParser("P.g4", grammar, "PParser", "PLexer",
|
||||
"a", "a}", false);
|
||||
assertEquals("a}\n", found);
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ public class TestTokenTypeAssignment extends BaseTest {
|
|||
"A : 'a' ;\n" +
|
||||
"B : '}' ;\n"+
|
||||
"WS : (' '|'\\n') {skip();} ;";
|
||||
String found = execParser("P.g", grammar, "PParser", "PLexer",
|
||||
String found = execParser("P.g4", grammar, "PParser", "PLexer",
|
||||
"a", "a}", false);
|
||||
assertEquals("a}\n", found);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ public class TestToolSyntaxErrors extends BaseTest {
|
|||
"grammar A;\n" +
|
||||
"",
|
||||
// YIELDS
|
||||
"error(64): A.g::: grammar A has no rules\n",
|
||||
"error(64): A.g4::: grammar A has no rules\n",
|
||||
|
||||
"A;",
|
||||
"error(16): <string>:1:0: 'A' came as a complete surprise to me\n",
|
||||
|
@ -23,22 +23,22 @@ public class TestToolSyntaxErrors extends BaseTest {
|
|||
"grammar A;\n" +
|
||||
"a : ID ;;\n"+
|
||||
"b : B ;",
|
||||
"error(16): A.g:2:8: ';' came as a complete surprise to me\n",
|
||||
"error(16): A.g4:2:8: ';' came as a complete surprise to me\n",
|
||||
|
||||
"grammar A;;\n" +
|
||||
"a : ID ;\n",
|
||||
"error(16): A;.g:1:10: ';' came as a complete surprise to me\n",
|
||||
"error(16): A;.g4:1:10: ';' came as a complete surprise to me\n",
|
||||
|
||||
"grammar A;\n" +
|
||||
"a @init : ID ;\n",
|
||||
"error(16): A.g:2:8: mismatched input ':' expecting ACTION while matching rule preamble\n",
|
||||
"error(16): A.g4:2:8: mismatched input ':' expecting ACTION while matching rule preamble\n",
|
||||
|
||||
"grammar A;\n" +
|
||||
"a ( A | B ) D ;\n" +
|
||||
"b : B ;",
|
||||
"error(16): A.g:2:3: '(' came as a complete surprise to me while matching rule preamble\n" +
|
||||
"error(16): A.g:2:11: mismatched input ')' expecting SEMI while matching a rule\n" +
|
||||
"error(16): A.g:2:15: mismatched input ';' expecting COLON while matching a lexer rule\n",
|
||||
"error(16): A.g4:2:3: '(' came as a complete surprise to me while matching rule preamble\n" +
|
||||
"error(16): A.g4:2:11: mismatched input ')' expecting SEMI while matching a rule\n" +
|
||||
"error(16): A.g4:2:15: mismatched input ';' expecting COLON while matching a lexer rule\n",
|
||||
};
|
||||
|
||||
@Test public void testA() { super.testErrors(A, true); }
|
||||
|
@ -48,7 +48,7 @@ public class TestToolSyntaxErrors extends BaseTest {
|
|||
"grammar A;\n" +
|
||||
"a : : A ;\n" +
|
||||
"b : B ;",
|
||||
"error(16): A.g:2:4: ':' came as a complete surprise to me while matching alternative\n",
|
||||
"error(16): A.g4:2:4: ':' came as a complete surprise to me while matching alternative\n",
|
||||
};
|
||||
super.testErrors(pair, true);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class TestToolSyntaxErrors extends BaseTest {
|
|||
"grammar A;\n" +
|
||||
"a : A \n" +
|
||||
"b : B ;",
|
||||
"error(16): A.g:3:0: unterminated rule (missing ';') detected at 'b :' while looking for rule element\n",
|
||||
"error(16): A.g4:3:0: unterminated rule (missing ';') detected at 'b :' while looking for rule element\n",
|
||||
};
|
||||
super.testErrors(pair, true);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class TestToolSyntaxErrors extends BaseTest {
|
|||
"lexer grammar A;\n" +
|
||||
"A : 'a' \n" +
|
||||
"B : 'b' ;",
|
||||
"error(16): A.g:3:0: unterminated rule (missing ';') detected at 'B :' while looking for lexer rule element\n",
|
||||
"error(16): A.g4:3:0: unterminated rule (missing ';') detected at 'B :' while looking for lexer rule element\n",
|
||||
};
|
||||
super.testErrors(pair, true);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public class TestToolSyntaxErrors extends BaseTest {
|
|||
"grammar A;\n" +
|
||||
"a : A \n" +
|
||||
"b[int i] returns [int y] : B ;",
|
||||
"error(16): A.g:3:9: unterminated rule (missing ';') detected at 'returns int y' while looking for rule element\n"
|
||||
"error(16): A.g4:3:9: unterminated rule (missing ';') detected at 'returns int y' while looking for rule element\n"
|
||||
};
|
||||
super.testErrors(pair, true);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public class TestToolSyntaxErrors extends BaseTest {
|
|||
" catch [Exception e] {...}\n" +
|
||||
"b : B ;\n",
|
||||
|
||||
"error(16): A.g:2:4: unterminated rule (missing ';') detected at 'b catch' while looking for rule element\n"
|
||||
"error(16): A.g4:2:4: unterminated rule (missing ';') detected at 'b catch' while looking for rule element\n"
|
||||
};
|
||||
super.testErrors(pair, true);
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ public class TestToolSyntaxErrors extends BaseTest {
|
|||
"a : A \n" +
|
||||
" catch [Exception e] {...}\n",
|
||||
|
||||
"error(16): A.g:2:4: unterminated rule (missing ';') detected at 'A catch' while looking for rule element\n"
|
||||
"error(16): A.g4:2:4: unterminated rule (missing ';') detected at 'A catch' while looking for rule element\n"
|
||||
};
|
||||
super.testErrors(pair, true);
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ public class TestToolSyntaxErrors extends BaseTest {
|
|||
"a @ options {k=1;} : A ;\n" +
|
||||
"b : B ;",
|
||||
|
||||
"error(16): A.g:2:4: 'options {' came as a complete surprise to me while looking for an identifier\n"
|
||||
"error(16): A.g4:2:4: 'options {' came as a complete surprise to me while looking for an identifier\n"
|
||||
};
|
||||
super.testErrors(pair, true);
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public class TestToolSyntaxErrors extends BaseTest {
|
|||
"a } : A ;\n" +
|
||||
"b : B ;",
|
||||
|
||||
"error(16): A.g:2:2: '}' came as a complete surprise to me while matching rule preamble\n"
|
||||
"error(16): A.g4:2:2: '}' came as a complete surprise to me while matching rule preamble\n"
|
||||
};
|
||||
super.testErrors(pair, true);
|
||||
}
|
||||
|
@ -135,8 +135,8 @@ public class TestToolSyntaxErrors extends BaseTest {
|
|||
"mode foo;\n" +
|
||||
"b : B ;",
|
||||
|
||||
"error(16): A.g:4:0: 'b' came as a complete surprise to me\n" +
|
||||
"error(16): A.g:4:6: mismatched input ';' expecting COLON while matching a lexer rule\n"
|
||||
"error(16): A.g4:4:0: 'b' came as a complete surprise to me\n" +
|
||||
"error(16): A.g4:4:6: mismatched input ';' expecting COLON while matching a lexer rule\n"
|
||||
};
|
||||
super.testErrors(pair, true);
|
||||
}
|
||||
|
|
|
@ -87,12 +87,12 @@ public class TestTopologicalSort extends BaseTest {
|
|||
@Test
|
||||
public void testSimpleTokenDependence() throws Exception {
|
||||
Graph g = new Graph();
|
||||
g.addEdge("Java.g", "MyJava.tokens"); // Java feeds off manual token file
|
||||
g.addEdge("Java.tokens", "Java.g");
|
||||
g.addEdge("Def.g", "Java.tokens"); // walkers feed off generated tokens
|
||||
g.addEdge("Ref.g", "Java.tokens");
|
||||
g.addEdge("Java.g4", "MyJava.tokens"); // Java feeds off manual token file
|
||||
g.addEdge("Java.tokens", "Java.g4");
|
||||
g.addEdge("Def.g4", "Java.tokens"); // walkers feed off generated tokens
|
||||
g.addEdge("Ref.g4", "Java.tokens");
|
||||
|
||||
String expecting = "[MyJava.tokens, Java.g, Java.tokens, Ref.g, Def.g]";
|
||||
String expecting = "[MyJava.tokens, Java.g4, Java.tokens, Ref.g4, Def.g4]";
|
||||
List nodes = g.sort();
|
||||
String result = nodes.toString();
|
||||
assertEquals(expecting, result);
|
||||
|
@ -101,12 +101,12 @@ public class TestTopologicalSort extends BaseTest {
|
|||
@Test
|
||||
public void testParserLexerCombo() throws Exception {
|
||||
Graph g = new Graph();
|
||||
g.addEdge("JavaLexer.tokens", "JavaLexer.g");
|
||||
g.addEdge("JavaParser.g", "JavaLexer.tokens");
|
||||
g.addEdge("Def.g", "JavaLexer.tokens");
|
||||
g.addEdge("Ref.g", "JavaLexer.tokens");
|
||||
g.addEdge("JavaLexer.tokens", "JavaLexer.g4");
|
||||
g.addEdge("JavaParser.g4", "JavaLexer.tokens");
|
||||
g.addEdge("Def.g4", "JavaLexer.tokens");
|
||||
g.addEdge("Ref.g4", "JavaLexer.tokens");
|
||||
|
||||
String expecting = "[JavaLexer.g, JavaLexer.tokens, JavaParser.g, Ref.g, Def.g]";
|
||||
String expecting = "[JavaLexer.g4, JavaLexer.tokens, JavaParser.g4, Ref.g4, Def.g4]";
|
||||
List nodes = g.sort();
|
||||
String result = nodes.toString();
|
||||
assertEquals(expecting, result);
|
||||
|
|
Loading…
Reference in New Issue