ANTLR4 Generating Lexer in JAVA instead of C Sharp - antlr4

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.

Related

Sublime text 3 and overriding settings per project doesn't work

I've setup to my user settings on sublime text 3, the following option: trim_trailing_white_space_on_save: true
But it seems our collagues have a different opinion regarding of it and if it is useful. So I have to override this setting per project (I wanted to other projects, I just want to be skipped on a specific one). I've tried by creating a file .sublime-workplace and/or .sublime-project on the root of the project folder and I added the following:
{
"settings":
{
"trim_trailing_white_space_on_save": false
}
}
But when I save a file with whitespaces, it still keeps trimming them. What am I doing wrong? Is there specific settings which I can bypass per-project? If yes, is there another way of doing that (maybe a sublime plugin or something).
From the description in your question, the problem may be that you created the project file but didn't actually open it. Sublime only treats paths with a project file in them specially if you open the project, e.g. via Project > Open Project or from the command line via subl --project path/to/project.sublime-project.
Additionally, without a list of paths to include in the project, the project defaults itself to being empty, which is probably not what you want.
From your existing window that you're already working with, select Project > Save Project As... to save a project and workspace that captures the current state of everything; folders visible in the side bar as well as any files that may already be open. Once that's done you can use Project > Edit Project to edit the project file and add the setting as you did above.
Aside from that, a project file like the following saved into the folder you're using for your project will also do what you want; just remember to use Project > Open Project... or Project > Switch Project... to open the file you've created so that Sublime will use it.
{
"folders":
[
{
"path": "."
}
],
"settings":
{
"trim_trailing_white_space_on_save": true
}
}

Error: A namespace cannot directly contain members such as fields EntityFramework.dll' could not be found

enter image description hereI want to create model: add > class > ado.net entity, for my db first project and also want to create CRUD operation by asp.netscaffolding, but failed to create a model with necessary code.and thus i failed to create scaffolding .
in my model file AllahHelp.Context.cs, there is no code, only the text "ErrorGeneratingOutput".
Error 1:
A namespace cannot directly contain members such as fields or methods F:\project\WebApplication8\WebApplication8\Models\AllahHelp.Context.cs 1 1 WebApplication8
Error 2:
Compiling transformation: Metadata file 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools..\IDE\EntityFramework.dll' could not be found F:\project\WebApplication8\WebApplication8\Models\AllahHelp.tt 1 1 WebApplication8
If there is an error transforming your .tt files into class files, your class files will just have "ErrorGeneratingOutput" in the source file, which causes a "namespace cannot directly contain members such as fields" error, but doesn't really have anything to do with that.
Your actual error sounds like you're missing a reference to EntityFramework.dll. Right click the project, choose "Manage NuGet Packages..." and find and install EntityFramework to your project.
In some situations I've also run into a problem where since the transformation occurs before files are copied, referenced dlls don't ever get copied since the error occurs and stops the process. In this case you would need to remove the model from your project temporarily, successfully compile the project, and then add the model back.
According to this similar question it could also be because of your install path. If that is your issue, try to find where the dll is, and correct the environment variable VS120COMNTOOLS (Control Panel -> System -> Advanced System Settings -> Environment Variables -> System Variables)
(Be careful changing system variables, though.)
I was getting this error when attempting to build a project using .tt templates. I fixed the issue by checking everywhere that I used C# code injection and making sure that I closed each section of C# code by including #>.
Example:
Problematic code:
{
"find": "__LOCATION__",
"replaceWith": "<#= deployment.Location"
},
Fixed code:
{
"find": "__LOCATION__",
"replaceWith": "<#= deployment.Location #>"
},

minko / lua issue : premake5.lua:3: attempt to index global 'minko' (a nil value)

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.

Visual studio export template replaces original projectname with $safeprojectname$

My project is a mvc4 project in visual studio 2013 ultimate.
I tryd to send my project by following the steps :
File > Export template > (leave all the options as default)
I get a zip that i unpack. If i open the unpacked solution and run the program i get alot of errors. It looks like visual studio replaced all the text that contained the projectname with $safeprojectname$. How can i export the project without visual studio replacing all the 'projectname' spots so that i can run my program.
I tryed creating a new project (console application) with no code in it, if i export it and import it i get the same message first i get :
Warning 1 Load of property 'RootNamespace' failed. The string for the root namespace must be a valid identifier. SvenEind
and after running i get
190 errors 31 warnings
I tryd importing http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/building-the-ef5-mvc4-chapter-downloads and that worked for me.
So i guess the problem is in some kind of settings for exporting files.
replaced all the text that contained the projectname with $safeprojectname$
This is very much by design. You created a project template, a cookie-cutter for new projects. You are not supposed to do anything with the .zip archive. It should sit patiently in your "My Exported Templates" folder. Until the day arrives that you want to start a new project.
You then can pick the template instead of using one of the built-in ones that were preinstalled by the Visual Studio installer. Visual Studio prompts you for the project name. It then unzips the archive, copying the files into your new project directory. And modifies the files, $safeprojectname$ is substituted by the new project name you entered. You now have a good start for your new project, using the settings and assets that you saved earlier when you created the template.
Sounds like you had an entirely different use in mind, I can't guess at the intention from the question.
Hmmm. I got this error on Build:
The app manifest must be valid as per schema: Line 42, Column 18, Reason: '$safeprojectname$' violates pattern constraint of '([A-Za-z][A-Za-z0-9]*)(\.[A-Za-z][A-Za-z0-9]*)*'. The attribute 'Id' with value '$safeprojectname$' failed to parse.
So I grabbed the project name from the VS Configuration Manger and put it in the app manifest like this.
<Applications>
<Application
Id="CordovaApp.Windows10"
And the error went away and the project built. HTH.

How to do code coverage and create reports in Visual Studio 2012 Professional

I'm trying to do code coverage and create reports in VS2012 Pro, which doesn't include the CodeCoverage.exe and the rest of the tools (As in Ultimate and Premium). I've looked through a lot of examples, and they usually seem to take the generated data file and convert it into xml. When I try to use (compile) that code, it complains about missing assemblies, which in turn seem related to the fact that I'm using the Pro version (as opposed to the Premium and Ultimate).
I have a script that generates the coverage data to a .vsp file, but when using the VSPerfReport.exe (which seemed like a good fit), it fails with:
Error VSP1712: Invalid File: myexename.vsp
Error: VSP1804: Did not successfully open the file.
I want to create an html page in the end, and can probably do that by getting an xml first.
I also tried to open the coverage file in VS but it couldn't read the file.
So, I wonder if it's at all possible to do this with the tools provided in the Pro version?
Here is the script:
#echo off
set EXE=<path to exe>\<exename>
set OUTPATH=.\coverage
set OUT=%OUTPATH%\<exename>
set ARGS=<some args>
rem I've seen this extension in several examples, but it generates:
rem Error VSP1712: No readers configured for the .coverage file extension. Check the ReaderFactoryConfig file.
rem set VSP=%EXE%.coverage
rem This extension generates the error message:
rem Error VSP1712: Invalid File: <path to exe>\<exename>.vsp
rem Error: VSP1804: Did not successfully open the file.
set VSP=%EXE%.vsp
mkdir %OUTPATH%
vsinstr.exe %EXE% -coverage -outputpath:%OUTPATH%
vsperfcmd.exe -start:coverage -output:%VSP%
echo Running exe!
%OUT% %ARGS%
vsperfcmd.exe -shutdown
VSPerfReport.exe %VSP% /Xml /Summary:all
rm %OUT%
Edit
I use C++ programs. And free is good, so I'd like to see what my options are.

Resources