Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jena-arq/Grammar/README
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Note:
cpp (the C Preprocessor) must be installed.
The grammar script runs cpp over main.jj to produce arq.jj and sparql.jj.

For ARQ, main.jj sets the javacc option USER_CHAR_STREAM: the ARQ parser
reads with ARQCharStream (org.apache.jena.sparql.lang.arq), which is not
generated, instead of a generated SimpleCharStream (GH-1324).

==== HTML

To produce the HTML for the SPARQL Grammar for the W3C spec:
Expand Down
18 changes: 17 additions & 1 deletion jena-arq/Grammar/arq.jj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ options
JAVA_UNICODE_ESCAPE = false ;
UNICODE_INPUT = true ;
STATIC = false ;
// ARQCharStream (GH-1324): see the parser class below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit that might not be a problem - I see the ticket number mentioned 5 times in the changes. There are a few places Jena has this, but it doesnt look like an established pattern.

USER_CHAR_STREAM = true ;
// DEBUG_PARSER = true ;
// DEBUG_TOKEN_MANAGER = true ;
}
Expand Down Expand Up @@ -64,8 +66,22 @@ import org.apache.jena.sparql.modify.request.* ;
import org.apache.jena.sparql.core.Quad ;
import java.util.List;
import java.util.ArrayList;
import org.apache.jena.sparql.lang.arq.ARQCharStream ;
public class ARQParser extends org.apache.jena.sparql.lang.arq.ARQParserBase
{}
{
// USER_CHAR_STREAM leaves out the InputStream and Reader constructors and
// ReInit operations: these are the ones javacc would generate, with ARQCharStream.
public ARQParser(java.io.InputStream stream) { this(stream, null); }
public ARQParser(java.io.InputStream stream, String encoding) { this(newCharStream(stream, encoding)); }
public ARQParser(java.io.Reader stream) { this(new ARQCharStream(stream, 1, 1)); }
public void ReInit(java.io.InputStream stream) { ReInit(stream, null); }
public void ReInit(java.io.InputStream stream, String encoding) { ReInit(newCharStream(stream, encoding)); }
public void ReInit(java.io.Reader stream) { ReInit(new ARQCharStream(stream, 1, 1)); }
private static ARQCharStream newCharStream(java.io.InputStream stream, String encoding) {
try { return new ARQCharStream(stream, encoding, 1, 1); }
catch (java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
}
}
PARSER_END(ARQParser)
// // Common top for single entry point.
// void Top(): {}
Expand Down
4 changes: 3 additions & 1 deletion jena-arq/Grammar/grammar
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function grammar

DIR="../src/main/java/org/apache/jena/sparql/lang/$PKG/javacc"

(cd "$DIR" ; rm -f TokenMgrError.java ParseException.java Token.java JavaCharStream.java )
## javacc does not overwrite existing support files, so remove them to have them regenerated.
## CharStream.java: ARQ only (USER_CHAR_STREAM in main.jj).
(cd "$DIR" ; rm -f TokenMgrError.java ParseException.java Token.java JavaCharStream.java CharStream.java )

echo "---- Process grammar -- $1"
javacc -OUTPUT_DIRECTORY=$DIR -JDK_VERSION=1.8 "${FILE}"
Expand Down
22 changes: 22 additions & 0 deletions jena-arq/Grammar/main.jj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ options
UNICODE_INPUT = true ;

STATIC = false ;
#ifdef ARQ
// ARQCharStream (GH-1324): see the parser class below.
USER_CHAR_STREAM = true ;
#endif
// DEBUG_PARSER = true ;
// DEBUG_TOKEN_MANAGER = true ;
}
Expand Down Expand Up @@ -103,10 +107,28 @@ import org.apache.jena.sparql.modify.request.* ;
import org.apache.jena.sparql.core.Quad ;
import java.util.List;
import java.util.ArrayList;
import org.apache.jena.sparql.lang.arq.ARQCharStream ;
#endif

public class CLASS extends PARSERBASE
#ifdef ARQ
{
// USER_CHAR_STREAM leaves out the InputStream and Reader constructors and
// ReInit operations: these are the ones javacc would generate, with ARQCharStream.
public CLASS(java.io.InputStream stream) { this(stream, null); }
public CLASS(java.io.InputStream stream, String encoding) { this(newCharStream(stream, encoding)); }
public CLASS(java.io.Reader stream) { this(new ARQCharStream(stream, 1, 1)); }
public void ReInit(java.io.InputStream stream) { ReInit(stream, null); }
public void ReInit(java.io.InputStream stream, String encoding) { ReInit(newCharStream(stream, encoding)); }
public void ReInit(java.io.Reader stream) { ReInit(new ARQCharStream(stream, 1, 1)); }
private static ARQCharStream newCharStream(java.io.InputStream stream, String encoding) {
try { return new ARQCharStream(stream, encoding, 1, 1); }
catch (java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
}
}
#else
{}
#endif
PARSER_END(CLASS)

// // Common top for single entry point.
Expand Down
Loading
Loading