how to fix a simple error on xtext? - eclipse

this is my example to show you the problem I need to call two rules
generate umlDsl "http://www.xtext.org/example/umldsl/UmlDsl"
Model:
elements+=rule*
;
rule:
rul1 'and' rul2
;
rul1:
'rul1' action1=[uml::Action|FQN]
;
rul2:
'rul2' action2=[uml::Action|FQN]
;
FQN returns ecore::EString:
ID ("." ID)*
;
I have this error
Multiple markers at this line (rul1 'and' rul2)
An unassigned rule call is not allowed, when the 'current'
was already created.
Cannot change type twice within a rule
I want to know why I have this error and how to fix it please

These errors occurs because of your rule implementation of rule rule
rule:
rul1 'and' rul2
;
As I understand rule has two attributes, rul1 and rul2. But in your implementation rule does not have any attributes. To define rul1 and rul2 as attribuites you have assign these elements to an attribute. This could look like this:
rule:
rul1=rul1 'and' rul2=rul2
;
Have you looked into the Xtext documentation [1] to learn about the grammar language syntax and semantics?
The things you need to know for understanding your error are the following:
An attribute of a parser rule needs a name. To this name you assign a value, which is an other parser rules name. It is similar to assing values to a field in Java:
int i = 42;
A field declaration consists of the fields type (int) and the fields name (i) this normally is followd by the assignment operator (=) and the value (42). The attribute definiton of a parser rule follows this scheme:
RuleA: 'some syntax' attributeName=OtherRule 'more syntax';
OtherRule: 'other syntax' attribute=NextRule ... ;
...
A parser rule in Xtexts grammar language is like a Java class. RuleName corresponds to class ClassName. Then you can define some static syntax with 'keyword'. If any other rule should occur within any other rule, it can be understood as a field declaration. This rule is an attribute which is implemented like this:
attributeName=AnyRule
Where attributeName corresponds to the field name. But to an attribute the type of the value is assigned (AnyRule).
Btw. I strongly recommand that rule names should start with an Capital letter and attribute names should start with an lower case letter.
[1] https://www.eclipse.org/Xtext/documentation/301_grammarlanguage.html

Related

In PostgreSQL, which types can be cast with the type name first?

