|
| 1 | +grammar SHACLC; |
| 2 | + |
| 3 | +shaclDoc : directive* (nodeShape|shapeClass)* EOF; |
| 4 | + |
| 5 | +directive : baseDecl | importsDecl | prefixDecl ; |
| 6 | +baseDecl : KW_BASE IRIREF ; |
| 7 | +importsDecl : KW_IMPORTS IRIREF ; |
| 8 | +prefixDecl : KW_PREFIX PNAME_NS IRIREF ; |
| 9 | + |
| 10 | +shapeClass : KW_SHAPE_CLASS iri nodeShapeBody ; |
| 11 | +nodeShape : KW_SHAPE iri targetClass? nodeShapeBody ; |
| 12 | +nodeShapeBody : '{' constraint* '}'; |
| 13 | +targetClass : '->' iri+ ; |
| 14 | + |
| 15 | +constraint : ( nodeOr+ | propertyShape ) '.' ; |
| 16 | +nodeOr : nodeNot ( '|' nodeNot) * ; |
| 17 | +nodeNot : negation? nodeValue ; |
| 18 | +nodeValue : nodeParam '=' iriOrLiteralOrArray ; |
| 19 | + |
| 20 | +propertyShape : path ( propertyCount | propertyOr )* ; |
| 21 | +propertyOr : propertyNot ( '|' propertyNot) * ; |
| 22 | +propertyNot : negation? propertyAtom ; |
| 23 | +propertyAtom : propertyType | nodeKind | shapeRef | propertyValue | nodeShapeBody ; |
| 24 | +propertyCount : '[' propertyMinCount '..' propertyMaxCount ']' ; |
| 25 | +propertyMinCount : INTEGER ; |
| 26 | +propertyMaxCount : (INTEGER | '*') ; |
| 27 | +propertyType : iri ; |
| 28 | +nodeKind : 'BlankNode' | 'IRI' | 'Literal' | 'BlankNodeOrIRI' | 'BlankNodeOrLiteral' | 'IRIOrLiteral' ; |
| 29 | +shapeRef : ATPNAME_LN | ATPNAME_NS | '@' IRIREF ; |
| 30 | +propertyValue : propertyParam '=' iriOrLiteralOrArray ; |
| 31 | +negation : '!' ; |
| 32 | + |
| 33 | +path : pathAlternative ; |
| 34 | +pathAlternative : pathSequence ( '|' pathSequence )* ; |
| 35 | +pathSequence : pathEltOrInverse ( '/' pathEltOrInverse )* ; |
| 36 | +pathElt : pathPrimary pathMod? ; |
| 37 | +pathEltOrInverse : pathElt | pathInverse pathElt ; |
| 38 | +pathInverse : '^' ; |
| 39 | +pathMod : '?' | '*' | '+' ; |
| 40 | +pathPrimary : iri | '(' path ')' ; |
| 41 | + |
| 42 | +iriOrLiteralOrArray : iriOrLiteral | array ; |
| 43 | +iriOrLiteral : iri | literal ; |
| 44 | + |
| 45 | +iri : IRIREF | prefixedName ; |
| 46 | +prefixedName : PNAME_LN | PNAME_NS ; |
| 47 | + |
| 48 | +literal : rdfLiteral | numericLiteral | booleanLiteral ; |
| 49 | +booleanLiteral : KW_TRUE | KW_FALSE ; |
| 50 | +numericLiteral : INTEGER | DECIMAL | DOUBLE ; |
| 51 | +rdfLiteral : string (LANGTAG | '^^' datatype)? ; |
| 52 | +datatype : iri ; |
| 53 | +string : STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2 | STRING_LITERAL1 | STRING_LITERAL2 ; |
| 54 | + |
| 55 | +array : '[' iriOrLiteral* ']' ; |
| 56 | + |
| 57 | +nodeParam : 'targetNode' | 'targetObjectsOf' | 'targetSubjectsOf' | |
| 58 | + 'deactivated' | 'severity' | 'message' | |
| 59 | + 'class' | 'datatype' | 'nodeKind' | |
| 60 | + 'minExclusive' | 'minInclusive' | 'maxExclusive' | 'maxInclusive' | |
| 61 | + 'minLength' | 'maxLength' | 'pattern' | 'flags' | 'languageIn' | |
| 62 | + 'equals' | 'disjoint' | |
| 63 | + 'closed' | 'ignoredProperties' | 'hasValue' | 'in' ; |
| 64 | + |
| 65 | +propertyParam : 'deactivated' | 'severity' | 'message' | |
| 66 | + 'class' | 'datatype' | 'nodeKind' | |
| 67 | + 'minExclusive' | 'minInclusive' | 'maxExclusive' | 'maxInclusive' | |
| 68 | + 'minLength' | 'maxLength' | 'pattern' | 'flags' | 'languageIn' | 'uniqueLang' | |
| 69 | + 'equals' | 'disjoint' | 'lessThan' | 'lessThanOrEquals' | |
| 70 | + 'qualifiedValueShape' | 'qualifiedMinCount' | 'qualifiedMaxCount' | 'qualifiedValueShapesDisjoint' | |
| 71 | + 'closed' | 'ignoredProperties' | 'hasValue' | 'in' ; |
| 72 | + |
| 73 | +// Keywords |
| 74 | +KW_BASE : 'BASE' ; |
| 75 | +KW_IMPORTS : 'IMPORTS' ; |
| 76 | +KW_PREFIX : 'PREFIX' ; |
| 77 | + |
| 78 | +KW_SHAPE_CLASS : 'shapeClass' ; |
| 79 | +KW_SHAPE : 'shape' ; |
| 80 | + |
| 81 | +KW_TRUE : 'true' ; |
| 82 | +KW_FALSE : 'false' ; |
| 83 | + |
| 84 | +// Terminals |
| 85 | +PASS : [ \t\r\n]+ -> skip; |
| 86 | +COMMENT : '#' ~[\r\n]* -> skip; |
| 87 | + |
| 88 | +IRIREF : '<' (~[\u0000-\u0020=<>\"{}|^`\\] | UCHAR)* '>' ; |
| 89 | +PNAME_NS : PN_PREFIX? ':' ; |
| 90 | +PNAME_LN : PNAME_NS PN_LOCAL ; |
| 91 | +ATPNAME_NS : '@' PN_PREFIX? ':' ; |
| 92 | +ATPNAME_LN : '@' PNAME_NS PN_LOCAL ; |
| 93 | +LANGTAG : '@' [a-zA-Z]+ ('-' [a-zA-Z0-9]+)* ; |
| 94 | +INTEGER : [+-]? [0-9]+ ; |
| 95 | +DECIMAL : [+-]? [0-9]* '.' [0-9]+ ; |
| 96 | +DOUBLE : [+-]? ([0-9]+ '.' [0-9]* EXPONENT | '.'? [0-9]+ EXPONENT) ; |
| 97 | +fragment EXPONENT : [eE] [+-]? [0-9]+ ; |
| 98 | +STRING_LITERAL1 : '\'' (~[\u0027\u005C\u000A\u000D] | ECHAR | UCHAR)* '\'' ; |
| 99 | +STRING_LITERAL2 : '"' (~[\u0022\u005C\u000A\u000D] | ECHAR | UCHAR)* '"' ; |
| 100 | +STRING_LITERAL_LONG1: '\'\'\'' (('\'' | '\'\'')? (~[\'\\] | ECHAR | UCHAR))* '\'\'\'' ; |
| 101 | +STRING_LITERAL_LONG2: '"""' (('"' | '""')? (~[\"\\] | ECHAR | UCHAR))* '"""' ; |
| 102 | +fragment UCHAR : '\\u' HEX HEX HEX HEX | '\\U' HEX HEX HEX HEX HEX HEX HEX HEX ; |
| 103 | +fragment ECHAR : '\\' [tbnrf\\\"\'] ; |
| 104 | +fragment WS : [\u0020\u0009\u000D\u000A] ; |
| 105 | +fragment PN_CHARS_BASE: [A-Z] | [a-z] | [\u00C0-\u00D6] | [\u00D8-\u00F6] | [\u00F8-\u02FF] | [\u0370-\u037D] |
| 106 | + | [\u037F-\u1FFF] | [\u200C-\u200D] | [\u2070-\u218F] | [\u2C00-\u2FEF] | [\u3001-\uD7FF] |
| 107 | + | [\uF900-\uFDCF] | [\uFDF0-\uFFFD] |
| 108 | + ; |
| 109 | +fragment PN_CHARS_U : PN_CHARS_BASE | '_' ; |
| 110 | +fragment PN_CHARS : PN_CHARS_U | '-' | [0-9] | [\u00B7] | [\u0300-\u036F] | [\u203F-\u2040] ; |
| 111 | +fragment PN_PREFIX : PN_CHARS_BASE ((PN_CHARS | '.')* PN_CHARS)? ; |
| 112 | +fragment PN_LOCAL : (PN_CHARS_U | ':' | [0-9] | PLX) ((PN_CHARS | '.' | ':' | PLX)* (PN_CHARS | ':' | PLX))? ; |
| 113 | +fragment PLX : PERCENT | PN_LOCAL_ESC ; |
| 114 | +fragment PERCENT : '%' HEX HEX ; |
| 115 | +fragment HEX : [0-9] | [A-F] | [a-f] ; |
| 116 | +fragment PN_LOCAL_ESC: '\\' ('_' | '~' | '.' | '-' | '!' | '$' | '&' | '\'' | '(' | ')' | '*' | '+' | ',' |
| 117 | + | ';' | '=' | '/' | '?' | '#' | '@' | '%') ; |
0 commit comments