Rule output is empty array instead of object

32 views
Skip to first unread message

xedin....@gmail.com

unread,
Jan 20, 2013, 2:21:28 PM1/20/13
to pe...@googlegroups.com
Hi!

Maybe I am missing something, but here's a simple example.

Example 1 ============

pegjs:

start
= expr

expr
= { return {item: 'asd'}; }

--------

Output:
[]

Example 2 ============

pegjs:

start
= expr

expr
= { return {item: 0}; }

--------

Output:

{
"item": 0
}

Example 3 ============

pegjs:

start
= expr

expr
= { return {item: 123}; }

--------

Output:

[]

=====================

Only example 2 illustrates the behavour I expect. What's wrong with the others?
Any suggestions please?

xedin....@gmail.com

unread,
Jan 20, 2013, 2:40:11 PM1/20/13
to pe...@googlegroups.com, xedin....@gmail.com

Funnily enough, if you try to use another property name, it works:

Example 1 ============

pegjs:

start
= expr

expr
= { return {index: 123}; }

--------

Output:

{
"index": 123
}

=====================

Looks like the property name 'item' is reserved by PEGjs for some processing behind the scenes. Still, I would like an explanation. If I'm right, this should be documented.

David Majda

unread,
Mar 12, 2013, 3:33:04 PM3/12/13
to xedinu...@gmail.com, pegjs, xedin....@gmail.com
Hi,

2013/1/20 <xedin....@gmail.com>:
> On Sunday, January 20, 2013 8:21:28 PM UTC+1, xedin....@gmail.com wrote:
>> Hi!
>>
>> Maybe I am missing something, but here's a simple example.
>>
>> [...]
>>
>>
>> Only example 2 illustrates the behavour I expect. What's wrong with the others?
>> Any suggestions please?
>
> Funnily enough, if you try to use another property name, it works:
>
> [...]
>
> Looks like the property name 'item' is reserved by PEGjs for some processing behind the scenes. Still, I would like an explanation. If I'm right, this should be documented.

I investigated a bit. This is not a bug in PEG.js, but in the jsDump
library that the online version uses to serialize JavaScript objects.
I'll look into this more later, see the GitHub issue [1] I created so
that I don't forget.

Thanks for reporting this!

[1] https://github.com/dmajda/pegjs-website/issues/5

--
David Majda
Entropy fighter
http://majda.cz/
Reply all
Reply to author
Forward
0 new messages