I want to be able to create libraries with blocks in them, import the library in a separate file and then use the blocks from the library in a blockUse statement.
I have created the following grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Program:
(imports+=Import)*
(libraries+=Library)*
(customBlocks+= Block)*
(blockUses+= BlockUse)*
;
Import:
'import' importedNamespace=QualifiedNameWithWildcard
;
QualifiedNameWithWildcard:
QualifiedName '.*'?
;
QualifiedName:
ID ('.' ID)*
;
Library:
'Library' name=QualifiedName
(blocks+=Block)+
'EndLibrary'
;
Block:
'block' name=ID
;
BlockUse:
'show' block=[Block|QualifiedName]
;
My end goal is that I could create two files, one with a library, and one using blocks from that library like this:
File 1:
Library lib1
block block1
block block2
EndLibrary
File 2:
import lib1.*
show block1
I believe the bulk of my confusion comes from the meaning behind importedNamespace and using cross references
These are some of the examples I have already tried to follow:
http://www.eclipse.org/Xtext/documentation/102_domainmodelwalkthrough.html#add-imports
http://blog2.vorburger.ch/2013/05/xtext-dsl-with-epackage-namespace.html
https://blogs.itemis.com/en/in-five-minutes-to-transitive-imports-within-a-dsl-with-xtext
imported namespaces shall not be references. thus you either have to change this
Import:
'import' importedNamespace=QualifiedNameWithWildcard
;
or you need to adapt the calculation of the namespace resolvers e.g. in org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getImportedNamespace(EObject) and use the nodemodel to retrieve the import text there.
Make sure the project has Xtext Builder and Xtext Nature and Build Automatically is enabled and you did a clean build.
Related
I have 2 JAR files coming from an SDK that I have to use.
Generation problem
I succeeded in generating the first .pas file, but Java2OP fails to generate the second .pas I need, with the message
Access violation at address 0042AF4A dans the 'Java2OP.exe' module. Read at address 09D00000
Would this come from a common issue? There's no other hints about what causes the problem in the SDK .jar.
I'm using Java2OP located in C:\Program Files (x86)\Embarcadero\Studio\18.0\bin\converters\java2op, but I had to first use the solutions in Delphi 10.1 Berlin - Java2OP: class or interface expected before generating the 1st file.
Compilation problem
Anyway, I tried to generate a .hpp file from the generated .pas.
I don't know much about Delphi. Does the problem come from the SDK itself, or the generation of the .pas file?
1st issue solved
Java2OP included Androidapi.JNI.Java.Util
and not Androidapi.JNI.JavaUtil. I had to import Androidapi.JNI.JavaUtil myself, though it is present in the /Program Files(x86)/Embarcadero/... folders.
2nd issue
The same 4 compilation errors happen multiple times across the .pas file on parts using the word this.
Do I have to replace every use of this with self?
Errors
E2023 The function require a type of result : Line 4
E2147 The property 'this' doesn't exist in the base class : Line 5
E2029 ',' or ':' awaited but found 'read' identificator : Line 5
E2029 ',' or ':' awaited but found number : Line 5
[JavaSignature('com/hsm/barcode/DecoderConfigValues$SymbologyFlags')]
JDecoderConfigValues_SymbologyFlags = interface(JObject)
['{BCF30FD2-B650-433C-8A4E-8B638A508487}']
function _Getthis$0: JDecoderConfigValues; cdecl;
property this$0: JDecoderConfigValues read _Getthis$0;
end;
[JavaSignature('com/hsm/barcode/ExposureValues$ExposureSettingsMinMax')]
JExposureValues_ExposureSettingsMinMax = interface(JObject)
['{A576F85F-A021-475C-9741-06D92DBC205F}']
function _Getthis$0: JExposureValues; cdecl;
property this$0: JExposureValues read _Getthis$0;
end;
In my Skylark rule, I am looking through all my deps - some of them are maven_jar instances defined in my WORKSPACE file. For those, I would like to access the value of maven_jar.artifact, but as far as I can tell it isn't available. Is it possible to get at that value?
For example, if my WORKSPACE has:
maven_jar(
name = "com_google_guava_guava",
artifact = "com.google.guava:guava:20.0",
)
And my BUILD file has something like this:
my_rule(
name = "foo",
deps = ["#com_google_guava_guava//jar"]
)
In the implementation of my_rule, I would like to get the value com.google.guava:guava:20.0.
I think you'll need to file a feature request for this:
https://github.com/bazelbuild/bazel/issues/new
The instance of the maven_jar rule in the workspace file isn't available to the rules in BUILD files, only the rules which the workspace rule generates are (i.e., #com_google_guava_guava//jar). Off the top of my head, maven_jar would have to generate a rule into the jar's workspace which has an attribute with the value of artifact, and that rule would need to create a provider containing that value for other rules to consume.
(There does happen to be META-INF/maven/com.google.guava/guava/pom.xml inside the jar, which seems to have the information you want, but I don't know if you can rely on that for all jars from maven, but either way, the contents of the jar aren't available at analysis time (within the rule implementation))
I have a Java app that has a class at this address, inside a standard Maven layout:
src/main/java/com/ollio/nlp/Transformer.java
The class and method that I want looks like this:
package com.ollio.nlp;
public class Transformer {
public String transform(String JSONInput) {
I store the jar artifact locally in my Clojure app at this address:
maven_repository/local/nlp/1.0-SNAPSHOT/nlp-1.0-SNAPSHOT.jar
I have tried a dozen variations to import it into my Clojure app, such as:
(:import
[com.ollio.nlp.Transformer])
But I keep getting the error "No such namespace".
What is the correct way to import this?
EDITED:
Here is how I currently try to do the import statement:
(ns slick.query
(:import
[nlp.*])
I also tried:
(ns slick.query
(:import
[com.ollio.nlp.*])
I tried a few other variations.
The project.clj file looks like this:
(defproject slick "0.1"
:description "slick is an API for other ollio services, such as our mobile app."
:dependencies [[org.clojure/clojure "1.6.0"]
[com.taoensso/timbre "3.2.1"]
[dire "0.5.1"]
[slingshot "0.10.3"]
[ring "1.4.0-RC1"]
[clj-time "0.6.0"]
[org.clojure/data.json "0.2.5"]
[compojure "1.3.4"]
[com.novemberain/monger "2.0.1"]
[org.clojure/tools.namespace "0.2.4"]
[manifold "0.1.0"]
[me.raynes/fs "1.4.4"]
[org.clojure/core.incubator "0.1.3"]
[clj-stacktrace "0.2.7"]
[overtone/at-at "1.2.0"]
[ring/ring-json "0.3.1"]
[clj-http "1.1.2"]
[org.clojure/core.cache "0.6.4"]
[cheshire "5.5.0"]
[org.clojure/core.match "0.3.0-alpha4"]
[local/nlp "1.0-SNAPSHOT"]]
:repositories {"local" ~(str (.toURI (java.io.File. "maven_repository")))}
:disable-implicit-clean true
:source-paths ["src/clojure"]
:java-source-paths ["src/java"]
:main slick.core
:aot :all
:jvm-opts ["-Xms100m" "-Xmx1000m" "-XX:-UseCompressedOops"])
If you are mixing java and clojure source code in one project, you should first review the lein docs: https://github.com/technomancy/leiningen/blob/master/doc/MIXED_PROJECTS.md
Also, if you posted your project.clj and the layout of your java/clojure sources, it would be easier to spot what is missing.
You probably want to change the last period in your :import statement into a space:
(ns mynamespace
(:import [com.ollio.nlp Transformer]))
(EDIT: You can't use wildcards here. Every class that in com.ollio.nlp must be listed explicitly, separated by spaces.) That will allow you to use Transformer unqualified:
(.transform (Transformer. <add constructor args here>) my-json-input)
As #noisesmith said, the :import statement should be part of an ns declaration.
There's also a good chance that there are problems with the way that the project is set up. You've given no indication that that is likely, but it often happens when one is starting to use Java interop, I believe. (It happened to me, in any event.) So #AlanThompson's advice may be relevant.
You an also simply remove the :import statement, and use the Java class name in fully qualified form, e.g.:
(.transform (com.ollio.nlp.Transformer. <add constructor args here>) my-json-input)
If you get an error when you do that, then there's probably a problem with the setup (unless you're using the class incorrectly).
(I'm not sure how helpful any of this. Alan Thompson's answer is probably the appropriate one.)
I am working on a DSL wherein I am supposed to call Java Functions I have written. How can they be called in XText Grammar definition rules ?
Example
Sample.xtext
Data:
'Data'':'
(objectRules += ObjectRule)+ //Call to Java Function here
;
I am writng the grammar and I want to invoke Java Function to perform further processing like pasting a block of code when the Rule is encountered.
Please refer to the documentation on Xbase if you want to use Java from your Xtext languages.
The pattern would be something like this:
grammar org.acme.MyDsl with org.eclipse.xtext.xbase.Xbase
generate ..
MyConcept:
operation=ID '(' ')' body = XBlockExpression
;
This would allow things like
myOperation() {
System.out.println("")
}
How to distribute expressions in other EPL files?
I tried but there are two problems need to see.
1. Any EPL file cannot contain only 'Expression'.('Unexpected end' error)
2. Accessing expression defined in another EPL file, gives 'not found' error.
Here is my attempt:
//epl1.epl
module eplTest;
expression twoPI
{
3.141 * 2
}
//epl2.epl
module eplTestmain;
uses SampleEvent;
uses eplTest;
select twoPI() from SampleEvent;
I am using netbeans.
It will be also useful if I get how to create single row function in epl?
there is no "create expression" syntax in Esper EPL currently, expressions are statement-local and not currently globabaly declarable