I attempt to document a syntax I use in menuentries.conf
, which is a configuration file for menu entries, by describing the syntax / grammar using the notation known as extended Backus-Naur-Form EBNF(BNF) This menuentries.conf uses indenting levels as syntactical component as should be displayed in this example:
menu_entry_1
menu_entry_2
menu_entry_2_submenu_entry_1
menu_entry_2_submenu_entry_2
menu_entry_2_submenu_entry_2_subsubmenu_1
menu_entry_2_submenu_entry_2_subsubmenu_2
menu_entry_2_submenu_entry_3
menu_entry_3
menu_entry_3_submenu_entry_1
In the above example each entry is represented by a string, which for the sake of the example implies/indicates its position. In addition the example should follow these rules
- each menu item is represented by single line (hence the menu entries are delimited by NEWLINE)
- menu entries without any indenting are "top level" menu entries
- menu entries with an indenting are not "top level" but child entries to the respective higher/upper level menu entry.
My attempt at providing a BNF is the following:
NEWLINE := '\n' INDENTING := ' ' menu_entry_string := ('a'|'b'|....|'z'|'_'|'0'|'1'|...|'9')+ menu_entries := menu_entry (NEWLINE menuentry)* menu_entry := menu_entry_string (NEWLINE INDENTING menu_entry)* submenu_entry := INDENTING menu_entry_string subsubmenu_entry := INDENTING INDENTING menu_entry_string
My question hence is with regards to my disatisfaction of the recursively declared notion menu_entry
and its redundancy with submenu_entry
and subsubmenu_entry
.
Knowing that python uses indenting as well to create the notion of blocks, I thought to look up the BNF/definition of pythons grammar (as found here: https://docs.python.org/3/reference/grammar.html) but it leaves the relevant notions of INDENT
and DEDENT
out of is grammar.
My question is hence: How to correctly use EBNF to describe a grammar/syntax in which indenting is employed as a grouping block? Ideally a small example (or if possible correction of my attempt) would be appreciated.
In the best case scenario the EBNF would define the notion of nesting-level
of the block
which would be: 1 for submenu_entry and 2 for subsubmenu_entry ....