Lexer Directives
Lexer directives start with percent (:%)
.
Lexer directives are designed to switch the language grammar to another predefined one. For example, let's consider a user-defined grammar named my_yaml
:
Schematically, U will execute the following steps:
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#ffffff', 'mainBkg': '#cde9f4'}}}%%
flowchart LR
S(Parse with U <br/>':a : :%') --> A(Find grammar named<br/><my_yaml>) --> B("Parse with <my_yaml> <br/>'(- name...)'") --> E(Parse with U <br/>'\< a ...')
style A fill:#FFFFFF,stroke:#333
style S fill:#FFFFFF,stroke:#333
style E fill:#FFFFFF,stroke:#333
Here's what happens:
- U lexer read
':a : '
, then the aperture':%'
- U lexer switches the language grammar to
my_yaml
- The code following the directive until
')'
is parsed according to the rules of themy_yaml
grammar. - While parsing,
my_yaml
uses U compiler to create an array with strings'name'
, and'password'
- Once parsing with
my_yaml
is complete, the lexer can switch back to the original grammar or another specified one.