actually I have a problem with incuding an antlr4 grammar in my angular project written in visual studio code. I could create the grammar itself (the .g4 file) and there was automatically built an .antlr folder, in which are the following files:
However, these are only the java files and I need for the browser the javascript version. At this point I am not sure how to continue.
Apparently, VS Code automatically does something like this behind the scenes:
java -cp antlr-4.7.2-complete.jar org.antlr.v4.Tool Grammar.g4
which generates the default target language (Java).
To let it generate Javascript sources, do something like this from your terminal where your grammar is located:
java -cp antlr-4.7.2-complete.jar org.antlr.v4.Tool -Dlanguage=JavaScript Grammar.g4
Assuming you have antlr-4.7.2-complete.jar in the same folder as your Grammar.g4 file.
You should be able to change this settting in antl4.generation -> language=JavaScript
Related
Good morning. I am working on a project that uses Karate Standalone. I am completely new to Karate to excuse my lack of knowledge here.
The standalone karate jar is executed with the '-m' command line parameter to start a mock.feature. The mock.feature references a utils class that is built on 'org.springframework.amqp'.
The problem is that the karate.jar startup fails with a Command Line Execution Exception due to external library 'org/springframework/amqp/rabbit/connection/ConnectionFactory'
api1_mock_test.feature
Feature: API1 Mock Test
Background:
* def RabbitUtils = Java.type('utils.RabbitUtils')
.
.
Our RabbitUtils is just a java class that imports org.springframework.amqp external libraries to provide functions to interact with a Rabbit AMQP broker e.g. connect, receive, publish, purge etc. When built and run in IntelliJ all works ok. The POM reference in the project is:
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>
Does the Karate standalone jar have some way of referencing external libraries? The classpath parameter is set to reference our workspace '.\target\test-classes' and contains the RabbitUtils.class file.
The current execution from workspace root looks like this:
java -jar C:\intuit\karate-0.9.3.RC2.jar -cp .\target\test-classes -p 6868 -m .\src\test\java\mocks\api1_mock_test.feature
08:57:05.122 [main] INFO com.intuit.karate.Main - Karate version: 0.9.3.RC2
08:57:05.891 [main] ERROR com.intuit.karate - server-side background init failed - api1_mock_test.feature:4
Exception in thread "main" picocli.CommandLine$ExecutionException:
-unknown-:4 - org/springframework/amqp/rabbit/connection/ConnectionFactory
Thank you!
Thanks for asking this, and I think I've figured out a way to do this which opens up a lot of great possibilities. The solution is to use Java first-principles, and not use the -jar option. The Karate command-line-app (or CLI) class happens to be com.intuit.karate.Main. I'm going to provide a demo here of using SikuliX. First, the feature file test.feature:
Feature: sikuli test
Background:
* def Screen = Java.type('org.sikuli.script.Screen')
Scenario:
* def s = new Screen()
* def c = s.capture()
* c.getFile('.')
And with the karate.jar and sikulixapi.jar in the same folder on the command line, this works (for windows, use ; instead of : as the "path separator"):
java -cp karate.jar:sikulixapi.jar com.intuit.karate.Main test.feature
For those looking to customize the classpath for the Visual Studio Code "Karate Runner" extension, please refer this: https://github.com/intuit/karate/wiki/Karate-Robot-Windows-Install-Guide#change-command-line-settings
Also see: https://stackoverflow.com/a/58398958/143475
For those who really don't want to compile Java but need to use some JVM libraries, it is possible via pure JS, (but hard to troubleshoot and debug): https://stackoverflow.com/a/65035825/143475
I have written code to compress image in .py file and tried to compile using transcrypt to convert to JS file. During this process i got the below error(screen shot) But if i run the .py file separately using IDE ,it works fine & compress the image.
Code:
import PIL
from PIL import Image as pil
class FileUpload:
def Images (self,arg):
# Open the image
im = pil.open(arg)
# Now save it
im.save("img_compressed.jpg", format="JPEG", quality=90)
fileupload = FileUpload()
Error :
\python src\imgcompress>python -m transcrypt -b -m -n imageCompress.py
Transcrypt (TM) Python to JavaScript Small Sane Subset Transpiler Version 3.6.101
Copyright (C) Geatec Engineering. License: Apache 2.0
Error while compiling (offending file last):
File '/python src/imgcompress/imageCompress.py', line 1, at import of:
File '/python/lib/site-packages/PIL/__init__.py', line 14, namely:
Can't import module 'PIL'
Aborted
screen shot
The following JS library for example is suitable to compress images before uploading:
https://github.com/brunobar79/J-I-C
Any JS library can be used directly from Transcrypt, so there are many alternatives. Main point is: look for a JS rather than a Python lib. Just Google for
javascript image compression browser
Transcrypt was deliberately made to live in the JS ecosystem.
http://www.transcrypt.org/docs/html/what_why.html#the-ecosystem-different-batteries
To compress without using a library at all, see e.g.
How to compress an image via Javascript in the browser?
Note that you can embed any JS code unmodified with:
http://www.transcrypt.org/docs/html/special_facilities.html#inserting-literal-javascript-pragma-js-and-include
but this is rarely necessary, you can use the trick above directly from Transcrypt, just convert to Python syntax. All DOM functions are available.
Transcrypt cannot use C extension libraries, only pure-Python libraries. That's why they reimplemented part of the Numpy API as Numscrypt instead of just using Numpy.
There are some pure-Python libraries that have similar functionality to Pillow, like pymaging, but I don't know if any of them have the functionality, speed, or robustness you need; you'd have to try them out for yourself.
If you're not running it in the browser, it can also use Node.js packages, and there are Node packages for dealing with image files. I doubt any of them will be an exact drop-in replacement for Pillow, but if you just want basic functionality, it should be pretty easy to write a try/except that imports whichever is available and defines a couple wrappers.
If you are running in the browser… well, then you don't have access to the filesystem, which rules out a lot of PIL functionality off the bat… but on the other hand, you've got native image objects from the DOM.
Currently trying to get a Kotlin "Hello, World" to compile to JS via the command line. I've followed the tutorial:
https://kotlinlang.org/docs/tutorials/javascript/getting-started-command-line/command-line-library-js.html
I'm seeing the Javascript files being generated, but I'm missing the kotlin.js file that I would expect to see per:
https://kotlinlang.org/docs/tutorials/javascript/kotlin-to-javascript/kotlin-to-javascript.html
The first few lines of the generated JS files read:
if (typeof kotlin === 'undefined') {
throw new Error("Error loading module 'sample-library'. Its dependency
'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to
'sample-library'.");
}
so it's clear that the it's meant to be run with a file that instantiates kotlin. Any ideas why I'm not seeing it? I'm following the tutorial exactly as written. I'm using the latest version of the compiler from homebrew, which is 1.1.2.2
As described here, yes, you'll need to include kotlin.js before you can run your own Kotlin code. This file contains the Kotlin runtime and standard library.
If you're doing this from the command line, you can find kotlin.js in the lib folder of the compiler, inside kotlin-stdlib-js.jar (which you can just open as a regular .zip file).
I started using VS2013 to edit some of my Windows Scripting Host (WSH) scripts... but can't get intellisense for the WSH objects.
Any directive ( /// wsh.d )I can include to get this
Ok... found 2 ways...
My initial goal was to have AutoComplete/IntelliSense suport
when coding Javascript+WSH inside Visual Studio 2013CE...
Way#1
Found a definition file you can use with a .js at https://github.com/jsakamoto/WSH-vsdoc
just add -> /// <reference path = "<<path>>\WScript.d.ts" />
to your .js file
Way#2
A better alternative is to use a TypeScript file .ts...
also found a good a definition file
http://blogs.msdn.com/b/freik/archive/2012/10/19/goofing-around-with-typescript-amp-windows-script-host.aspx
just add -> /// <reference path = "__WScript.d.ts" /> to the .ts file
Associate the TypeScript .ts extension with CScript.exe
or if you prefer launch CScript this way: CScript /E:Jscript script.ts
This way you don't have to compile .ts to .js
Your .ts will run directly in the CScript/WScript engine...
In the meanwhile I hope MS will launch better support for WSH
inside VS
The only care you must have if using option 2 is to not use any
TypeScript code feature beyond plain javascript... do this and you
will be fine with good AutoComplete+IntelliSense
I want to run some custom batch code just before every build. In a VS<11/C# app I could set the pre-build events in the project settings. I can't find similar settings in a javascript metro VS11 solution.
Anyone know where it is, or if the option is gone (!) what kind of workaround I can do in its place?
You can use the BeforeBuild target in the Visual Studio .jsproj file to accomplish this:
<Target Name="BeforeBuild"></Target>
<Target Name="AfterBuild"></Target>
To get here:
Right-click your project in Visual Studio and choose Open Folder in Windows Explorer
In Explorer, right-click the .jsproj file and choose Open With... and choose an editor like Notepad
Scroll to the bottom of the file and you'll notice these two Target sections commented out
Uncomment the BeforeBuild target and add your custom step inside of it. You can use the element to execute a command line script; the same $ variables are available as in C# pre-build steps (e.g. $(ProjectDir)). You can do more than call command line scripts in a Target, but this is closest to what you would normally do with C# pre-build steps.
As an example, the following code would call a batch file named processFile.bat passing it a path to default.js in the project root and an output path to create a file named output.js in the project's output directory (e.g. /bin/Debug in Debug mode):
<Target Name="BeforeBuild">
<Exec Command="processFile.bat "$(ProjectDir)default.js" "$(OutDir)output.js"">
</Target>
Note: The " is on purpose inside of the Command arguments, this makes sure the two parameters are quoted when passed to processFile.bat and called via cmd.exe.