diff --git a/codegen/templates/D.stg b/codegen/templates/D.stg index 628fe32..5462628 100644 --- a/codegen/templates/D.stg +++ b/codegen/templates/D.stg @@ -889,6 +889,7 @@ package ; import antlr.v4.runtime.Lexer; import antlr.v4.runtime.CharStream; import antlr.v4.runtime.InterfaceRuleContext; +import antlr.v4.runtime.RuleContext; import antlr.v4.runtime.RuntimeMetaData; import antlr.v4.runtime.Token; import antlr.v4.runtime.TokenStream; diff --git a/source/antlr/v4/runtime/dfa/DFA.d b/source/antlr/v4/runtime/dfa/DFA.d index b268730..293438f 100644 --- a/source/antlr/v4/runtime/dfa/DFA.d +++ b/source/antlr/v4/runtime/dfa/DFA.d @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. + * Copyright (c) 2012-2020 The ANTLR Project. All rights reserved. * Use of this file is governed by the BSD 3-clause license that * can be found in the LICENSE.txt file in the project root. */ @@ -189,14 +189,14 @@ class DFA } DFASerializer serializer = new DFASerializer(this, vocabulary); - return serializer.toString(); + return serializer.toString; } public string toLexerString() { if (s0 is null) return ""; DFASerializer serializer = new LexerDFASerializer(this); - return serializer.toString(); + return serializer.toString; } } diff --git a/source/antlr/v4/runtime/dfa/DFASerializer.d b/source/antlr/v4/runtime/dfa/DFASerializer.d index d2816b3..5336d10 100644 --- a/source/antlr/v4/runtime/dfa/DFASerializer.d +++ b/source/antlr/v4/runtime/dfa/DFASerializer.d @@ -1,31 +1,7 @@ /* - * [The "BSD license"] - * Copyright (c) 2012 Terence Parr - * Copyright (c) 2012 Sam Harwell - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * Copyright (c) 2012-2020 The ANTLR Project. All rights reserved. + * Use of this file is governed by the BSD 3-clause license that + * can be found in the LICENSE.txt file in the project root. */ module antlr.v4.runtime.dfa.DFASerializer; diff --git a/source/antlr/v4/runtime/dfa/LexerDFASerializer.d b/source/antlr/v4/runtime/dfa/LexerDFASerializer.d index 980aeb4..5308cd1 100644 --- a/source/antlr/v4/runtime/dfa/LexerDFASerializer.d +++ b/source/antlr/v4/runtime/dfa/LexerDFASerializer.d @@ -22,7 +22,8 @@ class LexerDFASerializer : DFASerializer */ public override string getEdgeLabel(int i) { - return "'" ~ to!string(i) ~ "'"; + import std.format : format; + return format!"'%s'"(cast(char)i); } } diff --git a/test/D.test.stg b/test/D.test.stg index 2d51dff..8d272e4 100644 --- a/test/D.test.stg +++ b/test/D.test.stg @@ -58,7 +58,7 @@ Text() ::= "this.getText.get!(string)" ValEquals(a,b) ::= <%==%> -TextEquals(a) ::= <%this.getText.get!(string).equals("")%> +TextEquals(a) ::= <%this.getText.get!(string) == ""%> PlusText(a) ::= <%"" ~ this.getText.get!(string)%> diff --git a/test/d/BaseDTest.java b/test/d/BaseDTest.java index 464ad9c..4f83e67 100644 --- a/test/d/BaseDTest.java +++ b/test/d/BaseDTest.java @@ -892,11 +892,13 @@ protected void writeParserTestFile(String parserName, String lexerName, protected void writeLexerTestFile(String lexerName, boolean showDFA) { ST outputFileST = new ST( - "import std.stdio : File, writefln;\n" + "import std.stdio : File, write, writefln;\n" + "\n" + "import antlr.v4.runtime.Token;\n" + "import antlr.v4.runtime.ANTLRInputStream;\n" + "import antlr.v4.runtime.CommonTokenStream;\n" + + "import antlr.v4.runtime.Lexer;\n" + + "import antlr.v4.runtime.atn.LexerATNSimulator;\n" + "import ;\n" + "\n" + "int main(string[] args) {\n" @@ -907,7 +909,7 @@ protected void writeLexerTestFile(String lexerName, boolean showDFA) { + " tokens.fill();\n" + " foreach (token; tokens.getTokens)\n" + " writefln!\"%s\"(token);\n" - + (showDFA ? " std::cout \\<\\< lexer.getInterpreter\\()->getDFA(Lexer::DEFAULT_MODE).toLexerString();\n" : "\n") + + (showDFA ? " write((cast(LexerATNSimulator)lexer.getInterpreter).getDFA(Lexer.DEFAULT_MODE).toLexerString);\n" : "\n") + " return 0;\n" + "}\n"); outputFileST.add("lexerName", lexerName);