Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated AST label upon nested ·ls #20

Open
msjyoo opened this issue Feb 6, 2016 · 4 comments
Open

Duplicated AST label upon nested ·ls #20

msjyoo opened this issue Feb 6, 2016 · 4 comments
Labels

Comments

@msjyoo
Copy link

msjyoo commented Feb 6, 2016

Hello,

When I attempt to use a nested ·ls(), I get a "Duplicated AST label ·array". What does that error mean and is ·ls supposed to be allowed to be nested? Or am I understanding it wrong?

·ls
(
    ·ls
    (
        ·token(T_VARIABLE)·array
        ,
        ·token(':')
    )
    ·arrays
    ,
    ·token(',')
)
·collection
@marcioAlmada
Copy link
Owner

This means an attempt to overwrite an index when your AST is under construction. What are you aiming to parse?

@msjyoo
Copy link
Author

msjyoo commented Feb 6, 2016

I'm trying to macro the individual elements of an array. So my first line of thought was that there should be an ·ls for the array itself, and another ·ls to parse the structures of a single element.

e.g. [ , , ]
The macro provided in OP would be e.g. [ $a : $b, $c : $d, $e : $f ]

Also, may I ask what ·ls stands for?
Oh, and also how would I specify an array token? e.g. either [] or array() instead of hardcoding [] which would exclude array()

@marcioAlmada
Copy link
Owner

So you want a macro that allows an alternative syntax for arrays, like [ 'key' : $value ]. My bet is that once you match the array you need a more procedural approach for expansion:

macro { [ ···array ] } >> { [ ·sekjun9878_array_expander(···array) ] }

Within sekjun9878_array_expander you would have freedom to do the token substitutions/enforestation in pure PHP, without any DSL limitations.

But first we need to add some form of DI here https://github.com/marcioAlmada/yay/blob/master/src/Macro.php#L579, so custom expanders can be recognized by the macro interpreter. This is listed on the roadmap (issue #3) as "Support user defined parsers and expanders (add proper D.I for DSL lookups)".

@assertchris
Copy link
Collaborator

Should this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants