Skip to content

Commit

Permalink
~Bulk test of sequalizer syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
AjaniBilby committed Jul 19, 2023
1 parent 481b70f commit acb1721
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 22 deletions.
51 changes: 31 additions & 20 deletions test/bnf/sequalize.bnf
@@ -1,31 +1,42 @@
# BNF from sequelize due to issue #8
# This package does not own any rights to this BNF
# After updating this file run:
# yarn run build-bnf
# or
# npx bnf-compile ./packages/core/src/utils/bnf/syntax.bnf
# To update the compiled artifacts

program ::= switcher+ ;

switcher ::= ( sw_attr | sw_json ) nl ;
sw_attr ::= "attr: " attribute ;
sw_json ::= "json: " partialJsonPath ;
nl ::= "\r\n" | "\n";


# Entry points
## Used when parsing the attribute
attribute ::= ( ...association | ...identifier ) jsonpath? castormodifiers?;
attribute ::= attributeBegin jsonAccess* transform* ;
attributeBegin ::= association | ...identifier ;

## Used when parsing a nested JSON path used inside of an attribute
## Difference with "attribute" is in the first part. Instead of accepting:
## $association.attribute$ & attribute
## It accepts:
## key, "quotedKey", and [0] (index access)
partialjsonpath ::= ( ...indexaccess | ...key ) jsonpath? castormodifiers? ;
partialJsonPath ::= key jsonAccess* transform* ;

# Internals
identifier ::= ( "A"->"Z" | "a"->"z" | digit | "_" )+ ;
digit ::= "0"->"9" ;
number ::= ...digit+ ;
association ::= %"$" identifier ("." identifier)* %"$" ;
jsonpath ::= ( ...indexaccess | ...keyaccess )+ ;
indexaccess ::= %"[" number %"]" ;
identifier ::= ( "A"->"Z"+ | "a"->"z"+ | "0"->"9"+ | "_" )+ ;
digit ::= "0"->"9" ;
number ::= ...digit+ ;
association ::= %"$" ...identifier (%"." ...identifier)* %"$" ;
jsonAccess ::= indexAccess | keyAccess ;
indexAccess ::= %"[" ...number %"]" ;
keyAccess ::= %"." ...key ;

keyaccess ::= %"." key ;
nonemptystring ::= ...(%"\\" (anyexceptquoteorbackslash | escapedcharacter)+ %"\\") ;
key ::= nonemptystring | ( "A"->"Z" | "a"->"z" | digit | "_" | "-" )+ ;
escapedcharacter ::= %"\\\\" ( "\\" | "\\\\" );
any ::= !"" ;
anyexceptquoteorbackslash ::= !("\\" | "\\\\");
castormodifiers ::= (...cast | ...modifier)+;
cast ::= %"::" identifier ;
modifier ::= %":" identifier ;
# path segments accept dashes without needing to be quoted
key ::= nonEmptyString | identifier ;
nonEmptyString ::= ...(%"\"" (anyExceptQuoteOrBackslash | escapedCharacter)+ %"\"") ;
escapedCharacter ::= %"\\" ( "\"" | "\\" );
anyExceptQuoteOrBackslash ::= !("\"" | "\\");
transform ::= cast | modifier ;
cast ::= %"::" ...identifier ;
modifier ::= %":" ...identifier ;
7 changes: 5 additions & 2 deletions test/index.js
Expand Up @@ -51,9 +51,12 @@ async function SampleTests() {
for (const file of files) {
const data = fs.readFileSync(`${dir}/${file}`, "utf8");
try {
const syntax = Parser.Parse_Program(data, false);
const syntax = Parser.Parse_Program(data, true);
if (syntax instanceof Shared.ParseError) throw syntax;
if (syntax.isPartial) throw new Error("Partial Match");
if (syntax.isPartial) throw new Shared.ParseError(
"Partial Match",
new Shared.ReferenceRange(syntax.root.ref.end, syntax.reach)
).toString();;

console.log(` ${chalk.green("PASS")} ${file}`);
} catch (e) {
Expand Down
77 changes: 77 additions & 0 deletions test/sample/sequalize/bulk.txt
@@ -0,0 +1,77 @@
attr: data.key
attr: jsonAttr.nested
attr: id
attr: name
attr: creationYear
attr: deletedAt
attr: value
attr: date
attr: uid::text
attr: age
attr: bar
attr: duration
attr: username
attr: data.email
attr: firstName
attr: test_user_id
attr: public
attr: $User.id_user$
attr: user_id
attr: $Company.owner_id$
attr: metadata
attr: metadata.pg_rating.dk
attr: profile.id.0.1
attr: metadata.pg_rating.is
attr: profile
attr: property
attr: profile.id
attr: foo
attr: email
attr: companyId
attr: project_id
attr: status
attr: scopeId
attr: data
attr: $postaliasname.title$
attr: intAttr1
attr: dateAttr
attr: stringAttr
attr: binaryAttr
attr: stringAttr::integer
attr: $intAttr1$
attr: $stringAttr$::integer
attr: $association.attribute$
attr: $association.attribute$::integer
attr: booleanAttr
attr: nullableIntAttr
attr: intAttr1::integer
attr: $intAttr1$::integer
attr: intAttr1::text
attr: jsonAttr
attr: jsonAttr.nested.twice
attr: $jsonAttr$.nested
attr: $association.jsonAttr$.nested
attr: jsonAttr.nested::STRING
attr: $association.jsonAttr$.nested::STRING
attr: $association.jsonAttr$.nested.deep::STRING
attr: $jsonAttr$
attr: jsonAttr.nested.attribute
attr: jsonAttr.0
attr: jsonAttr[0]
attr: jsonAttr.0.attribute
attr: jsonAttr[0].nested.attribute
attr: aliasedJsonAttr.nested.attribute
attr: jsonAttr:unquote
attr: jsonAttr.key:unquote
attr: jsonAttr.nested.key:unquote
attr: jsonAttr[0]:unquote
attr: $bar$
attr: foo::bar
attr: foo::bar::baz
attr: foo.bar
attr: foo:unquote
attr: foo:unquote:unquote
attr: textAttr::json:unquote::integer
json: foo.bar
json: twice
json: jsonPath

0 comments on commit acb1721

Please sign in to comment.