rql-parser.jj
来自「这是外国一个开源推理机」· JJ 代码 · 共 1,312 行 · 第 1/3 页
JJ
1,312 行
DataQuery ext_data_query() :{ DataQuery result;}{ result = uri() { return result; }| result = data_query() { return result; }}DataQuery data_query() :{ ResourceQuery result;}{ result = datavar() { return (DataQuery)result; }| result = proper_instances() result = array_selection(result) { return (DataQuery)result; }}DataQuery proper_instances() :{ ClassQuery cq;}{ <CIRCUMFLEX> cq = ext_class_query() { return new InstanceOf(cq, true); }}/*-------------------------------------------------+| CLASS QUERIES |+-------------------------------------------------*//* Extended class query = class_query + schemavar + uri */ClassQuery ext_class_query() :{ ResourceQuery result;}{ result = uri() { return (ClassQuery)result; }| result = class_query() { return (ClassQuery)result; }}ClassQuery class_query() :{ ResourceQuery result;}{ result = typeOf() result = array_selection(result) { return (ClassQuery)result; }| result = subClassOf() result = array_selection(result) { return (ClassQuery)result; }| result = superClassOf() result = array_selection(result) { return (ClassQuery)result; }| result = domain() { return (ClassQuery)result; }| result = range() { return (ClassQuery)result; }| result = classvar() { return (ClassQuery)result; }| result = rdfs_class() result = array_selection(result) { return (ClassQuery)result; }}ClassQuery typeOf() :{ ResourceQuery rq; Token t = null;}{ <TYPEOF> (t = <CIRCUMFLEX>)? <LPAREN> rq = typeOf_arg() <RPAREN> { return new TypeOf(rq, (t == null)); }}ResourceQuery typeOf_arg() :{ ResourceQuery rq;}{ // FIXME why not just all resourcequeries? rq = ext_data_query() { return rq; } | rq = property_query() { return rq; } | rq = class_query() { return rq; }}ClassQuery subClassOf() :{ ClassQuery cq; Token t = null;}{ <SUBCLASSOF> (t = <CIRCUMFLEX>)? <LPAREN> cq = ext_class_query() <RPAREN> { return new SubClassOf(cq, (t == null)); }}ClassQuery superClassOf() :{ ClassQuery cq; Token t = null;}{ <SUPERCLASSOF> (t = <CIRCUMFLEX>)? <LPAREN> cq = ext_class_query() <RPAREN> { return new SuperClassOf(cq, (t == null)); }}RdfsClass rdfs_class() :{}{ <CLASS> { return new RdfsClass(); }}ClassQuery domain() :{ PropertyQuery pq;}{ <DOMAIN> <LPAREN> pq = ext_property_query() <RPAREN> { return new Domain(pq); }}ClassQuery range() :{ PropertyQuery pq;}{ <RANGE> <LPAREN> pq = ext_property_query() <RPAREN> { return new Range(pq); }}/*-------------------------------------------------+| PROPERTY QUERIES |+-------------------------------------------------*//* Extended property query = property_query + schemavar + uri */PropertyQuery ext_property_query() :{ PropertyQuery result;}{ result = uri() { return result; }| result = property_query() { return result; }}PropertyQuery property_query() :{ ResourceQuery result;}{ result = subPropertyOf() result = array_selection(result) { return (PropertyQuery)result; }| result = superPropertyOf() result = array_selection(result) { return (PropertyQuery)result; }| result = propertyvar() { return (PropertyQuery)result; }| result = rdf_property() result = array_selection(result) { return (PropertyQuery)result; }}PropertyQuery subPropertyOf() :{ PropertyQuery pq; Token t = null;}{ <SUBPROPERTYOF> (t = <CIRCUMFLEX>)? <LPAREN> pq = ext_property_query() <RPAREN> { return new SubPropertyOf(pq, (t == null)); }}PropertyQuery superPropertyOf() :{ PropertyQuery pq; Token t = null;}{ <SUPERPROPERTYOF> (t = <CIRCUMFLEX>)? <LPAREN> pq = ext_property_query() <RPAREN> { return new SuperPropertyOf(pq, (t == null)); }}RdfProperty rdf_property() :{}{ <PROPERTY> { return new RdfProperty(); }}/*-------------------------------------------------+| RESOURCE QUERIES |+-------------------------------------------------*/// Only used within boolean_queryResourceQuery resource_query() :{ ResourceQuery r;}{ r = uri() { return r; }| r = data_query() /* NOT extended */ { return r; }| r = class_query() /* NOT extended */ { return r; }| r = property_query() /* NOT extended */ { return r; }| r = sfw_query() { return r; }| r = constant() { return r; }}ResourceQuery array_selection(ResourceQuery subject) :{ Token startIdx = null; Token endIdx = null;}{ ( LOOKAHEAD(1) <LBRACKET> startIdx = <INTEGER_LITERAL> ( <COLON> endIdx = <INTEGER_LITERAL> )? <RBRACKET> )? { if (startIdx != null) { int idx1, idx2; idx1 = Integer.parseInt(startIdx.image); if (endIdx == null) { idx2 = idx1; } else { idx2 = Integer.parseInt(endIdx.image); } subject = new ArraySelection(subject, idx1, idx2); } return subject; }}SetQuery set_query() :{ ResourceQuery arg1; ResourceQuery arg2; Token setOp;}{ <LPAREN> arg1 = sfw_query() <RPAREN> ( setOp = <UNION> | setOp = <INTERSECT> | setOp = <MINUS> ) { clearVars(); } <LPAREN> arg2 = sfw_query() <RPAREN> { if (setOp.image.equals("union")) { return new Union((SfwQuery)arg1, (SfwQuery)arg2); } else if (setOp.image.equals("intersect")) { return new Intersect((SfwQuery)arg1, (SfwQuery)arg2); } else { return new Minus((SfwQuery)arg1, (SfwQuery)arg2); } }}/*-------------------------------------------------+| BOOLEAN QUERIES |+-------------------------------------------------*/BooleanQuery boolean_query() :{ BooleanQuery result;}{ result = or_expression() { return result; }}BooleanQuery or_expression() :{ BooleanQuery arg1; BooleanQuery arg2 = null;}{ arg1 = and_expression() ( LOOKAHEAD(1) <OR> arg2 = or_expression() )? { if (arg2 == null) { return arg1; } else { return new Or(arg1, arg2); } }}BooleanQuery and_expression() :{ BooleanQuery arg1; BooleanQuery arg2 = null;}{ arg1 = and_part() ( LOOKAHEAD(1) <AND> arg2 = and_expression() )? { if (arg2 == null) { return arg1; } else { return new And(arg1, arg2); } }}BooleanQuery and_part() :{ BooleanQuery bq; ResourceQuery rq; Var var;}{ <TRUE> { return new BooleanConstant(true); }| <FALSE> { return new BooleanConstant(false); }| <NOT> bq = and_part() { return new Not(bq); }| <EXISTS> var = var() rq = resource_query() <COLON> bq = boolean_query() { return new Exists(var, rq, bq); }| <FORALL> var = var() rq = resource_query() <COLON> bq = boolean_query() { return new Forall(var, rq, bq); }| rq = resource_query() bq = compare_to_part(rq) { return bq; }| <LPAREN> bq = boolean_query() <RPAREN> { return bq; }}BooleanQuery compare_to_part(ResourceQuery arg1) :{ int op; ResourceQuery arg2; StringConstant sc;}{ op = comp_op() arg2 = resource_query() { return new CompareTo(arg1, op, arg2); }| <LIKE> sc = quoted_string() { return new Like(arg1, sc); }| <IN> arg2 = resource_query() { return new In(arg1, arg2); }}int comp_op() :{}{ <LT> { return CompareTo.LT; }| <LE> { return CompareTo.LE; }| <EQ> { return CompareTo.EQ; }| <GE> { return CompareTo.GE; }| <GT> { return CompareTo.GT; }| <NE> { return CompareTo.NE; }}/*-------------------------------------------------+| CONSTANTS |+-------------------------------------------------*/Constant constant() :{ Constant c;}{ c = quoted_string() { return c; }| c = quoted_char() { return c; }| c = integer_literal() { return c; }| c = real_literal() { return c; }}StringConstant quoted_string() :{ Token t;}{ t = <QUOTED_STRING> { String st = t.image; st = st.substring(1, st.length() - 1); return new StringConstant(st); }}StringConstant quoted_char() :{ Token t;}{ t = <QUOTED_CHAR> { String st = t.image; st = st.substring(1, st.length() - 1); return new StringConstant(st); }}IntegerConstant integer_literal() :{ Token t;}{ t = <INTEGER_LITERAL> { int i = Integer.parseInt(t.image); return new IntegerConstant(i); }}RealConstant real_literal() :{ Token t;}{ t = <REAL_LITERAL> { float f = Float.parseFloat(t.image); return new RealConstant(f); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?