Hello,
I try to return an object within the action part and of course it
didn't work because the curly brace literals are reserved to delimit
the action block.
So how would you do this?
---------------
%start test
%%
test
: STRING { return {str: $1}; }
;
-------------------------------------------
Thanks!
-- Philippe
When you need to use curly braces in your action, use double curly
braces instead of single for your action
:STRING {{ return {str:$1}; }}
-----Original Message-----
From: jison@librelist.com [mailto:jison@librelist.com] On Behalf Of
Philippe Rathe
Sent: Wednesday, November 10, 2010 4:25 PM
To: jison@librelist.com
Subject: [jison] How to return an object literal?
Hello,
I try to return an object within the action part and of course it didn't
work because the curly brace literals are reserved to delimit the action
block.
So how would you do this?
---------------
%start test
%%
test
: STRING { return {str: $1}; }
;
-------------------------------------------
Thanks!
-- Philippe
I was expecting using double start and end curly braces in the action
of the lexer would work.
Using {{ if (...) {...} else {...} }} only works in the jison files,
not in the jisonlex files.
I have repeated my if statement twice to avoid using curly braces
insdie the action so it is ok.
Could it be something to support?
-- Philippe
On 10-Nov-10, at 7:27 PM, Nathan Stults wrote:
> When you need to use curly braces in your action, use double curly
> braces instead of single for your action
>
> :STRING {{ return {str:$1}; }}
>
> -----Original Message-----
> From: jison@librelist.com [mailto:jison@librelist.com] On Behalf Of
> Philippe Rathe
> Sent: Wednesday, November 10, 2010 4:25 PM
> To: jison@librelist.com
> Subject: [jison] How to return an object literal?
>
> Hello,
>
> I try to return an object within the action part and of course it
> didn't
> work because the curly brace literals are reserved to delimit the
> action
> block.
>
> So how would you do this?
>
> ---------------
> %start test
>
> %%
>
> test
> : STRING { return {str: $1}; }
> ;
> -------------------------------------------
>
> Thanks!
>
> -- Philippe
>
>
>
>
Hi Philippe,
in Jisonlex you can use the percent character for escaping curly braces:
:STRING %{ return {str:$1}; %}
This works in both Jison and Jisonlex files/parts.
Best,
Johannes
Am 11.11.2010 um 22:33 schrieb Philippe Rathe:
> I was expecting using double start and end curly braces in the action
> of the lexer would work.
>
> Using {{ if (...) {...} else {...} }} only works in the jison files,
> not in the jisonlex files.
>
> I have repeated my if statement twice to avoid using curly braces
> insdie the action so it is ok.
> Could it be something to support?
>
> -- Philippe
>
>
>
>
> On 10-Nov-10, at 7:27 PM, Nathan Stults wrote:
>
>> When you need to use curly braces in your action, use double curly
>> braces instead of single for your action
>>
>> :STRING {{ return {str:$1}; }}
>>
>> -----Original Message-----
>> From: jison@librelist.com [mailto:jison@librelist.com] On Behalf Of
>> Philippe Rathe
>> Sent: Wednesday, November 10, 2010 4:25 PM
>> To: jison@librelist.com
>> Subject: [jison] How to return an object literal?
>>
>> Hello,
>>
>> I try to return an object within the action part and of course it
>> didn't
>> work because the curly brace literals are reserved to delimit the
>> action
>> block.
>>
>> So how would you do this?
>>
>> ---------------
>> %start test
>>
>> %%
>>
>> test
>> : STRING { return {str: $1}; }
>> ;
>> -------------------------------------------
>>
>> Thanks!
>>
>> -- Philippe
>>
>>
>>
>>
>
Thanks Johannes! Le 10-11-13 à 04:51, Johannes Emerich a écrit : > Hi Philippe, > > in Jisonlex you can use the percent character for escaping curly > braces: > > :STRING %{ return {str:$1}; %} > > This works in both Jison and Jisonlex files/parts. > > Best, > Johannes > > Am 11.11.2010 um 22:33 schrieb Philippe Rathe: > >> I was expecting using double start and end curly braces in the >> action >> of the lexer would work. >> >> Using {{ if (...) {...} else {...} }} only works in the jison files, >> not in the jisonlex files. >> >> I have repeated my if statement twice to avoid using curly braces >> insdie the action so it is ok. >> Could it be something to support? >> >> -- Philippe >> >> >> >> >> On 10-Nov-10, at 7:27 PM, Nathan Stults wrote: >> >>> When you need to use curly braces in your action, use double curly >>> braces instead of single for your action >>> >>> :STRING {{ return {str:$1}; }} >>> >>> -----Original Message----- >>> From: jison@librelist.com [mailto:jison@librelist.com] On Behalf Of >>> Philippe Rathe >>> Sent: Wednesday, November 10, 2010 4:25 PM >>> To: jison@librelist.com >>> Subject: [jison] How to return an object literal? >>> >>> Hello, >>> >>> I try to return an object within the action part and of course it >>> didn't >>> work because the curly brace literals are reserved to delimit the >>> action >>> block. >>> >>> So how would you do this? >>> >>> --------------- >>> %start test >>> >>> %% >>> >>> test >>> : STRING { return {str: $1}; } >>> ; >>> ------------------------------------------- >>> >>> Thanks! >>> >>> -- Philippe >>> >>> >>> >>> >> >
Thanks! -- Philippe On 10-Nov-10, at 7:27 PM, Nathan Stults wrote: > When you need to use curly braces in your action, use double curly > braces instead of single for your action > > :STRING {{ return {str:$1}; }} > > -----Original Message----- > From: jison@librelist.com [mailto:jison@librelist.com] On Behalf Of > Philippe Rathe > Sent: Wednesday, November 10, 2010 4:25 PM > To: jison@librelist.com > Subject: [jison] How to return an object literal? > > Hello, > > I try to return an object within the action part and of course it > didn't > work because the curly brace literals are reserved to delimit the > action > block. > > So how would you do this? > > --------------- > %start test > > %% > > test > : STRING { return {str: $1}; } > ; > ------------------------------------------- > > Thanks! > > -- Philippe > > > >