From 37d111ea8d0f4ae226abb25b9d8f87865cb9022b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Szeremeta?= Date: Mon, 17 Aug 2020 23:20:41 +0200 Subject: [PATCH] Variables support Variable can store properties list (also for schema) For example: $person = "fname": "String", "lname": "String" S{"Author"}[$person] S{"Student"}[$person, "bday": Date] --- other-notations/YARSpg.ebnf | 12 ++++++++++-- yarspg/YARSpg.g4 | 22 ++++++++++++++++++++-- yarspg/examples/test-example.yarspg | 9 ++++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/other-notations/YARSpg.ebnf b/other-notations/YARSpg.ebnf index 0290bf7..06aaf69 100644 --- a/other-notations/YARSpg.ebnf +++ b/other-notations/YARSpg.ebnf @@ -39,14 +39,22 @@ statement | edge | prefix_directive | metadata + | var_declaration | node_schema | edge_schema + | var_declaration_schema | section prefix_directive ::= pname IRI pname ::= ':' ALNUM_PLUS ':' pn_local ::= ALNUM_PLUS metadata ::= '-' ((pn_local pname) | (IRI ':')) (STRING | IRI) +var ::= '$' var_name +var_declaration + ::= var '=' prop ( ',' prop )* +var_declaration_schema + ::= var '=' prop_schema ( ',' prop_schema )* +var_name ::= ALNUM_PLUS graph_name ::= STRING annotation @@ -59,7 +67,7 @@ rdf_annotation annotations_list ::= '+' '[' annotation (',' annotation)* ']' props_list - ::= ( '[' ( prop (',' prop)* )? ']' )? + ::= ( '[' ( ( prop | var ) ( ',' ( prop | var ) )* )? ']' )? meta_prop ::= '@' key ':' value graphs_list @@ -99,7 +107,7 @@ struct ::= '{' key ':' ( primitive_value | struct ) meta_prop* ( ',' key ':' ( node_schema ::= 'S' ( '{' ( node_label ( ',' node_label )* )? '}' )? prop_list_schema graphs_list? annotations_list? prop_list_schema - ::= ( '[' ( prop_schema ( ',' prop_schema )* )? ']' )? + ::= ( '[' ( ( prop_schema | var ) ( ',' ( prop_schema | var ) )* )? ']' )? prop_schema ::= key ':' value_schema id_key? meta_prop_schema diff --git a/yarspg/YARSpg.g4 b/yarspg/YARSpg.g4 index 7b0a683..369ecec 100644 --- a/yarspg/YARSpg.g4 +++ b/yarspg/YARSpg.g4 @@ -35,8 +35,10 @@ statement | edge | prefix_directive | metadata + | var_declaration | node_schema | edge_schema + | var_declaration_schema | section ; @@ -56,6 +58,22 @@ metadata : '-' ((pn_local pname) | (IRI ':')) (STRING | IRI) ; +var + : '$' var_name + ; + +var_declaration + : var '=' prop (',' prop)* + ; + +var_declaration_schema + : var '=' prop_schema (',' prop_schema)* + ; + +var_name + : ALNUM_PLUS + ; + graph_name : STRING ; @@ -78,7 +96,7 @@ annotations_list ; props_list - : ( '[' ( prop (',' prop)* )? ']' )? + : ( '[' ( ( prop | var ) (',' ( prop | var ) )* )? ']' )? ; meta_prop @@ -170,7 +188,7 @@ node_schema ; prop_list_schema - : ( '[' ( prop_schema (',' prop_schema)* )? ']' )? + : ( '[' ( ( prop_schema | var ) (',' ( prop_schema | var ) )* )? ']' )? ; prop_schema diff --git a/yarspg/examples/test-example.yarspg b/yarspg/examples/test-example.yarspg index a1322f7..97fe843 100644 --- a/yarspg/examples/test-example.yarspg +++ b/yarspg/examples/test-example.yarspg @@ -17,11 +17,14 @@ # comment3#12 % NODES % NODE SCHEMAS +$var44 = "aa1a":true,"a2aa":"text" +<"a">{"a1d","x"}[$var44,"aa3aa":null]+[foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", : "Test annotation"] <"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: ] +$var44_schema = "value": String,"lang": String +S{"label333","c"}[$var44_schema,"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: ] <"c">{"label333","c"}["value":"male","lang":"en","valid":false]/"graph2", "graph3"/+[: , foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", : "Test annotation", "cdf": "fgh", foaf:maker: ] @@ -83,11 +86,15 @@ 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")+[: ] +$var_e344 = "aab2bc": [44, 22]@"list name": "alph" +("a")-<"ferf">{"aaa1a"}["key": "value"@"ok": "no", $var_e344]->("c")+[: ] ("a")-<"ferf">{"aaa1a"}["key": "value"@"ok": "no", "aab2bc": [44, 22]@"list name": "alph"]->("c")+[: ] ("a")-<"id341">{"aaa2a"}->("c") S("label1")-{"bbb23b"}-("ef22") ("b43b")-{"bbb23b"}-("e") +$var_234e_schema = "bbbd32d": Bool ID S("label1")-{"bbb23b"}["bbbd32d": Bool, "value": String NULL]-("ef22") +S("label1")-{"bbb23b"}[$var_234e_schema, "value": String NULL]-("ef22") S("label1")-{"bbb23b"}["bbbd32d": Bool ID, "value": String NULL]-("ef22") ("b43b")-{"bbbb53b"}["bbbd32d": false, "value": null]-("e")+[foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", : "Test annotation"] ("b43b")-{"bbbb53b"}["bbbd32d": false, "value": null@"psod": {"dff": 1, "ewf": 55}]-("e")+[foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", : "Test annotation"]