haldis/app/hlds/hlds.tatsu

88 lines
1.7 KiB
Text
Raw Normal View History

2019-12-01 01:04:13 +01:00
# This is a Tatsu file.
# Syntax is explained at
# https://tatsu.readthedocs.io/en/stable/syntax.html
@@grammar :: Hlds
# Don't ignore any whitespace
@@whitespace :: //
@@eol_comments :: /[ \t]*#.*?$/
2020-01-26 23:51:29 +01:00
@@keyword :: single_choice multi_choice dish preset only requires except
2019-12-01 01:04:13 +01:00
2020-01-24 15:16:01 +01:00
start = [n] { @+:location } $ ;
2019-12-01 01:04:13 +01:00
location_header =
/={3,}/ n ~
2019-12-01 01:04:13 +01:00
id:identifier ':' s name:string
attributes:{ location_attribute }
[ n ]
/={3,}\n+/
2019-12-01 01:04:13 +01:00
;
location_attribute =
n '\t' key:identifier ' ' value:string
;
location = >location_header items:{ block } ;
attributes =
2019-12-01 01:04:13 +01:00
name:/[^\n]*?(?= +-- | +:: | +€ |\n)/
[ s '--' ~ s description:/[^\n]*?(?= +:: | +€ |\n)/ ]
[ s '::' {s ('{' tags+:identifier '}')} ]
[ [ s '::' ~ ] s price:price ]
;
block =
2020-01-26 23:51:29 +01:00
| dish_block
2019-12-01 01:04:13 +01:00
| choice_block
;
2020-01-26 23:51:29 +01:00
dish_block =
'dish' s ~
2019-12-01 01:04:13 +01:00
id:identifier ':' s >attributes
n
choices:{ indent_choice_block }
;
choice_entry = id:identifier ':' s >attributes ;
noindent_choice_entry = n '\t' >choice_entry ;
indent_choice_entry = n '\t\t' >choice_entry ;
# Toplevel choice definitions
choice_block =
id:identifier ':' s >attributes entries:{ noindent_choice_entry }
2019-12-01 01:04:13 +01:00
n
;
2020-01-26 23:51:29 +01:00
# Appears in a dish block. One of:
2019-12-01 01:04:13 +01:00
# 1) reference to toplevel choice definition
# 2) inline choice declaration (as opposed to globally declared and referenced)
indent_choice_block =
'\t' type:choice_type s
(
| kind:`declaration` id:identifier ':' ~ s >attributes entries:{ indent_choice_entry }
2020-01-24 00:26:53 +01:00
| kind:`reference` id:identifier [ s price:price ]
2019-12-01 01:04:13 +01:00
)
n
;
s = / +/ ;
n = '\n' {{'\t'} '\n'} ;
@name
identifier = /[a-z0-9_-]+/ ;
string = /[^\n]+/ ;
choice_type = 'single_choice' | 'multi_choice' ;
int = /[0-9]+/ ;
2019-12-01 01:04:13 +01:00
currency = '€' ;
price = currency:currency s value_unit:int [ '.' value_cents:/[0-9]{,2}/ ] ;