Skip to content

Conversation

@0xedward
Copy link

@0xedward 0xedward commented Aug 14, 2022

Background

Currently it is not possible for a user to reference a rule from a grammar not in dharma/grammars unless they edit DharmaMachine.default_grammars to include the path to the grammar files they want to reference. In this patch, we add support for users to reference rules in other files or directories in their input grammar files using the -dependencies option. -dependencies accepts both files and directories of dharma grammar files. The -dependencies option prioritizes definitions in default_grammars over user defined dependent grammars to make resolving redefinition errors easier.

Example Usage

python3 -m dharma -g input_grammar.dg -d reference_grammar.dg

...
%section% := value

definition :=
    +reference_grammar:dependency+
...
...
%section% := value

dependency :=
    "This is a rule input_grammar references in its grammar"
...

…mmars rely on

Currently it is not possible for a user to reference a rule from a grammar not in `dharma/grammars` unless they edit [`DharmaMachine.default_grammars`](https://github.com/posidron/dharma/blob/c0fc27495abc342be207f9e4472ec4dc1ef6e425/dharma/core/dharma.py#L221) to include the path to the grammar files they want to reference. In this patch, we add support for users to reference rules in other files or directories in their input grammar files using the `-dependencies` option.

For example (`python3 -m dharma -g input_grammar.dg -d reference_grammar.dg`),

```input_grammar.dg
...
%section% := value

definition :=
    +reference_grammar:dependency+
...
```

```reference_grammar.dg
...
%section% := value

dependency :=
    "This is a rule input_grammar references in its grammar"
...
```
@posidron
Copy link
Owner

I'm terribly sorry that I only write now here, it's been a complex ride every since I left Mozilla that I can not really (yet) publish my changes made here at Microsoft and the public version here did not receive the proper attention.

First of all, thanks for the contribution, really appreciated, however, you were already able to do that via the colon operator if you specify your other grammar on the CLI use the name of that grammar as reference. :-) Look at the end of the README.md, although the common.dg is always pre-loaded, the concept works in general for other grammars.

Repository owner deleted a comment from milosavidev Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants