OSLC Query 2.0 Implementation
Introduction
The
OSLC Core 2.0 specification defines query parameters and a
Query syntax which we use in the EMS 2.0 REST API. This page contains information for implementers.
Please post feedback to:
oslc-core@open-servicesNOSPAM.net
ANTLR Grammar
ANTLR is a popular open source parser development technology. ANTLR defines grammars in a syntax that closely resembles the EBNF syntax used in the OSLC Core 2.0 specification. The following in an ANTLR grammar,
OslcSimpleQuery.g, for the query parameters defined in the
OSLC Core 2.0 and
OSLC Query 2.0 specifications:
grammar OslcSimpleQuery;
/* oslc.prefix */
oslc_prefix
: 'oslc.prefix=' prefix_defs
;
prefix_defs
: prefix_def (',' prefix_def)*
;
prefix_def
: prefix '=' uri_ref_esc
;
prefix
: PN_PREFIX
;
uri_ref_esc
: URI_REF_ESC
;
/* oslc.properties */
oslc_properties
: 'oslc.properties=' properties
;
properties
: property (',' property)*
;
property
: (prefixedName | wildcard) ('{' properties '}')?
;
wildcard
: '*'
;
prefixedName
: prefix? colonLocalName
;
colonLocalName
: COLON_LOCAL_NAME
;
/* oslc.select */
oslc_select
: 'oslc.select=' properties
;
/* oslc.where */
oslc_where
: 'oslc.where=' compound_term
;
compound_term
: simple_term (space? boolean_op space? simple_term)*
;
simple_term
: term
| scoped_term
;
space
: ' '
;
boolean_op
: 'and'
;
term
: identifier_wc comparison_op value
| identifier_wc space in_op space? in_val
;
scoped_term
: identifier_wc '{' compound_term '}'
;
identifier_wc
: identifier
| wildcard
;
identifier
: prefixedName
;
comparison_op
: '='
| '!='
| '<'
| '>'
| '<='
| '>='
;
in_op
: 'in'
;
in_val
: '[' value (',' value)* ']'
;
value
: uri_ref_esc
| literal_value
;
literal_value
: boolean
| decimal
| string_esc (langTag | datatype)?
;
string_esc
: STRING_ESC
;
langTag
: LANG_TAG
;
datatype
: '^^' prefixedName
;
boolean
: 'true'
| 'false'
;
decimal
: DECIMAL
;
/* oslc.orderBy */
oslc_orderBy
: 'oslc.orderBy=' sort_terms
;
sort_terms
: sort_term (',' sort_term)*
;
sort_term
: scoped_sort_terms
| ('+' | '-') identifier
;
scoped_sort_terms
: identifier '{' sort_terms '}'
;
/* oslc.searchTerms */
oslc_searchTerms
: 'oslc.searchTerms=' search_terms
;
search_terms
: string_esc (',' string_esc)*
;
/* lexer */
DECIMAL
: ('+' | '-')? '0'..'9'+ ('.' '0'..'9'*)?
| ('+' | '-')? '.' '0'..'9'+
;
LANG_TAG
: '@' ('a'..'z' | 'A'..'Z')+ ('-' ('a'..'z' | 'A'..'Z' | '0'..'9')+)*
;
STRING_ESC
: '"' ('\\"' | '\\\\' | ~('"' | '\\'))* '"'
;
URI_REF_ESC
: '<' ('\\>' | '\\\\' | ~('>' | '\\'))* '>'
;
COLON_LOCAL_NAME
: ':' (PN_CHARS_U | '0'..'9') ((PN_CHARS | '.')* PN_CHARS)?
;
PN_PREFIX
: PN_CHARS_BASE ((PN_CHARS|'.')* PN_CHARS)?
;
fragment
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'..'\uFDCF'
| '\uFDF0'..'\uFFFD'
// | '\u10000'..'\uEFFFF' - not allowed in ANTLR
;
fragment
PN_CHARS_U
: PN_CHARS_BASE
| '_'
;
fragment
PN_CHARS
: PN_CHARS_U
| '-'
| '0'..'9'
| '\u00B7'
| '\u0300'..'\u036F'
| '\u203F'..'\u2040'
;
Topic revision: r2 - 01 Mar 2011 - 18:34:43 -
ArthurRyman