Skip to content

Commit

Permalink
Add more datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
lszeremeta committed Nov 30, 2021
1 parent 96b38ee commit 4a52868
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 44 deletions.
75 changes: 46 additions & 29 deletions other-notations/YARSpg.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
*/
yarspg ::= (statement metadata?)*
yarspg ::= ( statement metadata? )*
statement
::= node
| edge
Expand All @@ -43,39 +43,35 @@ statement
| edge_schema
| variable_declaration_schema
| graph
| graphs_schema
metadata
::= '+' prop_list
| graph_schema
metadata ::= '+' prop_list
variable ::= '$' variable_name
variable_declaration
::= variable '=' prop ( ',' prop )*
variable_declaration_schema
::= variable '=' prop_schema ( ',' prop_schema )*
variable_name
::= ALNUMPLUS
graph_id
::= DEFAULT
graph_id ::= DEFAULT
| ALNUMPLUS
prop_list
::= ( '[' ( ( prop | variable ) ( ',' ( prop | variable ) )* )? ']' )?
::= '[' ( ( prop | variable ) ( ',' ( prop | variable ) )* )? ']'
meta_prop
::= '@' '<' ( key ':' value ( ',' key ':' value )* )? '>'
graphs_list
::= '/' graph_id (',' graph_id)* '/'
::= '/' graph_id ( ',' graph_id )* '/'
graph ::= '/' graph_id '/' ( '{' ( graph_label ( ',' graph_label )* )? '}' )? prop_list?
node
::= '(' node_id ( '{' ( node_label ( ',' node_label )* )? '}' )? prop_list? ')' graphs_list?
edge
::= directed
node ::= '(' node_id ( '{' ( node_label ( ',' node_label )* )? '}' )? prop_list? ')' graphs_list?
edge ::= directed
| undirected
directed ::= '(' node_id ')' '-' '(' edge_id? ( '{' ( edge_label ( ',' edge_label )* )? '}' )? prop_list? ')' '->' '(' node_id ')' graphs_list?
undirected
::= '(' node_id ')' '-' '(' edge_id? ( '{' ( edge_label ( ',' edge_label )* )? '}' )? prop_list? ')' '-' '(' node_id ')' graphs_list?
node_id ::= ALNUMPLUS
node_label
::= STRING
prop ::= key ':' value meta_prop?
edge_id ::= ALNUMPLUS
prop ::= key ':' value meta_prop?
edge_id ::= ALNUMPLUS
edge_label
::= STRING
graph_label
Expand All @@ -89,17 +85,20 @@ complex_value
::= set_value
| list_value
| struct_value
set_value ::= '{' ( primitive_value | set_value ) meta_prop? ( ',' ( primitive_value | set_value ) meta_prop? )* '}'
list_value ::= '[' ( primitive_value | list_value ) meta_prop? ( ',' ( primitive_value | list_value ) meta_prop? )* ']'
struct_value ::= '{' key ':' ( primitive_value | struct_value ) meta_prop? ( ',' key ':' ( primitive_value | struct_value ) meta_prop? )* '}'
set_value
::= '{' ( primitive_value | set_value ) meta_prop? ( ',' ( primitive_value | set_value ) meta_prop? )* '}'
list_value
::= '[' ( primitive_value | list_value ) meta_prop? ( ',' ( primitive_value | list_value ) meta_prop? )* ']'
struct_value
::= '{' key ':' ( primitive_value | struct_value ) meta_prop? ( ',' key ':' ( primitive_value | struct_value ) meta_prop? )* '}'
node_schema
::= 'S' '(' node_id_schema ( '{' ( node_label ( ',' node_label )* )? '}' )? prop_list_schema? ')' graphs_list?
node_id_schema
::= ALNUMPLUS
prop_list_schema
::= '[' ( ( prop_schema | variable ) ( ',' ( prop_schema | variable ) )* )? ']'
prop_schema
::= key ':' value_schema id_key?
::= key ':' value_schema
meta_prop_schema
::= '@' '<' ( key ':' value_schema ( ',' key ':' value_schema )* )? '>'
cardinality
Expand All @@ -111,30 +110,40 @@ max_cardinality
::= MAX card_num
card_num ::= UNSIGNED_INT
value_schema
::= primitive_value_schema ( UNIQUE | NULL )? OPTIONAL? meta_prop_schema?
| complex_value_schema NULL? OPTIONAL? meta_prop_schema?
::= ( primitive_value_schema ( UNIQUE | NULL )? | complex_value_schema NULL? ) OPTIONAL? meta_prop_schema?
primitive_value_schema
::= DECIMAL
| SMALLINT
| INTEGER
| UINTEGER
| BIGINT
| FLOAT
| REAL
| DOUBLE
| BOOL
| STRING_TYPE
| STRINGT
| DATE
| DATETIME
| LOCALDATETIME
| TIME
| LOCALTIME
| DURATION
| BINARY
| ALNUMPLUS
complex_value_schema
::= set_schema
::= multiset_schema
| set_schema
| list_schema
| listd_schema
| struct_schema
multiset_schema
::= MULTISET '(' ( primitive_value_schema | set_schema ) NULL? cardinality? ')' meta_prop_schema?
set_schema
::= SET '(' ( primitive_value_schema | set_schema ) NULL? cardinality? ')' meta_prop_schema?
list_schema
::= LIST '(' ( primitive_value_schema | list_schema ) NULL? cardinality? ')' meta_prop_schema?
listd_schema
::= LISTD '(' ( primitive_value_schema | list_schema ) NULL? cardinality? ')' meta_prop_schema?
struct_schema
::= STRUCT '(' ( primitive_value_schema | struct_schema ) NULL? cardinality? ')' meta_prop_schema?
edge_schema
Expand All @@ -143,7 +152,7 @@ edge_schema
directed_schema
::= 'S' '(' node_id_schema ')' '-' ( '(' ( '{' ( edge_label ( ',' edge_label )* )? '}' )? prop_list_schema? ')' )? '->' '(' node_id_schema ')' graphs_list?
undirected_schema
::= 'S' '(' node_id_schema ')' '-' ( '(' ( '{' ( edge_label ( ',' edge_label )* )? '}' )? prop_list_schema? ')' )? '-' '(' node_id_schema1 ')' graphs_list?
::= 'S' '(' node_id_schema ')' '-' ( '(' ( '{' ( edge_label ( ',' edge_label )* )? '}' )? prop_list_schema? ')' )? '-' '(' node_id_schema ')' graphs_list?
graph_schema
::= 'S' '/' graph_id '/' prop_list_schema?

