Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not generate java files from Rust grammar file #1997

Closed
onekosha opened this issue Aug 30, 2017 · 1 comment
Closed

Can not generate java files from Rust grammar file #1997

onekosha opened this issue Aug 30, 2017 · 1 comment

Comments

@onekosha
Copy link

I try to generate from Rust grammar file getting https://github.com/jorendorff/rust-grammar j

ava files. ANTLR4 generates two files with mistake.
Some code from file xidstart.java:
// Generated from src\main\antlr4\imports\xidstart.g4 by ANTLR 4.7
package src.main.antlr4.imports;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.;
import org.antlr.v4.runtime.atn.
;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;

@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class xidstart extends Lexer {
static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }

protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
	new PredictionContextCache();
public static final int

;
public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};

Some code from file xidcontinue.java:
// Generated from src\main\antlr4\imports\xidcontinue.g4 by ANTLR 4.7
package src.main.antlr4.imports;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.;
import org.antlr.v4.runtime.atn.
;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;

@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class xidcontinue extends Lexer {
static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }

protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
	new PredictionContextCache();
public static final int

;
public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
Project with code places on https://github.com/onekosha/nb-rust. Apache Maven 3.5.0. Windows 10 64 bit. JDK 1.8.0_141 64 bit. Add files from folder 'generated-sources'.
generated-sources.zip
If I use Clojure grammar file all good. I try to use other versions ANTLR4 but it does not help me. I think that problem in xidcontinue.g4 and xidstart.g4 but I find not other newer version for these files. Thanks.

@brauliobz
Copy link
Contributor

I had the same problem you had (in another grammar).

You shouldn't try to generate parsers for xidstart.g4 and xidcontinue.g4 (the build.sh script in the mentioned repo doesn't attempt to compile them... are you using it?). These files exist only to be included by the actual grammar, since they have only fragment rules.

Also, you could probably just use [\p{XID_start}] and [\p{XID_continue}] instead of including these files.

About the bug in code generation (where it generates public static final int ;): there is a pull request (#2007) to correct it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants