Re: ACTION-278: grammar for TriG

On Jul 6, 2013, at 4:49 PM, Eric Prud'hommeaux <eric@w3.org> wrote:

> https://www.w3.org/2011/rdf-wg/track/actions/278 says
> [[
> Create new grammar for TriG that includes optional graph keywords and
> make {} optional around the default graph
> ]]
> 
> I followed Sandro's lead and replaced
> [[
>  [1] 	turtleDoc 	::= 	statement*
>  [2] 	statement 	::= 	directive | triples '.'
> ]]
> with:
> [[
>  trigDoc           ::= statement*
>  statement         ::= directive | tripleOrBareGraph | graphword | wrappedDefault
>  tripleOrBareGraph ::= (iri | BlankNode | collection | BlankNodePropertyList) ('{' TriplesTemplate '}' | PropertyListNotEmpty '.')
>  graphword         ::= "GRAPH" (iri | BlankNode) '{' TriplesTemplate '}'
>  wrappedDefault    ::= '{' TriplesTemplate '}'
> ]].
> This permits docs like:
> [[
>  PREFIX p: <ns>
>  @prefix p: <ns> .
>  <s> <p> <o> .
>  { <s> <p> <o> }
>  <g> { <s> <p> <o> }
>  GRAPH <g> { <s> <p> <o> }
>  _:g { <s> <p> <o> }
>  GRAPH _:g { <s> <p> <o> }
> ]].

In keeping with case-insensitive keywords as with PREFIX and BASE, I think that "GRAPH" should instead be a terminal. You have a "GRAPH1" terminal, but it's not used. Presumably this would be used in the "graphword" production, perhaps just renamed "GRAPH".

You could also eliminate some duplication by using "wrappedDefault" wherever you already have '{' TriplesTemplate? '}'.

(Also, did you revert LANGTAG in your grammar?


> We can be conservative or liberal about what can go the the graph name
> position:
> [[
> tripleOrBareGraph ::= (iri | BlankNode) ('{' TriplesTemplate '}' | PropertyListNotEmpty '.')
>                    | collection PropertyListNotEmpty '.'
>                    | BlankNodePropertyList PropertyListNotEmpty? '.'
> [[
> or more liberal:
> [[
> tripleOrBareGraph ::= (iri | BlankNode | collection | BlankNodePropertyList) ('{' TriplesTemplate '}' | PropertyListNotEmpty '.')
> ]]
> which permits bnodes from collections and property lists like:
> [[
>  (1 2 3) { <s> <p> <o> }
>  [ <p> <o> ] { <s> <p> <o> }
> ]].
> I prefer the latter as it encourages the good practice of making
> assertions about labeled graphs, e.g.
> [[
>  [ :utteredBy "Bob" ] { <moon> <madeOf> <greenCheese> }
> ]]
> 
> 
> Following is <http://www.w3.org/2005/01/yacker/uploads/trigS_new>:
> 
> trigDoc           ::= statement*
> statement         ::= directive | tripleOrBareGraph | graphword | wrappedDefault
> #tripleOrBareGraph ::= (iri | BlankNode) ('{' TriplesTemplate '}' | PropertyListNotEmpty '.')
> #                    | collection PropertyListNotEmpty '.'
> #                    | BlankNodePropertyList PropertyListNotEmpty? '.'
> tripleOrBareGraph ::= (iri | BlankNode | collection | BlankNodePropertyList) ('{' TriplesTemplate '}' | PropertyListNotEmpty '.')
> graphword         ::= "GRAPH" (iri | BlankNode) '{' TriplesTemplate '}'
> wrappedDefault    ::= '{' TriplesTemplate '}'
> 
> [3]     directive                  ::= prefixID | base | sparqlPrefix | sparqlBase
> [4]     prefixID                   ::= PREFIX PNAME_NS IRIREF '.'
> [5]     base                       ::= BASE IRIREF '.'
> [5s]    sparqlBase                 ::= SPARQL_BASE IRIREF
> [6s]    sparqlPrefix               ::= SPARQL_PREFIX PNAME_NS IRIREF
> [52s]   TriplesTemplate            ::= TriplesSameSubject ( '.' TriplesTemplate? )?
> [6]     TriplesSameSubject         ::= subject PropertyListNotEmpty | BlankNodePropertyList PropertyList
> [76s]   PropertyList               ::= PropertyListNotEmpty?
> [77s]   PropertyListNotEmpty       ::= Verb ObjectList (';' (Verb ObjectList)?)*
> [8]     ObjectList                 ::= object (',' object)*
> [9]     Verb                       ::= predicate | 'a'
> [10]    subject                    ::= iri | BlankNode | collection
> [11]    predicate                  ::= iri
> [12]    object                     ::= iri | BlankNode | collection | BlankNodePropertyList | literal
> [13]    literal                    ::= RDFLiteral | NumericLiteral | BooleanLiteral
> [14]    BlankNodePropertyList      ::= '[' PropertyListNotEmpty ']'
> [15]    collection                 ::= '(' object* ')'
> [16]    NumericLiteral             ::= INTEGER | DECIMAL | DOUBLE
> [128s]  RDFLiteral                 ::= String (LANGTAG | '^^' iri)?
> [133s]  BooleanLiteral             ::= 'true' | 'false'
> [17]    String                     ::= STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2
> [135s]  iri                        ::= IRIREF | PrefixedName
> [136s]  PrefixedName               ::= PNAME_LN | PNAME_NS
> [137s]  BlankNode                  ::= BLANK_NODE_LABEL | ANON
> 
> @terminals
> 
> [18]    IRIREF                     ::= '<' ([^#x00-#x20<>\"{}|^`\\] | UCHAR)* '>'
> [139s]  PNAME_NS                   ::= PN_PREFIX? ':'
> [140s]  PNAME_LN                   ::= PNAME_NS PN_LOCAL
> [141s]  BLANK_NODE_LABEL           ::= '_:' (PN_CHARS_U | [0-9]) ((PN_CHARS | '.')* PN_CHARS)?
> [0]     GRAPH1                      ::= [Gg][Rr][Aa][Pp][Hh]
> [0]     SPARQL_PREFIX              ::= [Pp][Rr][Ee][Ff][Ii][Xx]
> [0]     SPARQL_BASE                ::= [Bb][Aa][Ss][Ee]
> [0]     BASE                       ::= '@base'
> [0]     PREFIX                     ::= '@prefix'
> [144s]  LANGTAG                    ::= BASE | PREFIX | '@' [a-zA-Z]+ ('-' [a-zA-Z0-9]+)*
> [19]    INTEGER                    ::= [+-]? [0-9]+
> [20]    DECIMAL                    ::= [+-]? [0-9]* '.' [0-9]+
> [21]    DOUBLE                     ::= [+-]? ([0-9]+ '.' [0-9]* EXPONENT | '.' [0-9]+ EXPONENT | [0-9]+ EXPONENT)
> [154s]  EXPONENT                   ::= [eE] [+-]? [0-9]+
> [155s]  STRING_LITERAL1            ::= "'" ([^#x27#x5C#xA#xD] | ECHAR | UCHAR)* "'"
> [156s]  STRING_LITERAL2            ::= '"' ([^#x22#x5C#xA#xD] | ECHAR | UCHAR)* '"'
> [157s]  STRING_LITERAL_LONG1       ::= "'''" (("'" | "''")? [^'\\] | ECHAR | UCHAR)* "'''"
> [158s]  STRING_LITERAL_LONG2       ::= '"""' (('"' | '""')? [^"\\] | ECHAR | UCHAR)* '"""'
> [26]    UCHAR                      ::= '\\u' HEX HEX HEX HEX | '\\U' HEX HEX HEX HEX HEX HEX HEX HEX
> [159s]  ECHAR                      ::= '\\' [tbnrf\\"']
> [161s]  WS                         ::= #x20 | #x9 | #xD | #xA
> [162s]  ANON                       ::= '[' WS* ']'
> [163s]  PN_CHARS_BASE              ::= [A-Z] | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] | [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
> [164s]  PN_CHARS_U                 ::= PN_CHARS_BASE | '_'
> [166s]  PN_CHARS                   ::= PN_CHARS_U | '-' | [0-9] | #x00B7 | [#x0300-#x036F] | [#x203F-#x2040]
> [167s]  PN_PREFIX                  ::= PN_CHARS_BASE ((PN_CHARS | '.')* PN_CHARS)?
> [168s]  PN_LOCAL                   ::= (PN_CHARS_U | ':' | [0-9] | PLX) ((PN_CHARS | '.' | ':' | PLX)* (PN_CHARS | ':' | PLX))?
> [169s]  PLX                        ::= PERCENT | PN_LOCAL_ESC
> [170s]  PERCENT                    ::= '%' HEX HEX
> [171s]  HEX                        ::= [0-9] | [A-F] | [a-f]
> [172s]  PN_LOCAL_ESC               ::= '\\' ('_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%')
> 
> @pass: [ \t\r\n]+ | '#' [^\r\n]*
> 
> 
> -- 
> -ericP
> 

Received on Sunday, 7 July 2013 19:54:33 UTC