[grammar test] Extra set delimiters and separators.

Delimiters: Square brackets and parentheses.
Separators: Commas and semicolons
This commit is contained in:
Miguel Lechon
2021-02-17 12:05:56 +01:00
parent 35c802deae
commit c5d88b890b
2 changed files with 17 additions and 20 deletions
+5 -9
View File
@@ -212,9 +212,10 @@ static void ExpandRule(MD_Node *rule, MD_String8List *out_strings, MD_Node *cur_
if(rule_element->string.size == 2 && rule_element->string.str[0] == '\\')
{
switch(rule_element->string.str[1]){
case '\\': c = '\\'; break;
case '\'': c = '\''; break;
case '"': c = '\"'; break;
case '\\': c = '\\'; break;
case '\'': c = '\''; break;
case '"': c = '\"'; break;
case 'n': c = '\n'; break;
}
}
else
@@ -349,8 +350,6 @@ struct Test
MD_Node *file_control_node;
MD_String8List expanded_list;
};
int TestCompare(const void *a_, const void *b_)
{
int result = 1;
@@ -365,8 +364,6 @@ int TestCompare(const void *a_, const void *b_)
return result;
}
int main(int argument_count, char **arguments)
{
MD_Node *grammar = MD_ParseWholeFile(MD_S8Lit("tests/grammar.md"));
@@ -418,7 +415,6 @@ int main(int argument_count, char **arguments)
for(MD_EachNode(production, productions->first_child))
{
printf("%.*s: \n", MD_StringExpand(production->string));
for(MD_EachNode(rule, production->first_child))
{
printf(" ");
@@ -502,6 +498,7 @@ int main(int argument_count, char **arguments)
MD_Node *file_node = MD_ParseWholeString(MD_S8Lit(""), expanded);
file_node->string = file_node->whole_string = (MD_String8){0};
// printf("> %.*s <\n", MD_StringExpand(expanded));
if(!EqualTrees(file_node, tests[i].file_control_node))
{
printf("\nFailed test %d\n", i_test);
@@ -510,7 +507,6 @@ int main(int argument_count, char **arguments)
MD_OutputTree(stdout, file_node);
printf("Grammar:\n");
MD_OutputTree(stdout, tests[i].file_control_node); printf("\n");
BP;
return -1;
}
+12 -11
View File
@@ -9,14 +9,21 @@
* and miscellaneous semantics (@fill, @markup)
*/
file : [@child set_list]
set_list : { [tag_list] set [' ' @sibling set_list] }
file : [@child file_set_list]
file_set_list : { [tag_list] set [file_set_separator @sibling file_set_list] }
file_set_separator : ' ' | '\n'
// TODO(mal): Unify file_set_separator and set_separator by allowing ',' and ';' everywhere
set_list : { [tag_list] set [set_separator @sibling file_set_list] }
set_separator : ' ' | '\n' | ',' | ';'
// TODO(mal): Accept other open/close tokens
tag_list : '@' @tag tag ' ' [tag_list]
tag : identifier [@markup '(' [@child set_list] @markup ')']
set : @fill leaf | @fill identifier ':' @child @fill leaf | [@fill identifier ':'] '{' [@child set_list] '}'
set : @fill leaf | @fill identifier ':' @child @fill leaf | [@fill identifier ':'] set_open [@child set_list] set_close
set_open : '{' | '[' | '('
set_close : '}' | ']' | ')'
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
identifier : alpha [alphanumeric] | '_' [alphanumeric]
alphanumeric : alpha [alphanumeric] | digit [alphanumeric] | '_' [alphanumeric]
integer_literal : { ['-'] natural_literal }
@@ -60,13 +67,7 @@ symbol_colon : ':'
/*
// 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 : @fill element | '{' [@child set_list] '}'
element : 'A'
// NOTE(mal): This is the simplest grammar that works
// NOTE(mal): This is the simplest subset of the grammar that works
file : [@child set_list]
set_list : set ['\n' @sibling set_list]
set : @fill element | '{' [@child set_list] '}'