Parse incorrect attributes but semantic error

This commit is contained in:
Midgard 2020-01-27 19:15:24 +01:00
parent 6768a35808
commit 2db02b9326
Signed by: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 7 additions and 7 deletions

View file

@ -28,13 +28,9 @@ location_attribute =
location = >location_header items:{ block } ;
name_and_description =
attributes =
name:/[^\n]*?(?= +-- | +:: | +€ |\n)/
[ s '--' ~ s description:/[^\n]*?(?= +:: | +€ |\n)/ ]
;
attributes =
>name_and_description
[ s '::' {s ('{' tags+:identifier '}')} ]
[ [ s '::' ~ ] s price:price ]
;
@ -60,7 +56,7 @@ indent_choice_entry = n '\t\t' >choice_entry ;
# Toplevel choice definitions
choice_block =
id:identifier ':' s >name_and_description entries:{ noindent_choice_entry }
id:identifier ':' s >attributes entries:{ noindent_choice_entry }
n
;
@ -70,7 +66,7 @@ choice_block =
indent_choice_block =
'\t' type:choice_type s
(
| kind:`declaration` id:identifier ':' ~ s >name_and_description entries:{ indent_choice_entry }
| kind:`declaration` id:identifier ':' ~ s >attributes entries:{ indent_choice_entry }
| kind:`reference` id:identifier [ s price:price ]
)
n

View file

@ -6,6 +6,7 @@ import itertools
from typing import Iterable, List, Union, Tuple
from tatsu import parse as tatsu_parse
from tatsu.ast import AST
from tatsu.exceptions import SemanticError
from .models import Location, Choice, Option, Dish
@ -51,6 +52,9 @@ class HldsSemanticActions:
)
def choice_block(self, ast) -> Choice:
if ast["price"] or ast["tags"]:
raise SemanticError("Choice blocks cannot have price or tags, put them on each of its options instead")
return Choice(
ast["id"],
name=ast["name"],