E208 Missing builder functionΒΆ
A value builder calls a function, => Point(x, y) or => Point alone, that the functions given with the grammar lack. Python reports it when it loads the grammar, so that the problem shows before any parse. fpeg check cannot know the functions and does not report it.
import fpeg
text = r"""
start: x=NUMBER "," y=NUMBER => Point(x, y)
NUMBER: [0-9]+
"""
try:
fpeg.Grammar(text)
except fpeg.GrammarError as error:
(problem,) = error.diagnostics
assert problem.code == "E208"
assert str(problem) == (
"<grammar>:2:33: error[E208]: the builder calls Point, which is not among the "
"functions given"
)
Give the function with the grammar.
from dataclasses import dataclass
@dataclass
class Point:
x: object
y: object
grammar = fpeg.Grammar(text, functions={"Point": Point})
assert fpeg.Transformer().transform(grammar.parse("1,2")) == Point("1", "2")