haldis/app/hlds/hlds.tatsu

90 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

2019-12-01 00:04:13 +00: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 22:51:29 +00:00
@@keyword :: single_choice multi_choice dish preset only requires except
2019-12-01 00:04:13 +00:00
2020-01-24 14:16:01 +00:00
start = [n] { @+:location } $ ;
2019-12-01 00:04:13 +00:00
location_header =
/={3,}/ n ~
2019-12-01 00:04:13 +00:00
id:identifier ':' s name:string
attributes:{ location_attribute }
[ n ]
/={3,}\n+/
2019-12-01 00:04:13 +00:00
;
location_attribute =
n '\t' key:identifier s value:string
2019-12-01 00:04:13 +00:00
;
location = >location_header items:{ block } ;
attributes =
name:/[^\n#]*?(?= +-- | | *\n| *#)/
[ s '--' ~ s description:/[^\n#]*?(?= | *\n| *#)/ ]
[ / {2,}/ ~
[ {[ s ] ('{' tags+:identifier '}')} / +|$/ ]
[ price:price ]
]
2019-12-01 00:04:13 +00:00
;
block =
2020-01-26 22:51:29 +00:00
| dish_block
2019-12-01 00:04:13 +00:00
| choice_block
;
2020-01-26 22:51:29 +00:00
dish_block =
'dish' s ~
2019-12-01 00:04:13 +00: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 00:04:13 +00:00
n
;
2020-01-26 22:51:29 +00:00
# Appears in a dish block. One of:
2019-12-01 00:04:13 +00: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-23 23:26:53 +00:00
| kind:`reference` id:identifier [ s price:price ]
2019-12-01 00:04:13 +00:00
)
n
;
s = / +/ ;
2019-12-01 00:04:13 +00:00
n = '\n' {{'\t'} '\n'} ;
@name
identifier = /[a-z0-9_-]+/ ;
2020-02-29 21:26:17 +00:00
string = /[^\n#]+/ ;
2019-12-01 00:04:13 +00:00
choice_type = 'single_choice' | 'multi_choice' ;
int = /[0-9]+/ ;
2019-12-01 00:04:13 +00:00
currency = '€' ;
price = currency:currency s value_unit:int [ '.' value_cents:/[0-9]{,2}/ ] ;