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

Macroses support. Dynamic grammar #1231

Closed
xor2003 opened this issue Dec 10, 2022 · 5 comments
Closed

Macroses support. Dynamic grammar #1231

xor2003 opened this issue Dec 10, 2022 · 5 comments
Labels

Comments

@xor2003
Copy link

xor2003 commented Dec 10, 2022

I want to implement Macroses support for my masm parser. So is it possible to have kind of Dynamic grammar so I could add tokens at runtime?
Or check if token match with my handler? (If macros was defined several lines before)
It also might called custom matcher

@xor2003
Copy link
Author

xor2003 commented Dec 10, 2022

@erezsh
Copy link
Member

erezsh commented Dec 10, 2022

@xor2003 Can you give an example of the new tokens you would like to create?

@xor2003
Copy link
Author

xor2003 commented Dec 11, 2022

LABEL: /[A-Z]+/
structdir: LABEL "struct"i structitem+ structend
structitem: LABEL TYPE VALUE
structusage: LABEL STRUCTNAME
%declare STRUCTNAME

Example:
abc STRUCT
qwe DB 0
abc ENDS

Struct usage:
zxc abc

"abc" is a struct name defined above.
I mean I need to dynamically update grammar at runtime like:
STRUCTNAME: "abc"
If I define new structure:
newone STRUCT
somevar DB 0
newone ENDS
need to update:
STRUCTNAME: "abc" | "newone"

@erezsh
Copy link
Member

erezsh commented Dec 11, 2022

There is no API for something like that, and I don't think it would be super simple to add.

But if you use the interactive parser, you can "pause" at each point, collect the structs as they get defined, and try to match STRUCTNAME yourself.

Here's a real-world example of how something like that might look: https://github.com/geographika/mappyfile/blob/master/mappyfile/parser.py#L235

@xor2003
Copy link
Author

xor2003 commented Dec 13, 2022

I tried like you suggested and but lexer raises exception
"unexpected character" before I got to parser.
Trying to do it with postlex. Will put result here later

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

2 participants