Reading the PostgreSQL docs, I see that you can cast a longish bit of text to xml like this:
SELECT xml '<long>long text, may span many lines</long>'
SELECT xml '...'
Curious, I found that I could do the same with JSON:
SELECT json '{"arg1":"val1", <more args spanning many lines>}'
(I couldn't find an official reference for this one. It just works!)
By contrast, this does not work:
SELECT float8 3.14159
I like this alternate syntax from a readability perspective. Now I'm looking for a reference listing which types may be specified up front like this. but I haven't found it yet.
Any pointers?
The documentation says:
A constant of an arbitrary type can be entered using any one of the following notations:
type 'string'
'string'::type
CAST ( 'string' AS type )
The string constant's text is passed to the input conversion routine for the type called type. The result is a constant of the indicated type. The explicit type cast can be omitted if there is no ambiguity as to the type the constant must be (for example, when it is assigned directly to a table column), in which case it is automatically coerced.
The form you are asking about is the first one.
So this can be used for all PostgreSQL types.
Note that the data must be specified as a string literal (in single or dollar quotes) when you use that syntax.

UIMA Ruta Check Feature of sub Annotation

Is it possible to make a rule to match the value of a FEATURE in an annotation that is a child of another Annotation?
Example:
Annotation Person
Annotation Doctor
Feature TYPE: xyz
something like Person.Doctor{FEATURE("TYPE","xyz")}
Also is it possible to create a rule that matches a FEATURE in an annotation that is PARTOF another annotation?
|-----------A1------------|
|-----A2-----| |---A3----|
Make a rule where
A3{FEATURE("X","1")} but also A3{PARTOF(A1)}
Thank you!
Assuming that there is a type Doctor and its parent type called Person which defined a feature kind of type uima.cas.String, you can simply write:
Doctor.kind=="xyz";
Doctor{Doctor.kind=="xyz"};
d:Doctor{d.kind=="xyz"};
Doctor<-{Person.kind=="xyz";};
Some short explanation of the label expression d: and the inlined rule as condition (<-{}). The label expression introduces a local annotation variable within the scope of the rule. In the above example d:Doctor matches on a annotation of the type Doctor and assigns it to a new variable called d. This variables can then be used in other parts of the rule in order to refer to this specific annotation. In the second rule, no label expression is used and the annotation is refered to by using the type (Doctor.kind). Here, the annotation is resolved anew in the context of the match of the rule, which could lead to a different one in case there are several annotations of the type Doctorwith the same offsets.
The inlined rule as condition works as a complex condition. The rule element Doctor matches only if the rule Person.kind=="xyz"; is able to match within the context/offsets/span of the matched Doctor annotation.
Concerning the second part of the question:
You cannot directly access the annotation which is used in a PARTOF condition because none is used actually. You need to match on the annotation in order to access its features. It depends on which annotation coveres which one, and which annotation should be checked for the feature value. Here are some examples:
a:A3{PARTOF(A1),a.x==1};
A1.x=="1"{CONTAINS(A3)};
A1<-{a:A3{a.x=="1"};};
DISCLAIMER: I am a developer of UIMA Ruta

How to put restrictions on Pattern of String in Yang Model

how can we design the string pattern if i want to allow special characters (##$%) also to be included in the value for Name.
For Ex. All the below ones are valid entries for Name
Name = aaa990ZX
Name = a##9980XS
Name = $$$$$$$$
Name = 00000000
typedef Name {
type string {
pattern [a-zA-Z0-9];
}
description
"Value " ;
}
YANG uses the XSD schema regular expression flavor to define such constraints. Simply define and expression such as:
pattern '[a-zA-Z0-9##$%]+';
It is recommended to use a single quote string to define a YANG pattern statement argument in order to avoid escape sequence problems.
The exact specification of acceptable regular expressions may be found here.
I suggest you read up on regular expressions and perhaps look for a tutorial on it.

How to test existence of properties on object

Given something like:
#props.field1.field2.field3
I want to test if field3 exists. So:
#props.field1.field2.field3?
But. If field2 does not exist on field1 then then above line produces an error.
But I want to avoid a bunch of nested tests:
if #props.field1
if #props.field2
if #props.field3
//do something
Is this possible?
From the fine manual:
The Existential Operator
[...]
The accessor variant of the existential operator ?. can be used to soak up null references in a chain of properties. Use it instead of the dot accessor . in cases where the base value may be null or undefined. If all of the properties exist then you'll get the expected result, if the chain is broken, undefined is returned instead of the TypeError that would be raised otherwise.
So you could say:
#props?.field1?.field2?.field3?
to ignore missing properties all the way down.
if #props.field1 && #props.field2 && #props.field3
If one of the properties does not exists the compiler will not test any of the following
Actually
if #props.field3 should do the job

functions and operator for user define type

I have built User Define Type with function_in and function_out.
CREATE OR REPLACE FUNCTION MyOwnType_in(cstring)
RETURNS MyOwnType
AS '/home/postgres/ENCRIPTION/MyOwnType/MyOwnType.so','MyOwnType_in'
LANGUAGE C IMMUTABLE STRICT;
CREATE OR REPLACE FUNCTION MyOwnType_out(MyOwnType)
RETURNS cstring
AS '/home/postgres/ENCRIPTION/MyOwnType/MyOwnType.so','MyOwnType_out'
LANGUAGE C IMMUTABLE STRICT;
As you can see each function_in receives cstring and function_out returns cstring.
The thing is function overloading and operator overriding on which I don't want to waste my time.
Is there any way to declare DEFAULT TYPE for my MyOwnType type which tells postgres that functions and operators with MyOwnTypearguments can parse and rewrite it into text?
The most you can do with your type is to mark it as a string type, with:
CREATE TYPE MyOwnType(
INPUT = MyOwnType_in,
OUTPUT = MyOwnType_out,
CATEGORY = 'S'
-- ...
);
The category parameter is especially useful when adding a user-defined type to an existing built-in category, such as the numeric or string types. However, it is also possible to create new entirely-user-defined type categories. Select any ASCII character other than an upper-case letter to name such a category ...
It may require additional CASTs, as #IgorRomanchenko suggested.
You need to CREATE CAST ... AS IMPLICIT from your datatype to text. This way your type will be automatically cast to text when a function/operator requires text.
Details here: http://www.postgresql.org/docs/current/static/sql-createcast.html