Expand All @@ -158,26 +167,34 @@ OPTIONAL ::= ( 'O' | 'o' ) ( 'P' | 'p' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'O' | 'o'
DECIMAL ::= ( 'D' | 'd' ) ( 'E' | 'e' ) ( 'C' | 'c' ) ( 'I' | 'i' ) ( 'M' | 'm' ) ( 'A' | 'a' ) ( 'L' | 'l' )
SMALLINT ::= ( 'S' | 's' ) ( 'M' | 'm' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'L' | 'l' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'T' | 't' )
INTEGER ::= ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'T' | 't' ) ( 'E' | 'e' ) ( 'G' | 'g' ) ( 'E' | 'e' ) ( 'R' | 'r' )
UINTEGER ::= ( 'U' | 'u' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'T' | 't' ) ( 'E' | 'e' ) ( 'G' | 'g' ) ( 'E' | 'e' ) ( 'R' | 'r' )
BIGINT ::= ( 'B' | 'b' ) ( 'I' | 'i' ) ( 'G' | 'g' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'T' | 't' )
FLOAT ::= ( 'F' | 'f' ) ( 'L' | 'l' ) ( 'O' | 'o' ) ( 'A' | 'a' ) ( 'T' | 't' )
REAL ::= ( 'R' | 'r' ) ( 'E' | 'e' ) ( 'A' | 'a' ) ( 'L' | 'l' )
DOUBLE ::= ( 'D' | 'd' ) ( 'O' | 'o' ) ( 'U' | 'u' ) ( 'B' | 'b' ) ( 'L' | 'l' ) ( 'E' | 'e' )
BOOL ::= ( 'B' | 'b' ) ( 'O' | 'o' ) ( 'O' | 'o' ) ( 'L' | 'l' )
STRING_TYPE
::= ( 'S' | 's' ) ( 'T' | 't' ) ( 'R' | 'r' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'G' | 'g' )
STRINGT ::= ( 'S' | 's' ) ( 'T' | 't' ) ( 'R' | 'r' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'G' | 'g' )
DATE ::= ( 'D' | 'd' ) ( 'A' | 'a' ) ( 'T' | 't' ) ( 'E' | 'e' )
DATETIME ::= ( 'D' | 'd' ) ( 'A' | 'a' ) ( 'T' | 't' ) ( 'E' | 'e' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'M' | 'm' ) ( 'E' | 'e' )
LOCALDATETIME
::= ( 'L' | 'l' ) ( 'O' | 'o' ) ( 'C' | 'c' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'D' | 'd' ) ( 'A' | 'a' ) ( 'T' | 't' ) ( 'E' | 'e' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'M' | 'm' ) ( 'E' | 'e' )
TIME ::= ( 'T' | 't' ) ( 'I' | 'i' ) ( 'M' | 'm' ) ( 'E' | 'e' )
LOCALTIME
::= ( 'L' | 'l' ) ( 'O' | 'o' ) ( 'C' | 'c' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'M' | 'm' ) ( 'E' | 'e' )
DURATION ::= ( 'D' | 'd' ) ( 'U' | 'u' ) ( 'R' | 'r' ) ( 'A' | 'a' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'O' | 'o' ) ( 'N' | 'n' )
BINARY ::= ( 'B' | 'b' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'A' | 'a' ) ( 'R' | 'r' ) ( 'Y' | 'y' )

