mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-06 15:48:47 +00:00
[grammar test] Extra set delimiters and separators.
Delimiters: Square brackets and parentheses. Separators: Commas and semicolons
This commit is contained in:
+5
-9
@@ -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] == '\\')
|
if(rule_element->string.size == 2 && rule_element->string.str[0] == '\\')
|
||||||
{
|
{
|
||||||
switch(rule_element->string.str[1]){
|
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
|
else
|
||||||
@@ -349,8 +350,6 @@ struct Test
|
|||||||
MD_Node *file_control_node;
|
MD_Node *file_control_node;
|
||||||
MD_String8List expanded_list;
|
MD_String8List expanded_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int TestCompare(const void *a_, const void *b_)
|
int TestCompare(const void *a_, const void *b_)
|
||||||
{
|
{
|
||||||
int result = 1;
|
int result = 1;
|
||||||
@@ -365,8 +364,6 @@ int TestCompare(const void *a_, const void *b_)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argument_count, char **arguments)
|
int main(int argument_count, char **arguments)
|
||||||
{
|
{
|
||||||
MD_Node *grammar = MD_ParseWholeFile(MD_S8Lit("tests/grammar.md"));
|
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))
|
for(MD_EachNode(production, productions->first_child))
|
||||||
{
|
{
|
||||||
printf("%.*s: \n", MD_StringExpand(production->string));
|
printf("%.*s: \n", MD_StringExpand(production->string));
|
||||||
|
|
||||||
for(MD_EachNode(rule, production->first_child))
|
for(MD_EachNode(rule, production->first_child))
|
||||||
{
|
{
|
||||||
printf(" ");
|
printf(" ");
|
||||||
@@ -502,6 +498,7 @@ int main(int argument_count, char **arguments)
|
|||||||
MD_Node *file_node = MD_ParseWholeString(MD_S8Lit(""), expanded);
|
MD_Node *file_node = MD_ParseWholeString(MD_S8Lit(""), expanded);
|
||||||
file_node->string = file_node->whole_string = (MD_String8){0};
|
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))
|
if(!EqualTrees(file_node, tests[i].file_control_node))
|
||||||
{
|
{
|
||||||
printf("\nFailed test %d\n", i_test);
|
printf("\nFailed test %d\n", i_test);
|
||||||
@@ -510,7 +507,6 @@ int main(int argument_count, char **arguments)
|
|||||||
MD_OutputTree(stdout, file_node);
|
MD_OutputTree(stdout, file_node);
|
||||||
printf("Grammar:\n");
|
printf("Grammar:\n");
|
||||||
MD_OutputTree(stdout, tests[i].file_control_node); printf("\n");
|
MD_OutputTree(stdout, tests[i].file_control_node); printf("\n");
|
||||||
BP;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-11
@@ -9,14 +9,21 @@
|
|||||||
* and miscellaneous semantics (@fill, @markup)
|
* and miscellaneous semantics (@fill, @markup)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
file : [@child set_list]
|
file : [@child file_set_list]
|
||||||
set_list : { [tag_list] set [' ' @sibling 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
|
// TODO(mal): Accept other open/close tokens
|
||||||
tag_list : '@' @tag tag ' ' [tag_list]
|
tag_list : '@' @tag tag ' ' [tag_list]
|
||||||
tag : identifier [@markup '(' [@child set_list] @markup ')']
|
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
|
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]
|
alphanumeric : alpha [alphanumeric] | digit [alphanumeric] | '_' [alphanumeric]
|
||||||
|
|
||||||
integer_literal : { ['-'] natural_literal }
|
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
|
// NOTE(mal): This is the simplest subset of the grammar that works
|
||||||
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
|
|
||||||
file : [@child set_list]
|
file : [@child set_list]
|
||||||
set_list : set ['\n' @sibling set_list]
|
set_list : set ['\n' @sibling set_list]
|
||||||
set : @fill element | '{' [@child set_list] '}'
|
set : @fill element | '{' [@child set_list] '}'
|
||||||
|
|||||||
Reference in New Issue
Block a user