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

Lark | Creating A Grammar For YAML #1482

Open
jordanparker6 opened this issue Nov 6, 2024 · 0 comments
Open

Lark | Creating A Grammar For YAML #1482

jordanparker6 opened this issue Nov 6, 2024 · 0 comments
Labels

Comments

@jordanparker6
Copy link

jordanparker6 commented Nov 6, 2024

What is your question?

Trying to create a grammar that can parse any YAML file.

If you're having trouble with your code or grammar

Here is the code I am using.

%import common.NEWLINE
%import common.ESCAPED_STRING
%import common.SIGNED_NUMBER
%import common.WS_INLINE
%ignore WS_INLINE

start: document

document: element+

element: mapping
       | sequence
       | scalar

mapping: mapping_pair+

mapping_pair: key ":" WS_INLINE? value NEWLINE?

key: scalar

value: scalar
     | mapping_block
     | sequence_block

mapping_block: NEWLINE INDENT mapping_pair+ DEDENT

sequence: sequence_item+

sequence_item: "-" WS_INLINE? value NEWLINE?

sequence_block: NEWLINE INDENT sequence_item+ DEDENT

scalar: ESCAPED_STRING       -> string
      | SIGNED_NUMBER        -> number
      | BOOL                 -> boolean
      | NULL                 -> null
      | unquoted_string      -> unquoted

unquoted_string: /[^{}\[\],":\s\n][^{}\[\],":\n]*/

BOOL: "true" | "false"
NULL: "null" | "~"

%declare INDENT DEDENT
%ignore WS_INLINE

Explain what you're trying to do, and what is obstructing your progress.

I new to CFG and seem to struggle with the INDENT / DEDENTs.

What is going wrong with this and does anyone have a working example on how I could use a CFG to parse a YAML file?

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

1 participant