Skip to main content

No project description provided

Project description


Adding semantic actions to Lark parser frontend.


  1. semantic action support
  2. inline python code
  3. %mkrepl
  4. Use # for comments instead of //.
  5. Use $1, $2, ... to acccess the i-th intermediate result.
  6. Use @1, @2, ... to access their locations(for token only)
  7. Use *1, *2, ... to access the lexeme of tokens(for token only)

(CONFESS: I develop this because the existing tools are crazily shitty.)


%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 and

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:

input 'q' and exit.
> % "asd"
call myfunc

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

lark_action-0.1.5-py3-none-any.whl (54.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page