MULTISET ::= ( 'M' | 'm' ) ( 'U' | 'u' ) ( 'L' | 'l' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'S' | 's' ) ( 'E' | 'e' ) ( 'T' | 't' )
SET ::= ( 'S' | 's' ) ( 'E' | 'e' ) ( 'T' | 't' )
LIST ::= ( 'L' | 'l' ) ( 'I' | 'i' ) ( 'S' | 's' ) ( 'T' | 't' )
LISTD ::= ( 'L' | 'l' ) ( 'I' | 'i' ) ( 'S' | 's' ) ( 'T' | 't' ) ( 'D' | 'd' )
STRUCT ::= ( 'S' | 's' ) ( 'T' | 't' ) ( 'R' | 'r' ) ( 'U' | 'u' ) ( 'C' | 'c' ) ( 'T' | 't' )
/* END CASE-INSENSITIVE NAMES */

COMMENT ::= '#' [^#xd#xa#xc]*
STRING ::= '"' ([^"\#xd#xa] | "'" | '\"')* '"'
STRING ::= '"' ( [^"\#xd#xa] | "'" | '\"' )* '"'
UNSIGNED_INT
::= [0-9]*
::= [0-9]+
ALNUMPLUS
::= [a-zA-Z_][a-zA-Z0-9_]*
WS ::= ([#x20#x9#xa])+
::= [a-zA-Z_] [a-zA-Z0-9_]*
WS ::= [ #x9#xa]+
34 changes: 26 additions & 8 deletions yarspg/YARSpg.g4
Original file line number Diff line number Diff line change
Expand Up @@ -198,31 +198,38 @@ value_schema
;

primitive_value_schema
// NUMBER
: DECIMAL
| SMALLINT
| INTEGER
| UINTEGER
| BIGINT
| FLOAT
| REAL
| DOUBLE
// BOOL
| BOOL
// STRING
| STRING_TYPE
// DATETYPE
| STRINGT
| DATE
| DATETIME
| DATETIME
| LOCALDATETIME
| TIME
| LOCALTIME
| DURATION
| BINARY
| ALNUMPLUS
;

complex_value_schema
: set_schema
: multiset_schema
| set_schema
| list_schema
| listd_schema
| struct_schema
;

multiset_schema
: MULTISET '(' (primitive_value_schema | set_schema) NULL? cardinality? ')' meta_prop_schema?
;

set_schema
: SET '(' (primitive_value_schema | set_schema) NULL? cardinality? ')' meta_prop_schema?
;
Expand All @@ -231,6 +238,10 @@ list_schema
: LIST '(' (primitive_value_schema | list_schema) NULL? cardinality? ')' meta_prop_schema?
;

listd_schema
: LISTD '(' (primitive_value_schema | list_schema) NULL? cardinality? ')' meta_prop_schema?
;

struct_schema
: STRUCT '(' (primitive_value_schema | struct_schema) NULL? cardinality? ')' meta_prop_schema?
;
Expand Down Expand Up @@ -264,19 +275,26 @@ OPTIONAL: ( 'O' | 'o' ) ( 'P' | 'p' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'O' | 'o' )
DECIMAL: ( 'D' | 'd' ) ( 'E' | 'e' ) ( 'C' | 'c' ) ( 'I' | 'i' ) ( 'M' | 'm' ) ( 'A' | 'a' ) ( 'L' | 'l' );
SMALLINT: ( 'S' | 's' ) ( 'M' | 'm' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'L' | 'l' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'T' | 't' );
INTEGER: ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'T' | 't' ) ( 'E' | 'e' ) ( 'G' | 'g' ) ( 'E' | 'e' ) ( 'R' | 'r' );
UINTEGER: ( 'U' | 'u' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'T' | 't' ) ( 'E' | 'e' ) ( 'G' | 'g' ) ( 'E' | 'e' ) ( 'R' | 'r' );
BIGINT: ( 'B' | 'b' ) ( 'I' | 'i' ) ( 'G' | 'g' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'T' | 't' );
FLOAT: ( 'F' | 'f' ) ( 'L' | 'l' ) ( 'O' | 'o' ) ( 'A' | 'a' ) ( 'T' | 't' );
REAL: ( 'R' | 'r' ) ( 'E' | 'e' ) ( 'A' | 'a' ) ( 'L' | 'l' );
DOUBLE: ( 'D' | 'd' ) ( 'O' | 'o' ) ( 'U' | 'u' ) ( 'B' | 'b' ) ( 'L' | 'l' ) ( 'E' | 'e' );
BOOL: ( 'B' | 'b' ) ( 'O' | 'o' ) ( 'O' | 'o' ) ( 'L' | 'l' );
STRING_TYPE: ( 'S' | 's' ) ( 'T' | 't' ) ( 'R' | 'r' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'G' | 'g' );
STRINGT: ( 'S' | 's' ) ( 'T' | 't' ) ( 'R' | 'r' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'G' | 'g' );
DATE: ( 'D' | 'd' ) ( 'A' | 'a' ) ( 'T' | 't' ) ( 'E' | 'e' );
DATETIME: ( 'D' | 'd' ) ( 'A' | 'a' ) ( 'T' | 't' ) ( 'E' | 'e' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'M' | 'm' ) ( 'E' | 'e' );
LOCALDATETIME: ( 'L' | 'l' ) ( 'O' | 'o' ) ( 'C' | 'c' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'D' | 'd' ) ( 'A' | 'a' ) ( 'T' | 't' ) ( 'E' | 'e' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'M' | 'm' ) ( 'E' | 'e' );
TIME: ( 'T' | 't' ) ( 'I' | 'i' ) ( 'M' | 'm' ) ( 'E' | 'e' );
LOCALTIME: ( 'L' | 'l' ) ( 'O' | 'o' ) ( 'C' | 'c' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'M' | 'm' ) ( 'E' | 'e' );
DURATION: ( 'D' | 'd' ) ( 'U' | 'u' ) ( 'R' | 'r' ) ( 'A' | 'a' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'O' | 'o' ) ( 'N' | 'n' );
BINARY: ( 'B' | 'b' ) ( 'I' | 'i' ) ( 'N' | 'n' ) ( 'A' | 'a' ) ( 'R' | 'r' ) ( 'Y' | 'y' );

// complex datetypes
MULTISET: ( 'M' | 'm' ) ( 'U' | 'u' ) ( 'L' | 'l' ) ( 'T' | 't' ) ( 'I' | 'i' ) ( 'S' | 's' ) ( 'E' | 'e' ) ( 'T' | 't' );
SET: ( 'S' | 's' ) ( 'E' | 'e' ) ( 'T' | 't' );
LIST: ( 'L' | 'l' ) ( 'I' | 'i' ) ( 'S' | 's' ) ( 'T' | 't' );
LISTD: ( 'L' | 'l' ) ( 'I' | 'i' ) ( 'S' | 's' ) ( 'T' | 't' ) ( 'D' | 'd' );
STRUCT: ( 'S' | 's' ) ( 'T' | 't' ) ( 'R' | 'r' ) ( 'U' | 'u' ) ( 'C' | 'c' ) ( 'T' | 't' );
// END CASE-INSENSITIVE NAMES

Expand Down
17 changes: 10 additions & 7 deletions yarspg/examples/test-example.yarspg
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,22 @@ S(ABC434)-({"bbb23b"}["bbbd32d": Bool, "value": String OPTIONAL])-(JSk342)
S(ad234)-({"bbb23b"}[$var_234e_schema, "value": String NULL])-(gr525)
S(asf32)-({"bbb23b"}["bbbd32d": Bool UNIQUE, "value": String NULL])-(wef32)
S(asf323)-({"bbb23b"}["bbbd32d": Bool UNIQUE, "value": List(String) NULL])-(wef323)
S(asf3233)-({"bbb23b"}["bbbd32d": Bool UNIQUE @<"dfwe": Integer NULL>, "value": List(String) NULL @<"efe": List(List(String))>])-(wef3234)
S(asf3233)-({"bbb23b"}["bbbd32d": Bool UNIQUE @<"dfwe": SInteger NULL>, "value": List(String) NULL @<"efe": List(List(String))>])-(wef3234)
S(asf3245)-({"bbb23b"}["bbbd32d": Bool UNIQUE, "value": List(String) OPTIONAL])-(wef3245)
S(asf3245)-({"bbb23b"}["bbbd32d": Bool UNIQUE, "value": List(String MIN 4) OPTIONAL])-(wef3245)
S(asf3244)-({"bbb23b"}["bbbd32d": Bool UNIQUE, "value": List(String) OPTIONAL @<"psod": Struct(Integer) OPTIONAL>])-(wef3245)
S(asf3244)-({"bbb23b"}["bbbd32d": Bool UNIQUE, "value": List(String) OPTIONAL @<"psod": Struct(SInteger) OPTIONAL>])-(wef3245)
S(asf3244)-({"bbb23b"}["bbbd32d": Bool UNIQUE, "value": List(String) OPTIONAL @<"psod": Struct(Integer MAX 3) OPTIONAL>])-(wef3245)
(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"]

S(f23)-({"label"}["date": Date])->(f321)
S(g34g2)-({"label2"}["time": Time])->(fwef334)
S(g34g2)-({"label2"}["time": LocalTime])->(fwef334)
S(weg12)-({"label3"}["timezp": Time])->(gerg534)
S(Adg3)-({"label4"}["timezm": Time])->(saf24)
S(Adg35)-({"label4"}["timezm": Time OPTIONAL])->(saf244)
S(wf23)-({"label5"}["datetime": DateTime])->(erg32)
S(wf2343)-({"label5"}["datetime": DateTime @<"info": String>])->(erg3264)
S(sdaf56)-({"label5"}["datetime": DateTime UNIQUE])->(dsf53)
S(wf23)-({"label5"}["datetime": LocalDateTime])->(erg32)
S(wf2343)-({"label5"}["datetime": LocalDateTime @<"info": String>])->(erg3264)
S(sdaf56)-({"label5"}["datetime": LocalDateTime UNIQUE])->(dsf53)
S(sas34)-({"label6"}["datetimetzp": DateTime])->(sdag654)
S(asdg41)-({"label7"}["datetimetzm": DateTime])->(asv94)
(ABC)-({"label"}["date": "1999-01-01"])->(XYZ)
Expand All @@ -180,4 +180,7 @@ S(asdg41)-({"label7"}["datetimetzm": DateTime])->(asv94)
(ABC8)-({"label7"}["datetimetzmminus": "-0003-01-05T11:15:32+05:00"])->(XYZ8)
(ABC9)-({"label7"}["datetimetzmminusms": "-0003-01-05T11:15:32.432+05:00"])->(XYZ9)
(ABC10)-({"label7"}["datetimetzmminusms2": "-0003-01-05T11:15:32.5+05:00"])->(XYZ10)
(ABC10)-({"label7"}["datetimetzmms3": "2020-01-07T14:15:32.24+08:00"])->(XYZ10)
(ABC10)-({"label7"}["datetimetzmms3": "2020-01-07T14:15:32.24+08:00"])->(XYZ10)
S(asdg41)-({"label7"}["test": MyType])->(asv94)

# Add DURATION, BINARY, SMALLINT, BIGINT examples

0 comments on commit 4a52868

Please sign in to comment.