librelist archives

« back to archive

How to return an object literal?

How to return an object literal?

From:
Philippe Rathe
Date:
2010-11-11 @ 00:25
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



Re: [jison] How to return an object literal?

From:
Nathan Stults
Date:
2010-11-11 @ 00:27
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



Re: [jison] How to return an object literal?

From:
Philippe Rathe
Date:
2010-11-11 @ 21:33
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
>
>
>
>

Re: [jison] How to return an object literal?

From:
Johannes Emerich
Date:
2010-11-13 @ 09:51
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
>> 
>> 
>> 
>> 
> 

Re: [jison] How to return an object literal?

From:
prathe
Date:
2010-11-13 @ 13:13
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
>>>
>>>
>>>
>>>
>>
>

Re: [jison] How to return an object literal?

From:
Philippe Rathe
Date:
2010-11-11 @ 00:29
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
>
>
>
>