Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » terminals gets my knickers in a twist every time...
terminals gets my knickers in a twist every time... [message #632388] Tue, 12 October 2010 17:44 Go to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
:)
With this specification of terminals:

terminal TEXTSTART : '«' !('»'|'‹')* '‹';
terminal TEXTMID : '›' !('»'|'‹')* '‹';
terminal TEXTEND : '›' !('»'|'‹')* '»';

terminal TEXT : '«' !('»'|'‹'|'›')* '»';

I manage to get a working switch between template and non template
parsing. Input could look something like:

var a = "Mary";
var b = "this morning";
«Hello ‹ a ›, how are you ‹ b ›?»

If I however switch to using two characters '<%' and '%>' instead of the
'UTF-8' characters '‹' and '›' (sort of "lower-case '«»'" ;) i.e.:

terminal TEXTSTART : '«' !('»'|'<%')* '<%';
terminal TEXTMID : '%>' !('»'|'<%')* '<%';
terminal TEXTEND : '%>' !('»'|'<%')* '»';

terminal TEXT : '«' !('»'|'<%'|'%>')* '»';

(and not changing anything else)

....then I get the following print out:

error(204):
.../org.eclipse.b3.beelang/src-gen/org/eclipse/b3/parser/ant lr/internal/InternalBeeLang.g:24002:39:
duplicate token type '%>' when collapsing subrule into set

What is it I am missing? or is this a bug? (which it almost never is
when things are not working as expected with terminals :)

What I really would like to have is '«{' and '}»' but I was afraid to
try this if I could not get the '%>' to work first

Any terminal [sic] help much appreciated :)

First working solution wins an ESE beer ...
Regards
- henrik
Re: terminals gets my knickers in a twist every time... [message #632429 is a reply to message #632388] Tue, 12 October 2010 20:41 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Henrik,

StringLiteral:
values+=TEXT
| values+=TEXTSTART values+=ID (values+=TEXTMID values+=ID)*
values+=TEXTEND
;

terminal TEXT : '[' ( (("%" !'>')|("<" !'%'))|!('%'|"<"|"]"))* ']';
terminal TEXTSTART : '[' ( (("%" !'>')|("<" !'%'))|!('%'|"<"|"]"))* '<' '%';
terminal TEXTEND : '%' '>' ( (("%" !'>')|("<" !'%'))|!('%'|"<"|"]"))* ']';
terminal TEXTMID : '%' '>' ( (("%" !'>')|("<" !'%'))|!('%'|"<"|"]"))*
'<' '%';

parses:

[ content <% ID %> content <% ID %> content ];

[<% /* */ ID %><% /* */ ID %>];

[ content <% ID %> content /* */ ];

[ <% ID %> ];

[ ID ];

[ % % % > < arbitrary content ];

[ % ];

[ > ];

[ < ];

[];

See you @ ESE ;-)

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


