ANTLR4 4.7.1 generates a line in the parse.cs file that says
throw new RuntimeException("UNEXPECTED_CHAR=" + (_localctx._UNEXPECTED_CHAR!=null?_localctx._UNEXPECTED_CHAR.Text:null));
The exception doesnt exist. Its easy to fix by hand editing the generated code, but thats kind of annoying to have to do each iteration of grammer edit.
Using the built in c# support like this
java -jar c:\tools\antlr-4.7.1-complete.jar -Dlanguage=CSharp -visitor SQLite.g4
That line is not coming from ANTLR, it's coming from the grammar file you're using.
Assuming that you're using SQLite.g4 from the grammars-v4 repository, the culprit is the error rule on lines 37-42:
error
: UNEXPECTED_CHAR
{
throw new RuntimeException("UNEXPECTED_CHAR=" + $UNEXPECTED_CHAR.text);
}
;
So you can fix the problem by editing the grammar to either contain C# code instead of Java code or not contain any embedded code at all (it should be fine to just remove the error rule (and the one instance where it's used) altogether).
Related
I am working on writing a native app written in Kotlin and compiled with the GraalVM. Part of this requires me to open and manage spreadsheets (xlsx).
When I run the app in vm mode using any JVM, including Graal, everything works fine. However, when I compile the app native, I get an error when I attempt to open the same excel file as the one I open in the JVM. For the record, I am using apache POI
UnsupportedCharsetException: CP1252
Can someone explain why it works in JVM mode but not native?
a snippet of the stacktrace:
java.lang.ExceptionInInitializerError: null
at org.apache.poi.poifs.filesystem.FileMagic.<init>(FileMagic.java:133) ~[pikr:5.2.3]
at org.apache.poi.poifs.filesystem.FileMagic.<clinit>(FileMagic.java:74) ~[pikr:5.2.3]
And the code in question in POI:
FileMagic(String... magic) {
this.magic = new byte[magic.length][];
int i=0;
for (String s : magic) {
this.magic[i++] = s.getBytes(LocaleUtil.CHARSET_1252);
}
}
Try adding -H:+AddAllCharsets to your command line.
There must be some way to add a few specified charsets only, but I cannot find it in the options (native-image --expert-options-all)
I am working with minko and managed to compile MINKO SDK properly for 3 platforms (Linux, Android, HTML5) and build all tutorials / examples. Moving on to create my own project, I followed the instructions on how to use the existing skeleton project, then using an existing example project.
(I believe there is an error in the skeleton code at this line :
auto sceneManager = SceneManager::create(canvas->context()); //does not compile
where as the example file look like this :
auto sceneManager = SceneManager::create(canvas); //compile and generate binary
I was able to do so by modifying premake5.lua (to include more plugins) and calling script/solution_gmake_gcc.sh
to generate the make solution a week ago. Today, I tried to make a new project in a new folder but calling
script/solution_gmake_gcc.sh and script/clean failed with this error:
minko-master/skel_tut/mycode/premake5.lua:3: attempt to index global 'minko' (a nil value)
Now at premake5.lua line 3 there is this line : minko.project.solution(PROJECT_NAME),
however sine i am not familiar with lua at all, can anyone shed any light on the issue ?
What is supposed to be declared here, why is it failing suddenly... ?
(I can still modify,compile and run the code but i can't for example add more plug-ins)
PS: weirdly enough, the previously 'working' project is also failing at this point.
Thanks.
PROJECT_NAME = path.getname(os.getcwd())
minko.project.application("minko-tutorial-" .. PROJECT_NAME)
files { "src/**.cpp", "src/**.hpp", "asset/**" }
includedirs { "src" }
-- plugins
minko.plugin.enable("sdl")
minko.plugin.enable("assimp")
minko.plugin.enable("jpeg")
minko.plugin.enable("bullet")
minko.plugin.enable("png")
--html overlay
minko.plugin.enable("html-overlay")
Assuming that's indeed your project premake5.lua file (please us the code tags next time), you should have include "script" at the beginning of the file:
https://github.com/aerys/minko/blob/master/skeleton/premake5.lua#L1
If you don't have this line, it will not include script/premake5.lua which is in charge of including the SDK build system files that defines everything inside the minko Lua namespace/table. That's why you get that error.
I think you copy pasted one of the examples/tutorials premake5.lua file instead of modifying the one provided by the skeleton. The premake conf file of the examples/tutorials are different since they are included from the SDK premake files. But your app premake5.lua does the "opposite": it includes the SDK conf files rather than being included by them.
The best practice is to edit your app's copy of the skeleton's premake5.lua (instead of copy/pasting one from the examples/tutorials).
(I believe there is an error in the skeleton code at this line :
That's possible. Our build server doesn't test the skeleton code. That's a mistake we will fix ASAP to make sure it works properly.
script/solution_gmake_gcc.sh and script/clean failed with this error:
minko-master/skel_tut/mycode/premake5.lua:3: attempt to index global 'minko' (a nil value)
Could you copy/paste your premake5.lua file?
Also, what's the value you set for the MINKO_HOME env var? Maybe you've moved the SDK...
Note that instead of setting a global MINKO_HOME env var, you can also set the corresponding LUA constant at the very begining of your premake5.lua file.
i am trying to read dicom images without using imageviewer and i came across VtkGdmReader.. when i am trying to execute it, its giving me an error:
code => vtkGdmReader example
error C2039: 'SetInput' : is not a member of 'vtkTexture'
error C2039: 'SetInput' : is not a member of 'vtkPolyDataMapper'
please can any one tell me why am i facing this problem, is this error related to vtk version ? if so then how can i go about it ?
please help me resolving the problem..
As said in the comments, this error is related to the VTK version. SetInput() was removed in VTK 6.
You can either work in VTK 5 or update the code. If you decide to update it, this error gets fixed by replacing SetInput() with either SetInputData() or SetInputConnection() with a few modifications. You should use SetInputConnection() if you want the filters to go through the pipeline.
As an example of fixing the errors you mentioned, you should replace the following lines in the code you provided:
VTKtexture->SetInput(ima); and
VTKplaneMapper->SetInput(VTKplane->GetOutput());
to:
VTKtexture->SetInputConnection(reader->GetOutputPort()); and
VTKplaneMapper->SetInputConnection(VTKplane->GetOutputPort());
In the second modification (VTKplaneMapper), note that we just changed GetOutput() to GetOutputPort(), while in the first one (VTKtexture) we completely changed the argument passed to SetInputConnection(). That happens because data objects (such as ima) no longer have dependency on pipeline objects (such as algorithms and executives). In this case, we give the algorithm that generated that data object as the argument - if you look for it, you can see the line vtkImageData* ima = reader->GetOutput();, you just have to replace GetOutput() by GetOutputPort() as we did in the second modification.
I recommend looking into the VTK Wiki's VTK 6 Migration pages (and guide) for more information on this error and other errors that you might run into.
When doing
java -cp C:\Tools\Libraries\antlr4-csharp-complete.jar org.antlr.v4.Tool Hello.g4
I get the following files:
HelloBaseListener.cs
Hello.tokens
HelloListener.cs
HelloParser.cs
HelloLexer.tokens
HelloLexer.java
My question is about the last file. Why is it .java instead of .cs?
I'm using antlr4-csharp-4.0.1-SNAPSHOT-complete.jar
Grammar is:
grammar Hello; // Define a grammar called Hello
options
{
language=CSharp_v4_0;
}
r : 'hello' ID ; // match keyword hello followed by an identifier
ID : [a-z]+ ; // match lower-case identifiers
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines, \r (Windows)
Hello Sam! I only have visual studio express so I can't install the extension. This is the code that I'm using but it is still generating the HelloLexer.java.
AntlrClassGenerationTaskInternal a = new AntlrClassGenerationTaskInternal();
List<String> files = new List<string>();
files.Add(#"C:\Tools\Grammars\Hello.g4");
a.JavaVendor = "JavaSoft";
a.ToolPath = #"C:\Tools\Libraries\antlr4-csharp-complete.jar";
a.JavaInstallation = "Java Development Kit";
a.SourceCodeFiles = files;
a.OutputPath = #"C:\Tools\Grammars\CSharp\";
a.Execute();
By the way, visual studio complained because it was not able to find Antlr4ClassGenerationTask.IsFatalException(ex)
I appreciate your help on this.
Regards,
Omar.
I think it's a bug, I had got the same problem, but there is a solution.
1) If you want you can remove
options
{
language=CSharp_v4_0;
}
I think is ignored by the code generator
2) create a BAT file with the follow code
#echo OFF
IF "%CLASSPATH%" == "" (SET CLASSPATH=.;.\antlr4-csharp-4.0.1-SNAPSHOT-complete.jar;%CLASSPATH%)
java org.antlr.v4.Tool %* -Dlanguage=CSharp_v4_5
put antlr4-csharp-4.0.1-SNAPSHOT-complete.jar in the same path, now you can use this file to comile. To resolve the issue the magic command line argument is "-Dlanguage=CSharp_v4_5" or the version of C# you are using.
The generated files now have inside the Lexer.cs
Edit 11/20/13: Updated instructions are now available on the project wiki
https://github.com/sharwell/antlr4cs/wiki/Installation
Here are a few messages I sent over the past few months related to this issue. If you don't want to install the Visual Studio extension described below, you'll need to use the source code of Antlr4ClassGenerationTaskInternal.cs to determine a set of command line options that will work.
Also, you can remove the language=CSharp_v4_0; option because it's passed on the command line now.
The C# target wasn't designed for command line usage. You will need to integrate the code generation into your project file according to the instructions on the following page, and the parsers will be generated automatically when you build your project.
https://github.com/sharwell/antlr4cs
You do need to include the .g4 file in your project and configure a few properties of the file. If you install the following extension before adding the grammar to your project, all the other options will be configured for you automatically.
ANTLR Language Support for Visual Studio 2010-
2012
If you already have the .g4 file in your project, and want to still use the extension to automatically configure the proper settings, you can do the following:
Install the extension.
Click the project in Solution Explorer and enable Show All Files (button on the Solution Explorer toolbar). This step greatly simplifies step 4.
Right click the .g4 file in the project, and select Exclude From Project.
Right click the .g4 file again and select Include In Project.
(Optional) You can disable Show All Files when you no longer need it.
Has anyone of you successfully added a lexer to scintilla?
I have been following the short instructions at http://www.scintilla.org/SciTELexer.html - and even discovered the secret extra instructions at http://www.scintilla.org/ScintillaDoc.html#BuildingScintilla (Changing Set of Lexers)
Everything compiles, and I can add the lexer to SciTE just fine, but my ColouriseMapfileDoc method just does not get called (a printf does not produce output). If I add the same code to e.g. the ColouriseLuaDoc lexer, everything is fine (a printf does produce output).
Specifically I have
In scintilla/include/Scintilla.iface, added val SCLEX_MAPFILE=99
And any lexical class IDs
In the scintilla/include directory run HFacer.py and confirmed that the SciLexer.h file has changed.
Created LexMapfile.cxx with a ColouriseMapfileDoc function
At the end of the file associated the lexer ID and name with the function:
LexerModule lmMapfile(SCLEX_MAPFILE, ColouriseMapfileDoc, "mapfile");
Run LexGen.py to generate all the makefiles (as per the secret instructions)
Created a new SciTE properties file by cloning scite/src/others.properties
Set up some styles
In scite/src/SciTEGlobal.properties added $(filter.conf) to the definition of open.filter.
Added this language to the Language menu of SciTE,
Built both Scintilla and SciTE.
Grumbled and cursed.
What am I doing wrong, except maybe step 12?
In case someone reads this question in the future - you will also have to add a line
import yourformat in SciTEGlobal.properties. That's the undocumented step 9b.
In case someone reads this question in the future - you will also have to add a line import
yourformat in SciTEGlobal.properties. That's the undocumented step 9b.
This step is no longer required. I compiled 3.2.2 and this was done with import *. The rest of the steps are still complete and relevant though.
I'm wring one lexer directly in scintilla/lexer/LexOthers.cxx as described in http://www.scintilla.org/SciTELexer.html.
For scite 3.2.3 the lacking step 5b is that you need to add LINK_LEXER(lmYouLexerMod); in scintilla/src/Catalogue.cxx.