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

Pluggable grammars #23

Open
xsawyerx opened this issue May 9, 2020 · 2 comments
Open

Pluggable grammars #23

xsawyerx opened this issue May 9, 2020 · 2 comments
Labels
capability A capability we need to support

Comments

@xsawyerx
Copy link
Owner

xsawyerx commented May 9, 2020

We can support grammar plugins so people could load additional grammar to parse DSLs.

Examples:

  • Moose
  • Dios
  • Dancer2

We can document the base lexemes so others can use them. They could create their own lexemes with a prefix for them, like MooseKeywordHasExpr and MooseKeywordHas.

@xsawyerx xsawyerx added the capability A capability we need to support label May 9, 2020
@xsawyerx
Copy link
Owner Author

Support from the wonderful #marpa developer community: 😍

05:44 | jdurand_ | Re https://colabti.org/irclogger/irclogger_log/marpa?date=2020-06-15#l6
05:45 | jdurand_ | as stated by Jeffrey, I it just a matter of compiling a grammar using variables
05:45 | jdurand_ | https://github.com/jddurand/MarpaX-Languages-M4/blob/master/lib/MarpaX/Languages/M4/Impl/Parser.pm does that for example
05:47 | jdurand_ | when https://github.com/jddurand/perl-MarpaX-ESLIF-URI  is playing with grammar subclass, as it if was a object (the later is  using MarpaX::ESLIF and not Marpa::R2 directly but the principles are  the same)

xsawyerx added a commit that referenced this issue May 30, 2022
To add new lexemes:

    Guacamole->add_lexemes(
        [ 'name'         => 'value' ],
        [ 'another_name' => 'another_value' ],
    );

This creates entries of:

    name         ~ 'value'
    another_name ~ 'another_value'

This doesn't even handle escaping "'" yet, so figure it out yourself. :)

To add new keywords:

    Guacamole->add_keyword(
        'MyNewKeyword',
        'unary',          # or: nullary, assign, list
        'my_new_keyword', # whatever name it has
        [ 'OpKeywordMyNewKeyword BlockNonEmpty' ],
    );

This will create the appropriate lexemes (prefixing your keyword with
'OpKeyword' which you can use in the rules) and the rules you provide.

Here is a small example of writing a try/catch implementation:

Example of adding support for Try::Tiny's try/catch:

Guacamole->add_keyword(
    'Catch',
    'unary',
    'catch',
    [ 'OpKeywordCatch BlockNonEmpty' ]
);

Guacamole->add_keyword(
    'Try',
    'list',
    'try',
    [
        'OpKeywordTry BlockNonEmpty OpKeywordCatchExpr',
        'OpKeywordTry BlockNonEmpty',
    ],
);

This, of course, does not check whether `Try::Tiny` is in effect.

Support "finally {}" is about the same with a few adjustments to
the different combinations ("try {} finally {}",
"try {} catch {} finally {}", etc.).
@xsawyerx
Copy link
Owner Author

xsawyerx commented May 30, 2022

Preliminary implementation available with documentation of it here: 801bcb6

xsawyerx added a commit that referenced this issue Jun 20, 2022
    * GH #23: (VERY) Preliminary support for extending the grammar.
    * GH #111: Support "die".
    * GH #112: Support "readline STDIN" or "readline(STDIN)".
    * GH #113: Support "$#_" (but not "$# _").
    * GH #114: Support all forms of binmode() (Val @valcomm).
    * GH #115: Support all forms of for() loop (Val @valcomm).
    * RT #132920: Fix confusion of quote-like operators by comments.
    * Support "_" in file operations ("-x _", etc.).
    * Support "$foo->$bar" and "$foo->$_".
    * Support 'eval "..."' or 'eval $foo'.
    * Improve wording on top-level anonymous hashes.
    * When failing without an exception, we throw an exception with
      more information (e.g., "print _").
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
capability A capability we need to support
Projects
None yet
Development

No branches or pull requests

1 participant