Skip to content

Commit

Permalink
Variables support
Browse files Browse the repository at this point in the history
Variable can store properties list (also for schema)

For example:
$person = "fname": "String", "lname": "String"
S{"Author"}[$person]
S{"Student"}[$person, "bday": Date]
  • Loading branch information
lszeremeta committed Aug 17, 2020
1 parent 9b36a83 commit 37d111e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
12 changes: 10 additions & 2 deletions other-notations/YARSpg.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,7 +67,7 @@ rdf_annotation
annotations_list
::= '+' '[' annotation (',' annotation)* ']'
props_list
::= ( '[' ( prop (',' prop)* )? ']' )?
::= ( '[' ( ( prop | var ) ( ',' ( prop | var ) )* )? ']' )?
meta_prop
::= '@' key ':' value
graphs_list
Expand Down Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions yarspg/YARSpg.g4
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ statement
| edge
| prefix_directive
| metadata
| var_declaration
| node_schema
| edge_schema
| var_declaration_schema
| section
;

Expand All @@ -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
;
Expand All @@ -78,7 +96,7 @@ annotations_list
;

props_list
: ( '[' ( prop (',' prop)* )? ']' )?
: ( '[' ( ( prop | var ) (',' ( prop | var ) )* )? ']' )?
;

meta_prop
Expand Down Expand Up @@ -170,7 +188,7 @@ node_schema
;

prop_list_schema
: ( '[' ( prop_schema (',' prop_schema)* )? ']' )?
: ( '[' ( ( prop_schema | var ) (',' ( prop_schema | var ) )* )? ']' )?
;

prop_schema
Expand Down
9 changes: 8 additions & 1 deletion yarspg/examples/test-example.yarspg
Original file line number Diff line number Diff line change
Expand Up @@ -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", <http://xmlns.com/dc/0.5/zyz>: "Test annotation"]
<"a">{"a1d","x"}["aa1a":true,"a2aa":"text","aa3aa":null]+[foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", <http://xmlns.com/dc/0.5/zyz>: "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"/+[<http://xmlns.com/dc/0.5/zyz>: <http://xmlns.com/dc/0.5/qtv>, foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", <http://xmlns.com/dc/0.5/zyz>: "Test annotation", "cdf": "fgh", foaf:maker: <http://example.com/me>]
$var44_schema = "value": String,"lang": String
S{"label333","c"}[$var44_schema,"valid": Bool]/"graph2"/+[<http://xmlns.com/dc/0.5/zyz>: <http://xmlns.com/dc/0.5/qtv>, foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", <http://xmlns.com/dc/0.5/zyz>: "Test annotation", "cdf": "fgh", foaf:maker: <http://example.com/me>]
S{"label333","c"}["value": String,"lang": String,"valid": Bool ID]/"graph2"/+[<http://xmlns.com/dc/0.5/zyz>: <http://xmlns.com/dc/0.5/qtv>, foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", <http://xmlns.com/dc/0.5/zyz>: "Test annotation", "cdf": "fgh", foaf:maker: <http://example.com/me>]
S{"label333","c"}["value": String ID,"lang": String,"valid": Bool]/"graph2"/+[<http://xmlns.com/dc/0.5/zyz>: <http://xmlns.com/dc/0.5/qtv>, foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", <http://xmlns.com/dc/0.5/zyz>: "Test annotation", "cdf": "fgh", foaf:maker: <http://example.com/me>]
<"c">{"label333","c"}["value":"male","lang":"en","valid":false]/"graph2", "graph3"/+[<http://xmlns.com/dc/0.5/zyz>: <http://xmlns.com/dc/0.5/qtv>, foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", <http://xmlns.com/dc/0.5/zyz>: "Test annotation", "cdf": "fgh", foaf:maker: <http://example.com/me>]
Expand Down Expand Up @@ -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")+[<http://xmlns.com/dc/0.5/zyz>: <http://xmlns.com/dc/0.5/qtv>]
$var_e344 = "aab2bc": [44, 22]@"list name": "alph"
("a")-<"ferf">{"aaa1a"}["key": "value"@"ok": "no", $var_e344]->("c")+[<http://xmlns.com/dc/0.5/zyz>: <http://xmlns.com/dc/0.5/qtv>]
("a")-<"ferf">{"aaa1a"}["key": "value"@"ok": "no", "aab2bc": [44, 22]@"list name": "alph"]->("c")+[<http://xmlns.com/dc/0.5/zyz>: <http://xmlns.com/dc/0.5/qtv>]
("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", <http://xmlns.com/dc/0.5/zyz>: "Test annotation"]
("b43b")-{"bbbb53b"}["bbbd32d": false, "value": null@"psod": {"dff": 1, "ewf": 55}]-("e")+[foaf:maker: "Łukasz Szeremeta and Dominik Tomaszuk", <http://xmlns.com/dc/0.5/zyz>: "Test annotation"]
Expand Down

0 comments on commit 37d111e

Please sign in to comment.