Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SLI-0088] The a keyword is not recognized by the grammar #88

Open
thewillyhuman opened this issue Apr 23, 2020 · 4 comments
Open

[SLI-0088] The a keyword is not recognized by the grammar #88

thewillyhuman opened this issue Apr 23, 2020 · 4 comments

Comments

@thewillyhuman
Copy link
Member

thewillyhuman commented Apr 23, 2020

Introduction

In turtle the keyword a was included as alias of rdf: type. The language of shapes expressions adopted it and therefore shex-lite should support it too.

Current Behavior

Currently for the scheme (input_correct_java_schema_user_car_1.shexl),

prefix : <example.org>
prefix xsd: <schema.org>
prefix foaf: <foaf.org>

:User {
    a		foaf:person ;
    :name       xsd:string  ;
    :surname    xsd:string  ;
    :age        xsd:integer ;
    :knows      @:User *
}

: Car {
    :plateNumber    xsd:string  ;
    :owner          @:User
}

If we execute java -jar shexlc-2.0-beta.jar input_correct_java_schema_user_car_1.shexl the compiler produces the following output:

Output:

line 6:7 extraneous input 'foaf' expecting ':'
line 6:19 extraneous input ';' expecting {':', 'iri', '.', 'nonliteral', '[', 'bnode', 'literal', '@', LABEL, IRI_LITERAL, REAL_LITERAL, STRING_LITERAL}
line 7:28 extraneous input ';' expecting {':', 'iri', '.', 'nonliteral', '[', 'bnode', 'literal', '@', LABEL, IRI_LITERAL, REAL_LITERAL, STRING_LITERAL}
line 8:28 extraneous input ';' expecting {':', 'iri', '.', 'nonliteral', '[', 'bnode', 'literal', '@', LABEL, IRI_LITERAL, REAL_LITERAL, STRING_LITERAL}
line 9:28 extraneous input ';' expecting {':', 'iri', '.', 'nonliteral', '[', 'bnode', 'literal', '@', LABEL, IRI_LITERAL, REAL_LITERAL, STRING_LITERAL}
line 10:16 extraneous input '@' expecting {':', '}', ';', LABEL, IRI_LITERAL}
line 10:23 mismatched input '*' expecting {':', 'iri', '.', 'nonliteral', '[', 'bnode', 'literal', '@', LABEL, IRI_LITERAL, REAL_LITERAL, STRING_LITERAL}
Exception in thread "main" java.lang.NullPointerException
        at es.weso.shexlc.syntactic.parser.ConstraintTripleExprPsr.getParseResult(ConstraintTripleExprPsr.scala:45)
        at es.weso.shexlc.syntactic.Syn01ASTBuilderVisitor.visitConstraint_triple_expr(Syn01ASTBuilderVisitor.scala:78)
        at es.weso.shexlc.syntactic.Syn01ASTBuilderVisitor.visitConstraint_triple_expr(Syn01ASTBuilderVisitor.scala:30)
        at es.weso.shexlc.syntactic.generated.Shexl2Parser$Constraint_triple_exprContext.accept(Shexl2Parser.java:1250)
        at es.weso.shexlc.syntactic.parser.ConstraintBlockTripleExprPsr.$anonfun$getParseResult$1(ConstraintBlockTripleExprPsr.scala:50)
        at scala.collection.Iterator$$anon$9.next(Iterator.scala:573)
        at scala.collection.mutable.Growable.addAll(Growable.scala:62)
        at scala.collection.mutable.Growable.addAll$(Growable.scala:59)
        at scala.collection.mutable.ArrayBuffer.addAll(ArrayBuffer.scala:147)
        at scala.collection.mutable.ArrayBuffer.addAll(ArrayBuffer.scala:40)
        at scala.collection.mutable.ArrayBuffer$.from(ArrayBuffer.scala:265)
        at scala.collection.mutable.ArrayBuffer$.from(ArrayBuffer.scala:253)
        at scala.collection.IterableOps.map(Iterable.scala:672)
        at scala.collection.IterableOps.map$(Iterable.scala:672)
        at scala.collection.AbstractIterable.map(Iterable.scala:921)
        at es.weso.shexlc.syntactic.parser.ConstraintBlockTripleExprPsr.getParseResult(ConstraintBlockTripleExprPsr.scala:50)
        at es.weso.shexlc.syntactic.Syn01ASTBuilderVisitor.visitConstraint_block_triple_expr(Syn01ASTBuilderVisitor.scala:74)
        at es.weso.shexlc.syntactic.Syn01ASTBuilderVisitor.visitConstraint_block_triple_expr(Syn01ASTBuilderVisitor.scala:30)
        at es.weso.shexlc.syntactic.generated.Shexl2Parser$Constraint_block_triple_exprContext.accept(Shexl2Parser.java:1170)
        at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
        at es.weso.shexlc.syntactic.generated.Shexl2BaseVisitor.visitConstraint_expr(Shexl2BaseVisitor.java:118)
        at es.weso.shexlc.syntactic.generated.Shexl2Parser$Constraint_exprContext.accept(Shexl2Parser.java:983)
        at es.weso.shexlc.syntactic.parser.ShapeDefStmtPsr.getParseResult(ShapeDefStmtPsr.scala:47)
        at es.weso.shexlc.syntactic.Syn01ASTBuilderVisitor.visitShape_def_stmt(Syn01ASTBuilderVisitor.scala:53)
        at es.weso.shexlc.syntactic.Syn01ASTBuilderVisitor.visitShape_def_stmt(Syn01ASTBuilderVisitor.scala:30)
        at es.weso.shexlc.syntactic.generated.Shexl2Parser$Shape_def_stmtContext.accept(Shexl2Parser.java:557)
        at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
        at es.weso.shexlc.syntactic.generated.Shexl2BaseVisitor.visitDefinition_stmt(Shexl2BaseVisitor.java:41)
        at es.weso.shexlc.syntactic.generated.Shexl2Parser$Definition_stmtContext.accept(Shexl2Parser.java:320)
        at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
        at es.weso.shexlc.syntactic.generated.Shexl2BaseVisitor.visitStatement(Shexl2BaseVisitor.java:27)
        at es.weso.shexlc.syntactic.generated.Shexl2Parser$StatementContext.accept(Shexl2Parser.java:200)
        at es.weso.shexlc.syntactic.parser.SchemaPsr.$anonfun$getParseResult$1(SchemaPsr.scala:44)
        at scala.collection.Iterator$$anon$9.next(Iterator.scala:573)
        at scala.collection.mutable.Growable.addAll(Growable.scala:62)
        at scala.collection.mutable.Growable.addAll$(Growable.scala:59)
        at scala.collection.mutable.ArrayBuffer.addAll(ArrayBuffer.scala:147)
        at scala.collection.mutable.ArrayBuffer.addAll(ArrayBuffer.scala:40)
        at scala.collection.mutable.ArrayBuffer$.from(ArrayBuffer.scala:265)
        at scala.collection.mutable.ArrayBuffer$.from(ArrayBuffer.scala:253)
        at scala.collection.IterableOps.map(Iterable.scala:672)
        at scala.collection.IterableOps.map$(Iterable.scala:672)
        at scala.collection.AbstractIterable.map(Iterable.scala:921)
        at es.weso.shexlc.syntactic.parser.SchemaPsr.getParseResult(SchemaPsr.scala:44)
        at es.weso.shexlc.syntactic.Syn01ASTBuilderVisitor.visitSchema(Syn01ASTBuilderVisitor.scala:33)
        at es.weso.shexl.DefaultShExLCompiler.buildAST(DefaultShExLCompiler.scala:105)
        at es.weso.shexl.DefaultShExLCompiler.$anonfun$compile$1(DefaultShExLCompiler.scala:82)
        at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:553)
        at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:551)
        at scala.collection.AbstractIterable.foreach(Iterable.scala:921)
        at es.weso.shexl.DefaultShExLCompiler.compile(DefaultShExLCompiler.scala:75)
        at es.weso.shexl.cli.ShExLiteCLI$.run(ShExLiteCLI.scala:51)
        at es.weso.shexl.cli.ShExLiteCLI$.run(ShExLiteCLI.scala:29)
        at org.backuity.clist.CliMain.$anonfun$runWith$1(CliMain.scala:14)
        at org.backuity.clist.Parser.$anonfun$withCommand$1(Parser.scala:156)
        at org.backuity.clist.Parser.withParsingException(Parser.scala:199)
        at org.backuity.clist.Parser.withCommand(Parser.scala:154)
        at org.backuity.clist.CliMain.runWith(CliMain.scala:14)
        at org.backuity.clist.CliMain.main(CliMain.scala:6)
        at es.weso.shexl.cli.ShExLiteCLI.main(ShExLiteCLI.scala)

