8000 GitHub - Zahgon/TatSu: 竜 TatSu generates Python parsers from grammars in a variation of EBNF · GitHub
[go: up one dir, main page]

Skip to content
ZahgonPublic
forked from neogeny/TatSu

About

竜 TatSu generates Python parsers from grammars in a variation of EBNF

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

3,190 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TatSu for Go

TatSu takes grammars in a variation of EBNF and parses text with them: a memoizing (Packrat) PEG parser with left recursion, cut, lookaheads, joins and gathers, named elements, constants, rule parameters and rule inheritance.

This repository is the Go port of TatSu: the module github.com/neogeny/tatsu-go (package tatsu) compiles TatSu grammars and parses with them, with the results, errors, semantic actions, model builder and walkers of the original Python library.

Usage

g, err := tatsu.Compile(`
    start: expr $

    expr: expr '+' term | term

    term: /\d+/
`)
if err != nil {
    log.Fatal(err)
}
ast, err := g.Parse("1 + 2 + 3")
if err != nil {
    log.Fatal(err)
}
fmt.Println(tatsu.Repr(ast)) // [['1', '+', '2'], '+', '3']

tatsu.Parse(grammar, text) compiles and parses in one call. Options such as tatsu.Start, tatsu.WithSemantics, tatsu.AsModel and tatsu.Setting give the keyword arguments of the original's compile() and parse(). Results are Python values in Go (see the package documentation): tatsu.Repr prints them as Python's repr() does and tatsu.AsJSONS writes their JSON.

The grammar language and the behaviour of the parser are documented in docs/. Python code generation, railroad diagrams and the command-line tools of the original are not part of the port.

Development

go build ./...
go vet ./...
go test ./...

The module uses the standard library only. internal/pyre reproduces CPython's re (the grammar's patterns are Python regular expressions), internal/pyuni the Unicode tables of CPython 3.12 and internal/pyval Python's repr(), int() and float().

License

TatSu is Copyright (C) 2017-2026 Juancarlo Añez and is distributed under the license in LICENSE.

About

竜 TatSu generates Python parsers from grammars in a variation of EBNF

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0