Browse Source

Docs: improve section concerning grammar imports

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.6.6
Rogdham 6 years ago
parent
commit
19fdff70f8
1 changed files with 9 additions and 0 deletions
  1. +9
    -0
      docs/grammar.md

+ 9
- 0
docs/grammar.md View File

@@ -133,20 +133,29 @@ When importing rules, all their dependencies will be imported into a namespace,
**Syntax:**
```html
%import <module>.<TERMINAL>
%import <module>.<TERMINAL> -> <NEWTERMINAL>
%import <module> (<TERM1> <TERM2>)
%import <module>.<rule>
%import <module>.<rule> -> <newrule>
```

If the module path is absolute, Lark will attempt to load it from the built-in directory (currently, only `common.lark` is available).

If the module path is relative, such as `.path.to.file`, Lark will attempt to load it from the current working directory. Grammars must have the `.lark` extension.

The rule or terminal can be imported under an other name with the `->` syntax.

**Example:**
```perl
%import common.NUMBER

%import .terminals_file (A B C)

%import .rules_file.rulea -> ruleb
```

Note that importing rules drops the `%ignore` directives, so this may change the grammar defined in the file.

### %declare

Declare a terminal without defining it. Useful for plugins.

Loading…
Cancel
Save