Skip to main content



      Home
Home » Modeling » TMF (Xtext) » syntatic predicates in Xtext 2.0
syntatic predicates in Xtext 2.0 [message #649539] Wed, 19 January 2011 10:53 Go to next message
Eclipse UserFriend
Noticed the remark "syntatic predicates (partly implemented in Xtext
2.0)" by jan.koehnlein@itemis.de in another thread.

This looks very promising and may help me remove some of the kludges I
have in the grammar I am working on.

Is there some info somewhere - bugzilla - ? that describes what this
partial syntactic predicate support consists of?

- henrik
Re: syntatic predicates in Xtext 2.0 [message #649582 is a reply to message #649539] Wed, 19 January 2011 14:36 Go to previous messageGo to next message
Eclipse UserFriend
Hi Henrik,

taken from commit message
http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/commit/?i d=1aef0084ea6a83a98b9d91c02ec967e5c5a9fdf8

Predicates can be defined in the Xtext grammar by means of the '=>'
keyword that prefixes the actual value that should be parsed, e.g.

IfExpression:
'if' '(' condition=Expression ')'
then=Expression
( =>'else' else=Expression )?;

will guide the parser to assign parse the 'else' eager and thereby
ensure that it will be part of the innermost if-expression.

Does that help?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 19.01.11 16:53, schrieb Henrik Lindberg:
> Noticed the remark "syntatic predicates (partly implemented in Xtext
> 2.0)" by jan.koehnlein@itemis.de in another thread.
>
> This looks very promising and may help me remove some of the kludges I
> have in the grammar I am working on.
>
> Is there some info somewhere - bugzilla - ? that describes what this
> partial syntactic predicate support consists of?
>
> - henrik
Re: syntatic predicates in Xtext 2.0 [message #649641 is a reply to message #649582] Wed, 19 January 2011 21:30 Go to previous messageGo to next message
Eclipse UserFriend
Looks promising!
Is it possible to have => RuleCall ?

In my case the 'else' is something like:
ElseRule : LOWER_E LOWER_L LOWER_S LOWER_E ;
terminal LOWER_E : 'e' ;
// etc

Can the result be assigned? i.e. if I want the equivalence of op =
'else' as well as direct the parser.

- henrik

On 1/19/11 8:36 PM, Sebastian Zarnekow wrote:
> Hi Henrik,
>
> taken from commit message
> http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/commit/?i d=1aef0084ea6a83a98b9d91c02ec967e5c5a9fdf8
>
>
> Predicates can be defined in the Xtext grammar by means of the '=>'
> keyword that prefixes the actual value that should be parsed, e.g.
>
> IfExpression:
> 'if' '(' condition=Expression ')'
> then=Expression
> ( =>'else' else=Expression )?;
>
> will guide the parser to assign parse the 'else' eager and thereby
> ensure that it will be part of the innermost if-expression.
>
> Does that help?
>
> Regards,
> Sebastian
Re: syntatic predicates in Xtext 2.0 [message #649672 is a reply to message #649641] Thu, 20 January 2011 03:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi Henrik,

yes, =>RuleCall is possible and =>name=ID as well as =>('else' foo=Bar
'zonk'|'baz'), too.
We do currently not support predicates in terminal rules and what will
never be possible is to use unordered groups as predicates.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 20.01.11 03:30, schrieb Henrik Lindberg:
> Looks promising!
> Is it possible to have => RuleCall ?
>
> In my case the 'else' is something like:
> ElseRule : LOWER_E LOWER_L LOWER_S LOWER_E ;
> terminal LOWER_E : 'e' ;
> // etc
>
> Can the result be assigned? i.e. if I want the equivalence of op =
> 'else' as well as direct the parser.
>
> - henrik
>
> On 1/19/11 8:36 PM, Sebastian Zarnekow wrote:
>> Hi Henrik,
>>
>> taken from commit message
>> http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/commit/?i d=1aef0084ea6a83a98b9d91c02ec967e5c5a9fdf8
>>
>>
>>
>> Predicates can be defined in the Xtext grammar by means of the '=>'
>> keyword that prefixes the actual value that should be parsed, e.g.
>>
>> IfExpression:
>> 'if' '(' condition=Expression ')'
>> then=Expression
>> ( =>'else' else=Expression )?;
>>
>> will guide the parser to assign parse the 'else' eager and thereby
>> ensure that it will be part of the innermost if-expression.
>>
>> Does that help?
>>
>> Regards,
>> Sebastian
>
Re: syntatic predicates in Xtext 2.0 [message #649888 is a reply to message #649672] Thu, 20 January 2011 15:51 Go to previous messageGo to next message
Eclipse UserFriend
Are predicates for the lexer planned? I have a lexer rule that could use it.
Re: syntatic predicates in Xtext 2.0 [message #649911 is a reply to message #649888] Thu, 20 January 2011 17:25 Go to previous messageGo to next message
Eclipse UserFriend
I forgot to ask earlier, but I think lexer fragments are also in 2.0,
and I assume that those can be used with semantic predicates (like any
rule call) - if that is the case then a data rule with semantic
predicate and a lexer fragment would probably work.

- henrik

On 1/20/11 9:51 PM, Mark Christiaens wrote:
> Are predicates for the lexer planned? I have a lexer rule that could use
> it.
Re: syntatic predicates in Xtext 2.0 [message #649954 is a reply to message #649911] Fri, 21 January 2011 02:56 Go to previous messageGo to next message
Eclipse UserFriend
Henrik, Marc,

they are currently not planned since we never faced the need for them.
Please file a feature request with a sample terminal rule that cannot be
expressed with the currently available abstractions.

Thanks,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 20.01.11 23:25, schrieb Henrik Lindberg:
> I forgot to ask earlier, but I think lexer fragments are also in 2.0,
> and I assume that those can be used with semantic predicates (like any
> rule call) - if that is the case then a data rule with semantic
> predicate and a lexer fragment would probably work.
>
> - henrik
>
> On 1/20/11 9:51 PM, Mark Christiaens wrote:
>> Are predicates for the lexer planned? I have a lexer rule that could use
>> it.
>
Re: syntatic predicates in Xtext 2.0 [message #650162 is a reply to message #649954] Fri, 21 January 2011 21:40 Go to previous messageGo to next message
Eclipse UserFriend
The problem I am facing is that terminals allow specification of NOT,
but data rules do not, and since my "terminals" are context sensitive I
have to use data rules. If I could instead use a fragment and directly
use it in a datatype rule, it would save me from having long lists
specifying the various sets of valid characters. (Long lists which I
have a strong suspicion is the source of some of the performance
problems I am having.

So, fragments seems perfect to overcome this problem.

As an example, let's say that SL_COMMENT is context sensitive.
It is easily specified as a terminal.
terminal SL_COMMENT '#' .* ('\r'? '\n') ;

Doing the same with a data rule is possible, but requires listing every
possible source character in the language (which is what I did). Here is
the start of that:

SL_COMMENT
: HASH
( ANY_DIGIT
| ANY_LETTER
| PUNCTUATION
| SP | TAB | NBSP
)*
CR? // CR optional depending on file format
NL // NL optional because file may end with a SL comment
;

If I understood fragments correctly, I would be able to provide
something like
CommentedStatement : statement SL_COMMENT? ;
fragment SL_COMMENT '#' .* ('\r'? '\n') ;

Please let me know if there is some other way to achieve what I want, or
if I misunderstood the usefulness of fragments - if not I will post an
enhancement request. (I agree that they are not terribly useful if they
can only be used inside terminals or other fragments).

Another alternative is naturally to support NOT and ANY (.) in datatype
rules.

Support for semantic predicates, the above, and the ability to use
'\uxxxx' would make my life a lot easier.

Regards
- henrik

On 1/21/11 8:56 AM, Sebastian Zarnekow wrote:
> Henrik, Marc,
>
> they are currently not planned since we never faced the need for them.
> Please file a feature request with a sample terminal rule that cannot be
> expressed with the currently available abstractions.
>
> Thanks,
> Sebastian
Re: syntatic predicates in Xtext 2.0 [message #650359 is a reply to message #650162] Mon, 24 January 2011 10:36 Go to previous messageGo to next message
Eclipse UserFriend
Added: https://bugs.eclipse.org/bugs/show_bug.cgi?id=335203
as Sebastian suggested.
- henrik

On 1/22/11 3:40 AM, Henrik Lindberg wrote:
> The problem I am facing is that terminals allow specification of NOT,
> but data rules do not, and since my "terminals" are context sensitive I
> have to use data rules. If I could instead use a fragment and directly
> use it in a datatype rule, it would save me from having long lists
> specifying the various sets of valid characters. (Long lists which I
> have a strong suspicion is the source of some of the performance
> problems I am having.
>
> So, fragments seems perfect to overcome this problem.
>
> As an example, let's say that SL_COMMENT is context sensitive.
> It is easily specified as a terminal.
> terminal SL_COMMENT '#' .* ('\r'? '\n') ;
>
> Doing the same with a data rule is possible, but requires listing every
> possible source character in the language (which is what I did). Here is
> the start of that:
>
> SL_COMMENT
> : HASH
> ( ANY_DIGIT
> | ANY_LETTER
> | PUNCTUATION
> | SP | TAB | NBSP
> )*
> CR? // CR optional depending on file format
> NL // NL optional because file may end with a SL comment
> ;
>
> If I understood fragments correctly, I would be able to provide
> something like
> CommentedStatement : statement SL_COMMENT? ;
> fragment SL_COMMENT '#' .* ('\r'? '\n') ;
>
> Please let me know if there is some other way to achieve what I want, or
> if I misunderstood the usefulness of fragments - if not I will post an
> enhancement request. (I agree that they are not terribly useful if they
> can only be used inside terminals or other fragments).
>
> Another alternative is naturally to support NOT and ANY (.) in datatype
> rules.
>
> Support for semantic predicates, the above, and the ability to use
> '\uxxxx' would make my life a lot easier.
>
> Regards
> - henrik
>
> On 1/21/11 8:56 AM, Sebastian Zarnekow wrote:
>> Henrik, Marc,
>>
>> they are currently not planned since we never faced the need for them.
>> Please file a feature request with a sample terminal rule that cannot be
>> expressed with the currently available abstractions.
>>
>> Thanks,
>> Sebastian
>
Re: syntatic predicates in Xtext 2.0 [message #650477 is a reply to message #650162] Tue, 25 January 2011 03:11 Go to previous message
Eclipse UserFriend
Hi Henrik,

as you already noticed, terminal fragments are already available. And
the good news is: unicode escapes are possible, too :-)

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 22.01.11 03:40, schrieb Henrik Lindberg:
> The problem I am facing is that terminals allow specification of NOT,
> but data rules do not, and since my "terminals" are context sensitive I
> have to use data rules. If I could instead use a fragment and directly
> use it in a datatype rule, it would save me from having long lists
> specifying the various sets of valid characters. (Long lists which I
> have a strong suspicion is the source of some of the performance
> problems I am having.
>
> So, fragments seems perfect to overcome this problem.
>
> As an example, let's say that SL_COMMENT is context sensitive.
> It is easily specified as a terminal.
> terminal SL_COMMENT '#' .* ('\r'? '\n') ;
>
> Doing the same with a data rule is possible, but requires listing every
> possible source character in the language (which is what I did). Here is
> the start of that:
>
> SL_COMMENT
> : HASH
> ( ANY_DIGIT
> | ANY_LETTER
> | PUNCTUATION
> | SP | TAB | NBSP
> )*
> CR? // CR optional depending on file format
> NL // NL optional because file may end with a SL comment
> ;
>
> If I understood fragments correctly, I would be able to provide
> something like
> CommentedStatement : statement SL_COMMENT? ;
> fragment SL_COMMENT '#' .* ('\r'? '\n') ;
>
> Please let me know if there is some other way to achieve what I want, or
> if I misunderstood the usefulness of fragments - if not I will post an
> enhancement request. (I agree that they are not terribly useful if they
> can only be used inside terminals or other fragments).
>
> Another alternative is naturally to support NOT and ANY (.) in datatype
> rules.
>
> Support for semantic predicates, the above, and the ability to use
> '\uxxxx' would make my life a lot easier.
>
> Regards
> - henrik
>
> On 1/21/11 8:56 AM, Sebastian Zarnekow wrote:
>> Henrik, Marc,
>>
>> they are currently not planned since we never faced the need for them.
>> Please file a feature request with a sample terminal rule that cannot be
>> expressed with the currently available abstractions.
>>
>> Thanks,
>> Sebastian
>
Previous Topic:Two different DSL and the workflow
Next Topic:derived properties
Goto Forum:
  


Current Time: Mon Jul 07 21:04:00 EDT 2025

Powered by FUDForum. Page generated in 0.04052 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top