From 2db02b93263f5dcdb125f759693e9d742a690d91 Mon Sep 17 00:00:00 2001 From: Midgard Date: Mon, 27 Jan 2020 19:15:24 +0100 Subject: [PATCH] Parse incorrect attributes but semantic error --- app/hlds/hlds.tatsu | 10 +++------- app/hlds/parser.py | 4 ++++ 2 files changed, 7 insertions(+), 7 deletions(-) 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"],