Expected Behavior

Typically, the grammar would accept this keyword and then be automatically replaced by the compiler with rdf: type.

@thewillyhuman
Copy link
Member Author

thewillyhuman commented Apr 23, 2020

A question that arises with this proposal is what to do with the prefix rdf. In the current implementation the rdf prefix is ​​not declared so a simple substitution would fail the semantic validation of the schema.

It would be nice to know how they deal with this problem in other parsers. I know that @labra and @mistermboy implemented a parser for this, so do you have any hint? Also @DaniFdezAlvarez any idea?

@thewillyhuman
Copy link
Member Author

Final Decision

According to the central team, the following solution is chosen:

  • When the parser finds a keyword a it will automatically insert a new prefix invocation node with a static prefix definition representing the reserved prefix rdf with value <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. In this way, being the hidden prefix for the symbol table allows others to be entered with the alias rdf.

@thewillyhuman
Copy link
Member Author

Problems Encountered

By using antlr it skips blanks and other characters so there is no diference between:

a:User {
  a  :Person  # Should compile.
}

And

a:user {
 a:Person # Should fail as this is not a valid triple constraint.
}

I've tried with the following regular expression:

A_KEYWORD
 : ~':''a'~':' // Every 'a' without heading ':' and trailing ':'.
 ;

But for the grammar developed there is no way to diferentitate betwen a :Person and a:Person.

@thewillyhuman
Copy link
Member Author

This issue will be solved after June 15. Therefore it goes to defered status.

@thewillyhuman thewillyhuman added status/deferred Deferred because it does not meet the goals of the upcoming major release. Will be considered later. and removed status/active-review labels May 2, 2020
@thewillyhuman thewillyhuman removed their assignment Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant