#if 0 // (Run through cpp -P -C first) #endif #define PACKAGE brt.text.parser #define CLASS RDFTuples_Parser #define PARSERBASE RDFTuplesParserBase options { // See also ECHAR for false/true. JAVA_UNICODE_ESCAPE = true ; UNICODE_INPUT = false ; // Whether the input stream is ASCII or Unicode STATIC = false ; // DEBUG_PARSER = true ; // DEBUG_TOKEN_MANAGER = true ; } PARSER_BEGIN(CLASS) /* * (c) Copyright 2009 Hewlett-Packard Development Company, LP * All rights reserved. */ package PACKAGE ; import com.hp.hpl.jena.graph.* ; import brt.text.PARSERBASE ; //@SuppressWarnings("unchecked") public class CLASS extends PARSERBASE { } PARSER_END(CLASS) // ---- Parser entry points void unit() : {} { { startParse() ; } (tuple())+ { finishParse() ; } } void tuple() : {Node n ; } { { startTuple() ; } ( n = termNode() { emitTerm(n); })* { finishTuple() ; } } Node termNode() : { Node n ; } { (n = IRI() | n = Literal() | n = BlankNode() ) { return n ; } } Node IRI() : { String x ;} { x = IRIstr() { return createURI(x) ; } } String IRIstr() : { Token t ; } { t = { return resolveQuotedIRI(t.image, t.beginLine, t.beginColumn) ; } } Node BlankNode() : { Token t = null ; } { t = { return createBNode(t.image, t.beginLine, t.beginColumn) ; } } Node Literal() : { Node n ; } { ( n = Number() | n = RDFLiteral() ) { return n ; } } Node RDFLiteral() : { Token t ; String lex = null ; } { lex = String() // Optional lang tag and datatype. { String lang = null ; String dt = null ; } ( lang = Langtag() | (
dt = IRIstr() ) )? { return createLiteral(lex, lang, dt) ; } } String Langtag() : { Token t ; } { // Enumerate the directives here because they look like language tags. ( t = ) { String lang = stripChars(t.image, 1) ; return lang ; } } Node Number() : { Token t ; } { t = { return createLiteralInteger(t.image) ; } | t = { return createLiteralDecimal(t.image) ; } | t = { return createLiteralDouble(t.image) ; } | t = { return createLiteralInteger(t.image) ; } | t = { return createLiteralDecimal(t.image) ; } | t = { return createLiteralDouble(t.image) ; } | t = { return createLiteralInteger(t.image) ; } | t = { return createLiteralDecimal(t.image) ; } | t = { return createLiteralDouble(t.image) ; } } String String() : { Token t ; String lex ; } { // ( t = { lex = stripQuotes(t.image) ; } // | t = { lex = stripQuotes(t.image) ; } // | t = { lex = stripQuotes3(t.image) ; } // | t = { lex = stripQuotes3(t.image) ; } // ) ( t = | t = ) { lex = stripQuotes(t.image) ; } { lex = unescapeStr(lex, t.beginLine, t.beginColumn) ; return lex ; } } SKIP : { <" " | "\t" | "\n" | "\r" | "\f"> } //TOKEN: { } SPECIAL_TOKEN : { } TOKEN : { | | | | | //| // | < #QUOTE_3D: "\"\"\""> // | < #QUOTE_3S: "'''"> | < STRING1: // Single quoted string "'" ( (~["'","\\","\n","\r"]) | )* "'" > | < STRING2: // Double quoted string "\"" ( (~["\"","\\","\n","\r"]) | )* "\"" > // | < STRING_LONG1: // // ( ("'" | "''")? (~["'","\\"] | ))* // > // | < STRING_LONG2: // // ( ("\"" | "\"\"")? (~["\"","\\"] | ))* // > | < #DIGITS: (["0"-"9"])+> | < INTEGER: > | < DECIMAL: ( "." ()* | ) > | < DOUBLE: // Required exponent. ( (["0"-"9"])+ "." (["0"-"9"])* | "." (["0"-"9"])+ () | (["0"-"9"])+ ) > | < POSITIVE_INTEGER: > | < POSITIVE_DECIMAL: > | < POSITIVE_DOUBLE: > | < NEGATIVE_INTEGER: > | < NEGATIVE_DECIMAL: > | < NEGATIVE_DOUBLE: > | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > //| ","<", "\"", "{", "}", "^", "\\", "|", "`", // "\u0000"-"\u0020"])* ">" > // Very liberal | ","<", " ", "\t", "\n", "\r", "\f" ])* ">" > // Very liberal | | ()+("-" ()+)* > | <#A2Z: ["a"-"z","A"-"Z"]> | <#A2ZN: ["a"-"z","A"-"Z","0"-"9"]> } // Catch-all tokens. Must be last. // Any non-whitespace. Causes a parser exception, rather than a // token manager error (with hidden line numbers). TOKEN: { <#UNKNOWN: (~[" ","\t","\n","\r","\f" ])+ > } /* * (c) Copyright 2009 Hewlett-Packard Development Company, LP * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* # Local Variables: # tab-width: 4 # indent-tabs-mode: nil # comment-default-style: "//" # End: */