Questions tagged [tatsu]

Use the [tatsu] tag for all questions related to the TatSu or Grako parser generators.

TatSu (the successor to Grako) is a tool that takes grammars in a variation of EBNF as input, and outputs memoizing (Packrat) PEG parsers in Python.

TatSu can also compile a grammar stored in a string into a tatsu.grammars.Grammar object that can be used to parse any given input, much like the re module does with regular expressions.

46 questions
5
votes
1 answer

How do I handle negative numbers in a PEG grammar?

I'm trying to write a simple int expression parser using tatsu, a PEG-based Python parser generator. Here is my code: import tatsu grammar = r''' start = expression $ ; expression = add | sub | term ; add = expression '+' term ; sub…
itsadok
  • 28,822
  • 30
  • 126
  • 171
4
votes
2 answers

How to generate standalone parser in Python?

I would like to generate a Python parser for a custom language. As I am new to parsing, my only requirement so far is that the generated module shall not depend on the generator. I learned Tatsu, as it can generate the parser as Python module. But…
Adam Trhon
  • 2,915
  • 1
  • 20
  • 51
3
votes
1 answer

Error with tatsu : does not recognize the right grammar pattern

I am getting started with tatsu and I am trying to implement a grammar for the miniML language. Once my grammar successfully parsed, I tried to parse some little expressions to check that it was working ; however I discovered Tatsu was unable to…
Lara
  • 33
  • 5
2
votes
1 answer

@name and @@keyword not working with rule annotations

I'm trying to use @@keyword and @name in my grammar but tatsu seems to ignore it if rules tagged @name are annotated. Am I missing something? To reproduce the behaviour, I provide the following example: This one works: import tatsu GRAMMAR =…
apio
  • 154
  • 11
2
votes
1 answer

How to handle semantic failures in TatSu when parsing is correct?

I am trying to create a TatSu parser for a language containing C-like expressions. I have the following grammar rules for the expressions: identifier = /[a-zA-Z][A-Za-z0-9_]*/ ; expression = or_expr ; or_expr = …
Dominick Pastore
  • 4,177
  • 2
  • 17
  • 29
2
votes
1 answer

Is it possible to continue parsing with other rules after an exception is raised in semantics?

Is it possible to fallback to other rules after an exception is raised in a semantic action? Like the following (contrived) scenario: var = /[a-zA-Z]+/; keyword = 'for' | 'in'; a = var:var | keyword:keyword; def a(ast): if (ast.var not in…
Sid Mani
  • 369
  • 3
  • 9
2
votes
1 answer

How to optimize this grammar rule?

I am implementing a grammar using the TatSu python library. My grammar is working OK but there is one rule that is eating quite a bit of time. On a block of around 3000 lines (part of a bigger grammar), if I take this full rule, it takes about 42s…
user4979733
  • 3,181
  • 4
  • 26
  • 41
2
votes
1 answer

Tatsu: Rule Ordering

I am playing around with Tatsu to implement a parser for a language used in the semiconductor industry. This language requires that variables be defined before usage. So for example: SignalGroup { A: In; B: Out}; Pattern { V {A=1, B=1 } V…
user4979733
  • 3,181
  • 4
  • 26
  • 41
2
votes
2 answers

Need help starting with Tatsu to parse grammar

I am getting a Tatsu error "tatsu.exceptions.FailedExpectingEndOfText: (1:1) Expecting end of text" running a test, using a grammar I supplied - it is not clear what the problem is. In essence, the statement calling the parser is: ast =…
Colin G
  • 309
  • 3
  • 14
2
votes
1 answer

How to match a pattern in Tatsu in a case insensitive manner

anybody knows how to recognize a pattern in Tatsu, in a case-insensitive way? The documentation says to: "Use (?i) in patterns that should ignore case." but I did not actually figure out how to use (?i) in my rule: graph = [ STRICT ] ( GRAPH…
Tommaso Mazza
  • 357
  • 4
  • 8
1
vote
0 answers

How to access TatSu parserinfo object

I've just started playing with TatSu and don't have much experience with it yet. I'm successfully parsing a small COBOL code snippet, but would like to access the details that are produced when parserinfo=True. Would anyone have some sample code I…
dreamer
  • 11
  • 1
1
vote
2 answers

Generate random grammar expansions in TatSu (Python)

I'm writing an interpreter for a grammar parser generated with TatSu. I'm looking for a convenient way to generate use cases for my grammar, so I can write unit tests for my interpreter. Currently, I'm generating my test cases by hand. I wonder if…
apio
  • 154
  • 11
1
vote
1 answer

Failure to match character that matches rule with PEG parser

I'm trying to parse Java-style floating point numbers (accepting underscores in the middle of digits) and have simplified the grammar presented in the Java spec: float_lit = [[DIGITS] '.'] DIGITS [FLOAT_EXP] [FLOAT_SUFFIX] ; DIGITS = /\d[\d_]*\d/ |…
Bruno Kim
  • 2,300
  • 4
  • 17
  • 27
1
vote
1 answer

Tatsu no stopping at end of text

I trying to add some simple error handling to a DSL grammar in Tatsu. I wrote a simple grammar that parses input into either numbers or errors. @@grammar :: Nums start = wordlist $ ; wordlist = {word eol}+ ; eol = ':' ; word = | num:num …
tjgriffin
  • 13
  • 2
1
vote
1 answer

Tatsu: How to validate/process arithmetic like expressions in semantic actions

I have a TatSu grammar where I am parsing arithmetic expressions like SignalGroup {ABUS='A3 + A2 + A1 + A0';}. Relevant grammar: #--------------------------------------------- SIGNAL GROUPS BLOCK…
user4979733
  • 3,181
  • 4
  • 26
  • 41
1
2 3 4