No project description provided
Project description
lark-action
Adding semantic actions to Lark parser frontend.
Features:
- semantic action support
- inline python code
- %mkrepl
- Use
#
for comments instead of//
. - Use
$1
,$2
, ... to acccess thei
-th intermediate result. - Use
@1
,@2
, ... to access their locations(for token only) - Use
*1
,*2
, ... to access the lexeme of tokens(for token only)
(CONFESS: I develop this because the existing tools are crazily shitty.)
Usage
%mkrepl # generate a repl for you; not necessary
# inline python code into the generated parser
%%
def my_func():
print("call myfunc")
%%
start : ESCAPED_STRING -> $1 # '$1' accesses the 1-st component
| "%" start -> my_func()
%import common.WS
%import common.ESCAPED_STRING
%ignore WS
execute command python -m lark_action <grammar.lark> [-- package=""] [--module="mylang"]
, with default arguments you get 3 generated files: mylang.lark
and mylang_raw.py
and mylang.py
.
You can directly access the generated parser via from mylang import parser
.
If %mkrepl
is specified, you get a simple repl to check your parser:
python mylang.py
input 'q' and exit.
> % "asd"
call myfunc
None
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for lark_action-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 706edb051988485f278a4e7278989d2c8a23f2a7de666208237aa8c7f0d8e7f5 |
|
MD5 | 19bf3d64e7d7ac2e3cc7c62f2841084d |
|
BLAKE2b-256 | da12d40fbac96be2439cf55a30e250127c24d3cbed24fe36a2b5790460e9d6ba |