[grammar test] Labeled nodes and tag parameters.

This commit is contained in:
Miguel Lechon
2021-02-16 19:35:24 +01:00
parent e2920e565b
commit 50d6f7cd64
2 changed files with 75 additions and 64 deletions
+13 -12
View File
@@ -1,20 +1,21 @@
/* MetaDesk grammar with semantic annotations
*
* Each line represents a BNF-esque production of the form:
* Each line represents a BNF-esque production:
* symbol : rule_1 | ... | rule_n
* - Pipe signs indicate mutually exclusive alternatives
* - Square quotes denote optional rules
* - Character literals are terminal productions
* - Tags indicate which way the productions attach to the generated tree (@child, @sibling, @leaf, @tag)
* and miscellaneous semantics (@delimiter)
* - Tags indicate which way the productions attach to the generated tree (@child, @sibling, @fill, @tag)
* and miscellaneous semantics (@markup)
*/
file : [@child set_list]
set_list : tagged_named_set [' ' @sibling set_list]
tagged_named_set: { [tag_list] set }
tag_list : @tag tag ' ' [tag_list]
tag : '@' identifier // TODO(mal): tag parameters
set : @leaf leaf | '{' [@child set_list] '}'
// TODO(mal): Accept other open/close tokens
set : @fill leaf | @fill identifier ':' @child @fill leaf | [@fill identifier ':'] '{' [@child set_list] '}'
tag_list : '@' @tag tag ' ' [tag_list]
tag : identifier [@markup '(' [@child set_list] @markup ')']
leaf : identifier | integer_literal | char_literal | string_literal // TODO(mal): Also symbol_label
identifier : alpha [alphanumeric] // TODO(mal): I think we should allow leading underscores
alphanumeric : alpha [alphanumeric] | digit [alphanumeric] | '_' [alphanumeric]
@@ -22,7 +23,7 @@ alphanumeric : alpha [alphanumeric] | digit [alphanumeric] | '_' [alphanumeri
integer_literal : { ['-'] natural_literal }
natural_literal : digit [natural_literal]
char_literal : @delimiter '\'' [char_literal_items] @delimiter '\''
char_literal : @markup '\'' [char_literal_items] @markup '\''
char_literal_items : char_literal_item [char_literal_items]
char_literal_item : ascii_no_backslash_no_quotes | '"' | '\\' ascii
ascii : ascii_no_backslash_no_quotes | '\'' | '"' | '\\'
@@ -31,7 +32,7 @@ symbol_no_backslash_no_quotes : symbol_no_backslash_no_quotes_1 | symbol_no_ba
symbol_no_backslash_no_quotes_1 : '!'|'#'|'$'|'%'|'&'|'('|')'|'*'|'+'|','|'-'|'.'|'/'|':'|';'
symbol_no_backslash_no_quotes_2 : '<'|'='|'>'|'?'|'@'|'['|']'|'^'|'_'|'`'|'{'|'|'|'}'|'~'
string_literal : @delimiter '"' [string_literal_items] @delimiter '"'
string_literal : @markup '"' [string_literal_items] @markup '"'
string_literal_items : string_literal_item [string_literal_items]
string_literal_item : ascii_no_backslash_no_quotes | '\'' | '\\' ascii
@@ -60,16 +61,16 @@ symbol_colon : ':'
/*
// NOTE(mal): I think this one should work too, but MD only delimits top level constructs with newlines
// NOTE(mal): I think this one should work too, but MD only allows newlines as top-level construct separators
file : [@child set_list]
set_list : set [',' @sibling set_list]
set : @leaf element | '{' [@child set_list] '}'
set : @fill element | '{' [@child set_list] '}'
element : 'A'
// NOTE(mal): This is the simples grammar that works
// NOTE(mal): This is the simplest grammar that works
file : [@child set_list]
set_list : set ['\n' @sibling set_list]
set : @leaf element | '{' [@child set_list] '}'
set : @fill element | '{' [@child set_list] '}'
element : 'A'
*/