Am 12.10.10 19:44, schrieb Henrik Lindberg:
> :)
> With this specification of terminals:
>
> terminal TEXTSTART : '«' !('»'|'‹')* '‹';
> terminal TEXTMID : '›' !('»'|'‹')* '‹';
> terminal TEXTEND : '›' !('»'|'‹')* '»';
>
> terminal TEXT : '«' !('»'|'‹'|'›')* '»';
>
> I manage to get a working switch between template and non template
> parsing. Input could look something like:
>
> var a = "Mary";
> var b = "this morning";
> «Hello ‹ a ›, how are you ‹ b ›?»
>
> If I however switch to using two characters '<%' and '%>' instead of the
> 'UTF-8' characters '‹' and '›' (sort of "lower-case '«»'" ;) i.e.:
>
> terminal TEXTSTART : '«' !('»'|'<%')* '<%';
> terminal TEXTMID : '%>' !('»'|'<%')* '<%';
> terminal TEXTEND : '%>' !('»'|'<%')* '»';
>
> terminal TEXT : '«' !('»'|'<%'|'%>')* '»';
>
> (and not changing anything else)
>
> ...then I get the following print out:
>
> error(204):
> ../org.eclipse.b3.beelang/src-gen/org/eclipse/b3/parser/antl r/internal/InternalBeeLang.g:24002:39:
> duplicate token type '%>' when collapsing subrule into set
>
> What is it I am missing? or is this a bug? (which it almost never is
> when things are not working as expected with terminals :)
>
> What I really would like to have is '«{' and '}»' but I was afraid to
> try this if I could not get the '%>' to work first
>
> Any terminal [sic] help much appreciated :)
>
> First working solution wins an ESE beer ...
> Regards
> - henrik
>
>
>
Re: terminals gets my knickers in a twist every time... [message #632446 is a reply to message #632429] Wed, 13 October 2010 00:35 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
WOOT !

(Hint «{=expr}» is an "echo", while «{expr}» just has side effects, but
can include printing of templates inline).

--- testingIfSebastianGetsABeer.b3

« This is a documentation clause with trimmed whitespace and
processing of \t as in Java String. It should have different
appearance in the editor than a Template.
Testing { }«} «
»
function testIfSebastianGetsBeer :
testIfConstructorGetsBeer("Sebastian", 2).print() ;

function testIfSomeoneGetsBeer(String someone, Integer pints) {
if pints < 0 then throw "no beer return" endif;
«The constructor of my terminal rules' logic, «{=someone}», is
hereby granted «{=
switch pints
case 0 : "no"
default : pints
endswitch
}» «{=
switch pints
case 0 : "beer"
case 1 : "pint"
default : "pints"
endswitch
}» since this template with stuff like { }«} parses ok «{="\u263A"}»!
Look out for the lo«{(0..pints).do(x|«o«{=x}»o».print()) }»op»;
}

function testing () {
var a = 1;

« content «{ a }» content «{ a }» content »;

««{ /* */ a }»«{ /* */ a }»»;

« content «{ a }» content /* */ »;

« «{ a }» »;

// ««{}»»; // uncomment for correct parse error (no expression)
// ««{=}»»; // uncomment for correct parse error (no expression)

« a »;

« } } } { { { « arbitrary content »;

« } »;

// « » »; // uncomment for correct parse error (end end)

« « »;

«»;
}

Now I should do "9 green bottles hanging on a wall" HTML template as an
exercise...

See you @ ESE ;-)

Regards,
Sebastian

On 10/12/10 10:41 PM, Sebastian Zarnekow wrote:
> Hi Henrik,
>
> StringLiteral:
> values+=TEXT
> | values+=TEXTSTART values+=ID (values+=TEXTMID values+=ID)*
> values+=TEXTEND
> ;
>
> terminal TEXT : '[' ( (("%" !'>')|("<" !'%'))|!('%'|"<"|"]"))* ']';
> terminal TEXTSTART : '[' ( (("%" !'>')|("<" !'%'))|!('%'|"<"|"]"))* '<'
> '%';
> terminal TEXTEND : '%' '>' ( (("%" !'>')|("<" !'%'))|!('%'|"<"|"]"))* ']';
> terminal TEXTMID : '%' '>' ( (("%" !'>')|("<" !'%'))|!('%'|"<"|"]"))*
> '<' '%';
>
> parses:
>
> [ content <% ID %> content <% ID %> content ];
>
> [<% /* */ ID %><% /* */ ID %>];
>
> [ content <% ID %> content /* */ ];
>
> [ <% ID %> ];
>
> [ ID ];
>
> [ % % % > < arbitrary content ];
>
> [ % ];
>
> [ > ];
>
> [ < ];
>
> [];
>
> See you @ ESE ;-)
>
> Regards,
> Sebastian
Previous Topic:Xtext and macro expansion
Next Topic:[Xtext] Use Xtend in generator project -- how to define metamodels
Goto Forum:
  


Current Time: Wed Apr 24 15:30:01 GMT 2024

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

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

Back to the top