From 9b36a83044a4b1b1858bf9aa3245f5bbf5fb794b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Szeremeta?= Date: Mon, 17 Aug 2020 18:43:18 +0200 Subject: [PATCH] More flexibility in empty labels or properties > Examples < Node without labels: Option 1: {}[...] Option 2: [...] Node without properties: Option 1: {...}[] Option 2: {} Similar in edges and node/edge schamas --- other-notations/YARSpg.ebnf | 19 +++++++++---------- yarspg/YARSpg.g4 | 16 ++++++++-------- yarspg/examples/test-example.yarspg | 4 ++++ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/other-notations/YARSpg.ebnf b/other-notations/YARSpg.ebnf index e2adb5c..0290bf7 100644 --- a/other-notations/YARSpg.ebnf +++ b/other-notations/YARSpg.ebnf @@ -59,20 +59,20 @@ rdf_annotation annotations_list ::= '+' '[' annotation (',' annotation)* ']' props_list - ::= '[' prop (',' prop)* ']' + ::= ( '[' ( prop (',' prop)* )? ']' )? meta_prop ::= '@' key ':' value graphs_list ::= '/' graph_name (',' graph_name)* '/' node - ::= '<' node_id '>' ('{' node_label (',' node_label)* '}')? props_list? graphs_list? annotations_list? + ::= '<' node_id '>' ( '{' ( node_label ( ',' node_label )* )? '}' )? props_list graphs_list? annotations_list? edge ::= directed | undirected section ::= '%' SECTION_NAME -directed ::= '(' node_id ')' '-' ('<' edge_id '>')? '{' edge_label '}' props_list? '->' '(' node_id ')' graphs_list? annotations_list? +directed ::= '(' node_id ')' '-' ( '<' edge_id '>' )? ( '{' ( edge_label ( ',' edge_label )* )? '}' )? props_list '->' '(' node_id ')' graphs_list? annotations_list? undirected - ::= '(' node_id ')' '-' ('<' edge_id '>')? '{' edge_label '}' props_list? '-' '(' node_id ')' graphs_list? annotations_list? + ::= '(' node_id ')' '-' ( '<' edge_id '>' )? ( '{' ( edge_label ( ',' edge_label )* )? '}' )? props_list '-' '(' node_id ')' graphs_list? annotations_list? node_id ::= STRING node_label ::= STRING @@ -97,9 +97,9 @@ set ::= '{' ( primitive_value | set ) meta_prop* ( ',' ( primitive_value | list ::= '[' ( primitive_value | list ) meta_prop* ( ',' ( primitive_value | list ) meta_prop* )* ']' struct ::= '{' key ':' ( primitive_value | struct ) meta_prop* ( ',' key ':' ( primitive_value | struct ) meta_prop* )* '}' node_schema - ::= 'S' ('{' node_label (',' node_label)* '}')? props_list_schema? graphs_list? annotations_list? -props_list_schema - ::= '[' prop_schema (',' prop_schema)* ']' + ::= 'S' ( '{' ( node_label ( ',' node_label )* )? '}' )? prop_list_schema graphs_list? annotations_list? +prop_list_schema + ::= ( '[' ( prop_schema ( ',' prop_schema )* )? ']' )? prop_schema ::= key ':' value_schema id_key? meta_prop_schema @@ -134,10 +134,9 @@ edge_schema ::= directed_schema | undirected_schema directed_schema - ::= 'S' ('(' node_label ')')? '-' '{' edge_label '}' props_list_schema? '->' ('(' node_label ')')? + ::= 'S' '(' node_label ')' '-' ( '{' ( edge_label ( ',' edge_label )* )? '}' )? prop_list_schema '->' '(' node_label ')' undirected_schema - ::= 'S' ('(' node_label ')')? '-' '{' edge_label '}' props_list_schema? '-' ('(' node_label ')')? - + ::= 'S' '(' node_label ')' '-' ( '{' ( edge_label ( ',' edge_label )* )? '}' )? prop_list_schema '-' '(' node_label ')' SECTION_NAME ::= 'METADATA' | 'NODE SCHEMAS' diff --git a/yarspg/YARSpg.g4 b/yarspg/YARSpg.g4 index f13a249..7b0a683 100644 --- a/yarspg/YARSpg.g4 +++ b/yarspg/YARSpg.g4 @@ -78,7 +78,7 @@ annotations_list ; props_list - : '[' prop (',' prop)* ']' + : ( '[' ( prop (',' prop)* )? ']' )? ; meta_prop @@ -90,7 +90,7 @@ graphs_list ; node - : '<' node_id '>' ('{' node_label (',' node_label)* '}')? props_list? graphs_list? annotations_list? + : '<' node_id '>' ( '{' ( node_label ( ',' node_label )* )? '}' )? props_list graphs_list? annotations_list? ; edge @@ -103,11 +103,11 @@ section ; directed - : '(' node_id ')' '-' ('<' edge_id '>')? '{' edge_label '}' props_list? '->' '(' node_id ')' graphs_list? annotations_list? + : '(' node_id ')' '-' ('<' edge_id '>')? ( '{' ( edge_label ( ',' edge_label )* )? '}' )? props_list '->' '(' node_id ')' graphs_list? annotations_list? ; undirected - : '(' node_id ')' '-' ('<' edge_id '>')? '{' edge_label '}' props_list? '-' '(' node_id ')' graphs_list? annotations_list? + : '(' node_id ')' '-' ('<' edge_id '>')? ( '{' ( edge_label ( ',' edge_label )* )? '}' )? props_list '-' '(' node_id ')' graphs_list? annotations_list? ; node_id @@ -166,11 +166,11 @@ struct ; node_schema - : 'S' '{' node_label (',' node_label)* '}' prop_list_schema? graphs_list? annotations_list? + : 'S' ( '{' ( node_label ( ',' node_label )* )? '}' )? prop_list_schema graphs_list? annotations_list? ; prop_list_schema - : '[' prop_schema (',' prop_schema)* ']' + : ( '[' ( prop_schema (',' prop_schema)* )? ']' )? ; prop_schema @@ -229,11 +229,11 @@ edge_schema ; directed_schema - : 'S' '(' node_label ')' '-' '{' edge_label '}' prop_list_schema? '->' '(' node_label ')' + : 'S' '(' node_label ')' '-' ( '{' ( edge_label ( ',' edge_label )* )? '}' )? prop_list_schema '->' '(' node_label ')' ; undirected_schema - : 'S' '(' node_label ')' '-' '{' edge_label '}' prop_list_schema? '-' '(' node_label ')' + : 'S' '(' node_label ')' '-' ( '{' ( edge_label ( ',' edge_label )* )? '}' )? prop_list_schema '-' '(' node_label ')' ; SECTION_NAME diff --git a/yarspg/examples/test-example.yarspg b/yarspg/examples/test-example.yarspg index e880d4c..a1322f7 100644 --- a/yarspg/examples/test-example.yarspg +++ b/yarspg/examples/test-example.yarspg @@ -18,7 +18,9 @@ % NODES % NODE SCHEMAS <"a">{"a1d","x"}["aa1a":true,"a2aa":"text","aa3aa":null]+[foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", : "Test annotation"] +<"b43b">{}[]+[foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk"] #b43b <"b43b">{"label1"}["value":5]+[foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk"] #b43b +S{}[]/"graph2"/ S{"label333","c"}["value": String,"lang": String,"valid": Bool]/"graph2"/+[: , foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", : "Test annotation", "cdf": "fgh", foaf:maker: ] S{"label333","c"}["value": String,"lang": String,"valid": Bool ID]/"graph2"/+[: , foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", : "Test annotation", "cdf": "fgh", foaf:maker: ] S{"label333","c"}["value": String ID,"lang": String,"valid": Bool]/"graph2"/+[: , foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", : "Test annotation", "cdf": "fgh", foaf:maker: ] @@ -76,8 +78,10 @@ S{"ZYT5"}["datetime": DateTime] % EDGES % EDGE SCHEMAS +S("a1d")-{}[]->("label333") S("a1d")-{"aaa1a"}["key": String, "aab2bc": List(Integer)]->("label333") S("a1d")-{"aaa1a"}["key": String ID, "aab2bc": List(Integer)]->("label333") +("a")-<"ferf">{}[]->("c") ("a")-<"ferf">{"aaa1a"}["key": "value", "aab2bc": [44, 22]]->("c")+[: ] ("a")-<"ferf">{"aaa1a"}["key": "value"@"ok": "no", "aab2bc": [44, 22]@"list name": "alph"]->("c")+[: ] ("a")-<"id341">{"aaa2a"}->("c")