I
I
Igor Statkevich2020-05-22 10:52:53
Python
Igor Statkevich, 2020-05-22 10:52:53

How to implement an EBNF grammar of this kind?

I'm trying to parse the string "###" using the EBNF grammar rules in the TatSu (grako) library:

grammar = """mask =
                  | ['()'] ['$'] {'#'} '#'
                  | ['()'] {'#'} '#%'
                  | ['()'] ['$'] {'#'} {'0'} '0' '.#' {'#'}
"""

I am getting an error:
tatsu.exceptions.FailedToken: (1:1) expecting '#' :
#
^
mask
start

My guess is that it does first {'#'} (finds '#' zero or more times) and after that tries to find '#' (mandatory '#' character).
Therefore, how to implement so that the mandatory character '#' is found first and after that it looks for additional characters '#' ?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question