diff --git a/app/hlds/hlds.tatsu b/app/hlds/hlds.tatsu index cb4d38c..62538b2 100644 --- a/app/hlds/hlds.tatsu +++ b/app/hlds/hlds.tatsu @@ -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 diff --git a/app/hlds/parser.py b/app/hlds/parser.py index 854e766..f8761db 100644 --- a/app/hlds/parser.py +++ b/app/hlds/parser.py @@ -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"],