/* * (c) Copyright 2009 Andy Seaborne * All rights reserved. */ // http://www.w3.org/TR/owl2-manchester-syntax/ // http://www.w3.org/TR/owl2-syntax/ // http://www.w3.org/TR/owl2-mapping-to-rdf/ // http://www.w3.org/TR/owl2-overview/ options { JAVA_UNICODE_ESCAPE = true ; UNICODE_INPUT = false ; STATIC = false ; // LOOKAHEAD = 2 ; // FORCE_LA_CHECK = true ; DEBUG_PARSER = true ; DEBUG_TOKEN_MANAGER = true ; } PARSER_BEGIN(JenaOWLManchesterParser) /* * (c) Copyright 2009 Andy Seaborne * All rights reserved. */ package lang.owlmanchestersyntax ; public class JenaOWLManchesterParser { // Reserved prefixes //rdf: //rdfs: //xsd: //owl: } PARSER_END(JenaOWLManchesterParser) // state IRI_State void fullIRI(): { } { } // state IRI_State void prefixName(): { } { } // state IRI_State void abbreviatedIRI(): { } { } void IRI(): { } { { token_source.SwitchTo(IRI_State) ; } ( fullIRI() | abbreviatedIRI() ) { token_source.SwitchTo(DEFAULT) ; } } void nonNegativeInteger(): {} { // zero | positiveInteger } void positiveInteger(): {} { // nonZero ( digit )* } void digits(): {} { } // void digit(): {} // { // zero | nonZero // } // // nonZero := '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' // // void zero(): {} // { // '0' // } void classIRI(): {} { IRI() } void Datatype(): {} { ( datatypeIRI() | "integer" | "decimal" | "float" | "string" ) } void datatypeIRI(): {} { IRI() } void objectPropertyIRI(): {} { IRI() } void dataPropertyIRI(): {} { IRI() } void objectOrDataPropertyIRI(): {} { IRI() } void annotationPropertyIRI(): {} { IRI() } void individual(): {} { ( individualIRI() | nodeID() ) } void individualIRI(): {} { IRI() } void nodeID(): {} { } void literal(): {} { //( typedLiteral | stringLiteralNoLanguage | stringLiteralWithLanguage | integerLiteral | decimalLiteral | floatingPointLiteral ) // ( typedLiteral() | stringLiteralNoLanguage() | stringLiteralWithLanguage() ) ( quotedString() ( "^^" Datatype() | languageTag() ) ? | integerLiteral() | decimalLiteral() | floatingPointLiteral() ) } // void typedLiteral(): {} // { // lexicalValue "^^" Datatype // } // // void stringLiteralNoLanguage(): {} // { // quotedString // } // // void stringLiteralWithLanguage(): {} // { // quotedString languageTag // } void languageTag(): { } { } // void lexicalValue(): {} // { // quotedString() // } void quotedString(): { } { // Needs to include newlines } void floatingPointLiteral(): {} { //( "+" | "-")? ( digits ("."digits)? (exponent)? | "." digits[exponent]) ( "f" | "F" ) ( | | ) } // void exponent(): {} // { // ("e" | "E") ("+" | "-")? digits // } //decimalLiteral ::= ("+" | "-")? digits "." digits void decimalLiteral(): {} { ( | | ) } //integerLiteral ::= ("+" | "-")? digits void integerLiteral(): {} { ( | | ) } // Grammar proper void entity(): {} { ( "Datatype" "(" Datatype() ")" | "Class" "(" classIRI() ")" | "ObjectProperty" "(" objectPropertyIRI() ")" | "DataProperty" "("dataPropertyIRI() ")" | "AnnotationProperty" "(" annotationPropertyIRI() ")" | "NamedIndividual" "(" individualIRI() ")" ) } void annotations(): {} { "Annotations:" annotationAnnotatedList() } void annotation(): {} { annotationPropertyIRI() annotationTarget() } void annotationTarget(): {} { ( nodeID() | IRI() | literal() ) } void ontologyDocument(): {} { ( prefixDeclaration() )* ontology() } void prefixDeclaration(): {} { "Prefix:" { token_source.SwitchTo(IRI_State) ; } prefixName() fullIRI() { token_source.SwitchTo(DEFAULT) ; } } void ontology(): {} { "Ontology:" { token_source.SwitchTo(IRI_State) ; } ( ontologyIRI() ( versionIRI() )? )? { token_source.SwitchTo(DEFAULT) ; } ( importOntology() )* ( annotations() )* ( frame() )* } void ontologyIRI(): {} { IRI() } void versionIRI(): {} { IRI() } void importOntology(): {} { "Import:" IRI() } void frame(): {} { ( datatypeFrame() | classFrame() | objectPropertyFrame() | dataPropertyFrame() | annotationPropertyFrame() | individualFrame() | misc() ) } void objectOrDataPropertyExpression(): {} { objectOrDataPropertyIRI() ("inverse" objectPropertyIRI())? } void objectPropertyExpression(): {} { ( objectPropertyIRI() | inverseObjectProperty() ) } void inverseObjectProperty(): {} { "inverse" objectPropertyIRI() } void dataPropertyExpression(): {} { dataPropertyIRI() } void dataRange(): {} { // ( // dataConjunction() "or" dataConjunction() ( // "or" dataConjunction() )* // | dataConjunction() ) dataConjunction() ( "or" dataConjunction()) * } void dataConjunction(): {} { // ( // dataPrimary() "and" dataPrimary() ( "and" dataPrimary() )* // | dataPrimary() // ) dataPrimary() ("and" dataPrimary())* } void dataPrimary(): {} { ( "not" )? dataAtomic() } void dataAtomic(): {} { ( Datatype() // datatypeRestriction ("[" facet() restrictionValue() ( "," facet() restrictionValue() )* "]" )? | "{" literalList() "}" | "(" dataRange() ")" ) // ( // Datatype() // | "{" literalList() "}" // | datatypeRestriction() // | "(" dataRange() ")" // ) } // void datatypeRestriction(): {} // { // Datatype() "[" facet() restrictionValue() ( "," facet() restrictionValue() )* "]" // } void facet(): {} { ( "length" | "minLength" | "maxLength" | "pattern" | "langPattern" | "<=" | "<" | ">=" | ">" ) } void restrictionValue(): {} { literal() } void description(): {} { // ( // conjunction() "or" conjunction() ( "or" conjunction() )* // | conjunction() // ) // conjunction() ( "or" conjunction() )* CONJUNCTION() ( "or" CONJUNCTION() )* } void CONJUNCTION(): {} { IRI() ( "that" ( "not" )? restriction() ( "and" ( "not" )? restriction() )* | restrictionTail() | ("and" primary() )+ | atomicNotIRI() )? } // Now allows empty tail. void restriction(): {} { IRI() restrictionTail() } void restrictionTail(): {} { ( "some" primary() | "only" primary() | "value" individual() | "Self" // Only for objectPropertyIRIs | "min" nonNegativeInteger() ( primary() )? | "max" nonNegativeInteger() ( primary() )? | "exactly" nonNegativeInteger() ( primary() )? ) } // Better name? void atomicNotIRI(): {} { ( "{" individualList() "}" | "(" description() ")" ) } void primary(): {} { restriction() } // void conjunction(): {} // { // ( // //WARNING classIRI and primary - both start classIRI // classIRI() "that" // ( "not" )? restriction() // ( "and" ( "not" )? restriction() )* // | primary() ( "and" primary() )* // ) // } // // void primary(): {} // { // ( "not" )? // //WARNING - both start with IRIs // ( restriction() | atomic() ) // } // // void restriction(): {} // { // // ( objectPropertyExpression() "some" primary() // // | objectPropertyExpression() "only" primary() // // | objectPropertyExpression() "value" individual() // // | objectPropertyExpression() "Self" // // | objectPropertyExpression() "min" nonNegativeInteger() ( primary() )? // // | objectPropertyExpression() "max" nonNegativeInteger() ( primary() )? // // | objectPropertyExpression() "exactly" nonNegativeInteger() ( primary() )? // // | dataPropertyExpression() "some" dataPrimary() // // | dataPropertyExpression() "only" dataPrimary() // // | dataPropertyExpression() "value" literal() // // | dataPropertyExpression() "min" nonNegativeInteger() ( dataPrimary() )? // // | dataPropertyExpression() "max" nonNegativeInteger() ( dataPrimary() )? // // | dataPropertyExpression() "exactly" nonNegativeInteger() ( dataPrimary() )? // // ) // // // == IRI() ("inverse" IRI())? // objectOrDataPropertyExpression() // ( // "some" primary() // | "only" primary() // | "value" individual() // | "Self" // Only for objectPropertyIRIs // | "min" nonNegativeInteger() ( primary() )? // | "max" nonNegativeInteger() ( primary() )? // | "exactly" nonNegativeInteger() ( primary() )? // ) // } // // void atomic(): {} // { // ( // classIRI() // | "{" individualList() "}" // | "(" description() ")" // ) // } void datatypeFrame(): {} { "Datatype:" Datatype() // ( "Annotations:" annotationAnnotatedList() )* // ( "EquivalentTo:" annotations() dataRange() )? // ( "Annotations:" annotationAnnotatedList() )* ( "Annotations:" annotationAnnotatedList() )* ( "EquivalentTo:" annotations() dataRange() ( "Annotations:" annotationAnnotatedList() )* )? } void classFrame(): {} { // "Class:" classIRI() // ( // ( // "Annotations:" annotationAnnotatedList() // | "SubClassOf:" descriptionAnnotatedList() // | "EquivalentTo:" descriptionAnnotatedList() // | "DisjointWith:" descriptionAnnotatedList() // | "DisjointUnionOf:" annotations() description2List() // )* // | "HasKey:" annotations() // ( objectPropertyExpression() | dataPropertyExpression() ) // ( objectPropertyExpression() | dataPropertyExpression() )* // ) "Class:" classIRI() ( "Annotations:" annotationAnnotatedList() | "SubClassOf:" descriptionAnnotatedList() | "EquivalentTo:" descriptionAnnotatedList() | "DisjointWith:" descriptionAnnotatedList() // | "DisjointUnionOf:" annotations() description2List() | "DisjointUnionOf:" descriptionAnnotatedList() | "HasKey:" annotations() ( objectOrDataPropertyExpression() )+ )* } void objectPropertyFrame(): {} { "ObjectProperty:" objectPropertyIRI() ( "Annotations:" annotationAnnotatedList() | "Domain:" descriptionAnnotatedList() | "Range:" descriptionAnnotatedList() | "Characteristics:" objectPropertyCharacteristicAnnotatedList() | "SubPropertyOf:" objectPropertyExpressionAnnotatedList() | "EquivalentTo:" objectPropertyExpressionAnnotatedList() | "DisjointWith:" objectPropertyExpressionAnnotatedList() | "InverseOf:" objectPropertyExpressionAnnotatedList() | "SubPropertyChain:" annotations() objectPropertyExpression() "o" objectPropertyExpression() ( "o" objectPropertyExpression() )* )* } void objectPropertyCharacteristic(): {} { ( "Functional" | "InverseFunctional" | "Reflexive" | "Irreflexive" | "Symmetric" | "Asymmetric" | "Transitive" ) } void dataPropertyFrame(): {} { "DataProperty:" dataPropertyIRI() ( "Annotations:" annotationAnnotatedList() | "Domain:" descriptionAnnotatedList() | "Range:" dataRangeAnnotatedList() | "Characteristics:" annotations() "Functional" | "SubPropertyOf:" dataPropertyExpressionAnnotatedList() | "EquivalentTo:" dataPropertyExpressionAnnotatedList() | "DisjointWith:" dataPropertyExpressionAnnotatedList() )* } void annotationPropertyFrame(): {} { "AnnotationProperty:" annotationPropertyIRI() ( ( "Annotations:" annotationAnnotatedList() )+ | "Domain:" IRIAnnotatedList() | "Range:" IRIAnnotatedList() | "SubPropertyOf:" annotationPropertyIRIAnnotatedList() ) } void individualFrame(): {} { "Individual:" individual() ( "Annotations:" annotationAnnotatedList() | "Types:" descriptionAnnotatedList() | "Facts:" factAnnotatedList() | "SameAs:" individualAnnotatedList() | "DifferentFrom:" individualAnnotatedList() )* } void fact(): {} { ( "not" )? objectOrDataPropertyFact() } void objectOrDataPropertyFact(): {} { objectOrDataPropertyIRI() ( individual() | literal() ) } // void objectPropertyFact(): {} // { // objectPropertyIRI() individual() // } // // void dataPropertyFact(): {} // { // dataPropertyIRI() literal() // } void misc(): {} { ( "EquivalentClasses:" annotations() description2List() | "DisjointClasses:" annotations() description2List() | "DisjointProperties:" annotations() objectOrDataProperty2List() | "EquivalentProperties:" annotations() objectOrDataProperty2List() // | "EquivalentProperties:" annotations() objectProperty2List() // | "DisjointProperties:" annotations() dataProperty2List() // | "EquivalentProperties:" annotations() dataProperty2List() // | "DisjointProperties:" annotations() dataProperty2List() | "SameIndividual:" annotations() individual2List() | "DifferentIndividuals:" annotations() individual2List() ) } // The meta productions, expanded. void objectOrDataPropertyList(): {} { objectOrDataPropertyIRI() ( "," objectOrDataPropertyIRI() )* } void objectOrDataProperty2List(): {} { objectOrDataPropertyIRI() "," objectOrDataPropertyList() } void objectOrDataPropertyAnnotatedList(): {} { (annotations())? objectOrDataPropertyIRI() ( "," (annotations()) objectOrDataPropertyIRI() )* } void annotationList(): {} { annotation() ( "," annotation() )* } void annotation2List(): {} { annotation() "," annotationList() } void annotationAnnotatedList(): {} { (annotations())? annotation() ( "," (annotations()) annotation() )* } void annotationPropertyIRIList(): {} { annotationPropertyIRI() ( "," annotationPropertyIRI() )* } void annotationPropertyIRI2List(): {} { annotationPropertyIRI() "," annotationPropertyIRIList() } void annotationPropertyIRIAnnotatedList(): {} { (annotations())? annotationPropertyIRI() ( "," (annotations()) annotationPropertyIRI() )* } void descriptionList(): {} { description() ( "," description() )* } void description2List(): {} { description() "," descriptionList() } void descriptionAnnotatedList(): {} { (annotations())? description() ( "," (annotations()) description() )* } void objectPropertyCharacteristicList(): {} { objectPropertyCharacteristic() ( "," objectPropertyCharacteristic() )* } void objectPropertyCharacteristic2List(): {} { objectPropertyCharacteristic() "," objectPropertyCharacteristicList() } void objectPropertyCharacteristicAnnotatedList(): {} { (annotations())? objectPropertyCharacteristic() ( "," (annotations()) objectPropertyCharacteristic() )* } void objectPropertyExpressionList(): {} { objectPropertyExpression() ( "," objectPropertyExpression() )* } void objectPropertyExpression2List(): {} { objectPropertyExpression() "," objectPropertyExpressionList() } void objectPropertyExpressionAnnotatedList(): {} { (annotations())? objectPropertyExpression() ( "," (annotations()) objectPropertyExpression() )* } void dataRangeList(): {} { dataRange() ( "," dataRange() )* } void dataRange2List(): {} { dataRange() "," dataRangeList() } void dataRangeAnnotatedList(): {} { (annotations())? dataRange() ( "," (annotations()) dataRange() )* } void dataPropertyExpressionList(): {} { dataPropertyExpression() ( "," dataPropertyExpression() )* } void dataPropertyExpression2List(): {} { dataPropertyExpression() "," dataPropertyExpressionList() } void dataPropertyExpressionAnnotatedList(): {} { (annotations())? dataPropertyExpression() ( "," (annotations()) dataPropertyExpression() )* } void IRIList(): {} { IRI() ( "," IRI() )* } void IRI2List(): {} { IRI() "," IRIList() } void IRIAnnotatedList(): {} { (annotations())? IRI() ( "," (annotations()) IRI() )* } void factList(): {} { fact() ( "," fact() )* } void fact2List(): {} { fact() "," factList() } void factAnnotatedList(): {} { (annotations())? fact() ( "," (annotations()) fact() )* } void individualList(): {} { individual() ( "," individual() )* } void individual2List(): {} { individual() "," individualList() } void individualAnnotatedList(): {} { (annotations())? individual() ( "," (annotations()) individual() )* } void literalList(): {} { literal() ( "," literal() )* } void literal2List(): {} { literal() "," literalList() } void literalAnnotatedList(): {} { (annotations())? literal() ( "," (annotations()) literal() )* } SKIP : { " " | "\t" | "\n" | "\r" | "\f" } SPECIAL_TOKEN : { } TOKEN: { <#WS: " " | "\t" | "\n" | "\r" | "\f"> | < PLUS: "+" > | < MINUS: "-" > | | < INTEGER: > | < DECIMAL: ( "." ()* | "." ) > | < DOUBLE: // Required exponent. ( (["0"-"9"])+ "." (["0"-"9"])* | "." (["0"-"9"])+ () | (["0"-"9"])+ ) > | < INTEGER_POSITIVE: > | < DECIMAL_POSITIVE: > | < DOUBLE_POSITIVE: > | < INTEGER_NEGATIVE: > | < DECIMAL_NEGATIVE: > | < DOUBLE_NEGATIVE: > | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > | <#ECHAR: "\\" ( "t"|"b"|"n"|"r"|"f"|"\\"|"\""|"'") > | )* "\"" > | | ()+("-" ()+)* > | <#A2Z: ["a"-"z","A"-"Z"]> | <#A2ZN: ["a"-"z","A"-"Z","0"-"9"]> // | ","<", "\"", "{", "}", "^", "\\", "|", "`", // "\u0000"-"\u0020"])* ">" > | > } // State change here (and see rules IRI() and prefixName()) SKIP : { " " | "\t" | "\n" | "\r" | "\f" } TOKEN: { )? ":" > | > | ","<", "\"", "{", "}", "^", "\\", "|", "`", "\u0000"-"\u0020"])* ">" > } TOKEN: { > | > // XML 1.1 NCNameStartChar without "_" | <#PN_CHARS_BASE: ["A"-"Z"] | ["a"-"z"] | ["\u00C0"-"\u00D6"] | ["\u00D8"-"\u00F6"] | ["\u00F8"-"\u02FF"] | ["\u0370"-"\u037D"] | ["\u037F"-"\u1FFF"] | ["\u200C"-"\u200D"] | ["\u2070"-"\u218F"] | ["\u2C00"-"\u2FEF"] | ["\u3001"-"\uD7FF"] | ["\uF900"-"\uFFFD"] > // [#x10000-#xEFFFF] | <#PN_CHARS_U: | "_" > | // No DOT <#PN_CHARS: ( | "-" | ["0"-"9"] | "\u00B7" | ["\u0300"-"\u036F"] | ["\u203F"-"\u2040"] ) > | // No leading "_", no trailing ".", can have dot inside prefix name. <#PN_PREFIX: ((|".")* )? > | // With a leading "_", no dot at end of local name. <#PN_LOCAL: ( | ["0"-"9"]) ((|".")* )? > | // NCNAME without "-" and ".", allowing leading digits. <#VARNAME: ( | ["0"-"9"] ) ( | ["0"-"9"] | "\u00B7" | ["\u0300"-"\u036F"] | ["\u203F"-"\u2040"] )* > } // End of tokens. // Catch-all tokens. Must be last. // Any non-whitespace. Causes a parser exception, rather than a // token manager error (with hidden line numbers). // Only bad IRIs (e.g. spaces) now give unhelpful parse errors. TOKEN: { <#UNKNOWN: (~[" ","\t","\n","\r","\f" ])+ > } /* # Local Variables: # tab-width: 4 # indent-tabs-mode: nil # comment-default-style: "//" # End: */