diff --git a/src/main/antlr/Turtle.g4 b/src/main/antlr/Turtle.g4 index ec73f7ca3..0741d90f0 100644 --- a/src/main/antlr/Turtle.g4 +++ b/src/main/antlr/Turtle.g4 @@ -180,23 +180,50 @@ EXPONENT : ('e' | 'E') ('+' | '-' )? ('0' .. '9')+ ; -// "'''" (("'" | "''")? ([^'\] | ECHAR | UCHAR))* "'''" STRING_LITERAL_LONG_SINGLE_QUOTE : '\'\'\'' ( + ( '\'' | '\'\'' )? + SINGLE_QUOTE_LONG_LITERAL_CONTENT + )+ '\'\'\'' + | '\'\'\'' ( + SINGLE_QUOTE_LONG_LITERAL_CONTENT + ( '\'' | '\'\'' )? + )+ '\'\'\'' + | '\'\'\'' ( ( '\'' | '\'\'' ) - | ( ~['\\] | ECHAR | UCHAR | '"') - )+ '\'\'\'' + SINGLE_QUOTE_LONG_LITERAL_CONTENT+ + ( '\'' | '\'\'' ) + )+ '\'\'\'' | '\'\'\'\'\'\'' + | '\'\'\'\'\'\'\'' + | '\'\'\'\'\'\'\'\'' ; STRING_LITERAL_LONG_QUOTE : '"""' ( + ( '"' | '""' )? + QUOTE_LONG_LITERAL_CONTENT + )+ '"""' + | '"""' ( + QUOTE_LONG_LITERAL_CONTENT + ( '"' | '""' )? + )+ '"""' + | '"""' ( + ( '"' | '""' ) + QUOTE_LONG_LITERAL_CONTENT+ ( '"' | '""' ) - | ( ~["\\] | ECHAR | UCHAR | '\'') - )+ '"""' + )+ '"""' | '""""""' + | '"""""""' + | '""""""""' ; +QUOTE_LONG_LITERAL_CONTENT + : ( ~["\\] | ECHAR | UCHAR ) ; + +SINGLE_QUOTE_LONG_LITERAL_CONTENT + : ( ~['\\] | ECHAR | UCHAR ) ; + STRING_LITERAL_QUOTE : '"' (~["\\\r\n] | ECHAR | UCHAR)* '"' ; diff --git a/src/test/java/fr/inria/corese/core/next/impl/io/parser/turtle/TurtleParserTest.java b/src/test/java/fr/inria/corese/core/next/impl/io/parser/turtle/TurtleParserTest.java index 1931c8570..bac9a85c4 100644 --- a/src/test/java/fr/inria/corese/core/next/impl/io/parser/turtle/TurtleParserTest.java +++ b/src/test/java/fr/inria/corese/core/next/impl/io/parser/turtle/TurtleParserTest.java @@ -1,6 +1,7 @@ package fr.inria.corese.core.next.impl.io.parser.turtle; import fr.inria.corese.core.next.api.Model; +import fr.inria.corese.core.next.api.Statement; import fr.inria.corese.core.next.api.ValueFactory; import fr.inria.corese.core.next.api.io.parser.RDFParser; import fr.inria.corese.core.next.impl.common.vocabulary.RDFS; @@ -8,9 +9,15 @@ import fr.inria.corese.core.next.impl.temp.CoreseModel; import org.junit.jupiter.api.Test; + + import java.io.StringReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Unit tests for the ANTLRTurtle class. @@ -20,6 +27,8 @@ */ public class TurtleParserTest { + private static final Logger logger = LoggerFactory.getLogger(TurtleParserTest.class); + private ValueFactory factory = new CoreseAdaptedValueFactory(); @Test @@ -75,9 +84,10 @@ public void testTripleQuoteLiteralWithDoubleQuoteIncludedTextBeforeAndAfter() { @Test public void testTripleQuoteLiteralWithDoubleQuoteIncludedNoText() { - String turtle = "@prefix rdfs: .\n" + - "<#0214> \n" + - " rdfs:comment \"\"\"\"abc\"\"\"\" ."; + String turtle = """ + @prefix rdfs: . + <#0214>\s + rdfs:comment ""\""abc""\"" ."""; Model model = new CoreseModel(); RDFParser parser = new TurtleParser(model, factory, new TurtleParserOptions.Builder().baseIRI("http://inria.fr/").build()); @@ -86,4 +96,34 @@ public void testTripleQuoteLiteralWithDoubleQuoteIncludedNoText() { model.contains(factory.createIRI("http://inria.fr/#0214"), RDFS.comment.getIRI(), factory.createLiteral("\"abc\"")); } + @Test + public void testRdfaManifest() { + String turtle = """ + @base . + @prefix rdf: . + @prefix rdfs: . + + <#0006> rdfs:label \"""Test 0006: @rel and @rev\"""; + rdfs:comment \"""Tests @rev and @rel together, with the object being specified by @href, ignoring content\"""; + . + """; + + Model model = new CoreseModel(); + RDFParser parser = new TurtleParser(model, factory, new TurtleParserOptions.Builder().baseIRI("http://inria.fr/").build()); + parser.parse(new StringReader(turtle)); + + Model refModel = new CoreseModel(); + refModel.add(factory.createIRI("http://rdfa.info/test-suite/test-cases/rdfa1.1/xml/manifest#0006"), RDFS.label.getIRI(), factory.createLiteral("Test 0006: @rel and @rev")); + refModel.add(factory.createIRI("http://rdfa.info/test-suite/test-cases/rdfa1.1/xml/manifest#0006"), RDFS.comment.getIRI(), factory.createLiteral("Tests @rev and @rel together, with the object being specified by @href, ignoring content")); + + for(Statement stat : model) { + assertTrue(refModel.contains(stat)); + } + for(Statement stat : refModel) { + assertTrue(model.contains(stat)); + } + + assertEquals(refModel.size(), model.size()); + } + }