You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/11/15 12:23:12 UTC
svn commit: r1542235 - in /jena/trunk/jena-arq/src/main/java:
com/hp/hpl/jena/sparql/sse/SSE.java org/apache/jena/atlas/io/PeekReader.java
org/apache/jena/riot/tokens/TokenizerText.java
Author: andy
Date: Fri Nov 15 11:23:12 2013
New Revision: 1542235
URL: http://svn.apache.org/r1542235
Log:
Correct out-of-date comments and reformat.
Modified:
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/sse/SSE.java
jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/io/PeekReader.java
jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/tokens/TokenizerText.java
Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/sse/SSE.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/sse/SSE.java?rev=1542235&r1=1542234&r2=1542235&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/sse/SSE.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/sse/SSE.java Fri Nov 15 11:23:12 2013
@@ -357,6 +357,9 @@ public class SSE
return handler.getItem() ;
}
+ private static Item parse(Reader reader)
+ { return parse(reader, null) ; }
+
private static Item parse(Reader reader, PrefixMapping pmap)
{
if ( pmap == null )
Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/io/PeekReader.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/io/PeekReader.java?rev=1542235&r1=1542234&r2=1542235&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/io/PeekReader.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/atlas/io/PeekReader.java Fri Nov 15 11:23:12 2013
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-package org.apache.jena.atlas.io;
+package org.apache.jena.atlas.io ;
import static org.apache.jena.atlas.io.IO.EOF ;
import static org.apache.jena.atlas.io.IO.UNSET ;
@@ -32,67 +32,67 @@ import org.apache.jena.atlas.lib.Chars ;
import com.hp.hpl.jena.shared.JenaException ;
-/** Parsing-centric reader.
- * This class is not thread safe.
+/**
+ * Parsing-centric reader. This class is not thread safe.
+ *
* @see BufferingWriter
* @see PeekInputStream
- */
+ */
-public final class PeekReader extends Reader
-{
+public final class PeekReader extends Reader {
// Remember to apply fixes to PeekInputStream as well.
-
+
// Buffering is done by a CharStream - does i t make adifference?
- // Yes. A lot (Java6).
-
- // Using a Reader here seems to have zero cost or benefit but CharStream allows fast String handling.
+ // Yes. A lot (Java6).
+
+ // Using a Reader here seems to have zero cost or benefit but CharStream
+ // allows fast String handling.
private final CharStream source ;
-
- private static final int PUSHBACK_SIZE = 10 ;
- static final byte CHAR0 = (char)0 ;
-
- private char[] pushbackChars ;
- private int idxPushback ; // Index into pushbackChars: points to next pushBack. -1 => none.
-
- private int currChar = UNSET ; // Next character to return when reading forwards.
- private long posn ;
-
- public static final int INIT_LINE = 1 ;
- public static final int INIT_COL = 1 ;
-
- private long colNum ;
- private long lineNum ;
-
+
+ private static final int PUSHBACK_SIZE = 10 ;
+ static final byte CHAR0 = (char)0 ;
+
+ private char[] pushbackChars ;
+ private int idxPushback ; // Index into
+ // pushbackChars: points
+ // to next pushBack. -1
+ // => none.
+
+ private int currChar = UNSET ; // Next character to
+ // return when reading
+ // forwards.
+ private long posn ;
+
+ public static final int INIT_LINE = 1 ;
+ public static final int INIT_COL = 1 ;
+
+ private long colNum ;
+ private long lineNum ;
+
// ---- static construction methods.
-
- public static PeekReader make(Reader r)
- {
+
+ public static PeekReader make(Reader r) {
if ( r instanceof PeekReader )
return (PeekReader)r ;
return make(r, CharStreamBuffered.CB_SIZE) ;
}
-
- public static PeekReader make(Reader r, int bufferSize)
- {
- // It is worth our own buffering evcen if a BufferedReader
- // because of the synchronized on one char reads in BufferedReader.
+
+ public static PeekReader make(Reader r, int bufferSize) {
+ // It is worth our own buffering even if a BufferedReader
+ // because of the synchronized on one char reads in BufferedReader.
return new PeekReader(new CharStreamBuffered(r, bufferSize)) ;
}
- /** Make PeekReader where the input is UTF8 : BOM is removed */
- public static PeekReader makeUTF8(InputStream in)
- {
+ /** Make PeekReader where the input is UTF8 : BOM is removed */
+ public static PeekReader makeUTF8(InputStream in) {
// This is the best route to make a PeekReader because it avoids
// chances of wrong charset for a Reader say.
PeekReader pr ;
- if ( true )
- {
+ if ( true ) {
Reader r = IO.asUTF8(in) ;
// This adds reader-level buffering
pr = make(r) ;
- }
- else
- {
+ } else {
// This is a bit slower - reason unknown.
InputStreamBuffered in2 = new InputStreamBuffered(in) ;
CharStream r = new InStreamUTF8(in2) ;
@@ -105,176 +105,174 @@ public final class PeekReader extends Re
pr.readChar() ;
return pr ;
}
-
- /** Make PeekReader where the input is ASCII */
- public static PeekReader makeASCII(InputStream in)
- {
+
+ /** Make PeekReader where the input is ASCII */
+ public static PeekReader makeASCII(InputStream in) {
Reader r = IO.asASCII(in) ;
return make(r) ;
}
-
- public static PeekReader make(CharStream r)
- {
+
+ public static PeekReader make(CharStream r) {
return new PeekReader(r) ;
}
-
- public static PeekReader readString(String string)
- {
+
+ public static PeekReader readString(String string) {
return new PeekReader(new CharStreamSequence(string)) ;
}
-
- public static PeekReader open(String filename)
- {
+
+ public static PeekReader open(String filename) {
try {
InputStream in = new FileInputStream(filename) ;
return makeUTF8(in) ;
- } catch (FileNotFoundException ex){ throw new AtlasException("File not found: "+filename) ; }
+ } catch (FileNotFoundException ex) {
+ throw new AtlasException("File not found: " + filename) ;
+ }
}
-
- private PeekReader(CharStream stream)
- {
+
+ private PeekReader(CharStream stream) {
this.source = stream ;
- this.pushbackChars = new char[PUSHBACK_SIZE] ;
+ this.pushbackChars = new char[PUSHBACK_SIZE] ;
this.idxPushback = -1 ;
-
+
this.colNum = INIT_COL ;
this.lineNum = INIT_LINE ;
this.posn = 0 ;
-
- // We start at character "-1", i.e. just before the file starts.
- // Advance always so that the peek character is valid (is character 0)
- // Returns the character before the file starts (i.e. UNSET).
}
-
- public long getLineNum() { return lineNum; }
- public long getColNum() { return colNum; }
+ public long getLineNum() {
+ return lineNum ;
+ }
+
+ public long getColNum() {
+ return colNum ;
+ }
- public long getPosition() { return posn; }
+ public long getPosition() {
+ return posn ;
+ }
- //---- Do not access currChar except with peekChar/setCurrChar.
- public final int peekChar()
- {
+ // ---- Do not access currChar except with peekChar/setCurrChar.
+ public final int peekChar() {
if ( idxPushback >= 0 )
return pushbackChars[idxPushback] ;
-
+
// If not started ... delayed initialization.
if ( currChar == UNSET )
init() ;
return currChar ;
}
-
+
// And the correct way to read the currChar is to call peekChar.
- private final void setCurrChar(int ch)
- {
+ private final void setCurrChar(int ch) {
currChar = ch ;
}
-
- public final int readChar() { return nextChar() ; }
-
- /** push back a character : does not alter underlying position, line or column counts*/
- public final void pushbackChar(int ch) { unreadChar(ch) ; }
-
+
+ public final int readChar() {
+ return nextChar() ;
+ }
+
+ /**
+ * push back a character : does not alter underlying position, line or
+ * column counts
+ */
+ public final void pushbackChar(int ch) {
+ unreadChar(ch) ;
+ }
+
// Reader operations
@Override
- public final void close() throws IOException
- {
+ public final void close() throws IOException {
source.closeStream() ;
}
@Override
- public final int read() throws IOException
- {
+ public final int read() throws IOException {
if ( eof() )
return EOF ;
int x = readChar() ;
return x ;
}
-
+
@Override
- public final int read(char[] cbuf, int off, int len) throws IOException
- {
+ public final int read(char[] cbuf, int off, int len) throws IOException {
if ( eof() )
return EOF ;
- // Note - need to preserve line count, so single char ops are reasonably efficient.
- for ( int i = 0 ; i < len ; i++ )
- {
+ // Note - we need to preserve line count
+ // Single char ops are reasonably efficient.
+ for (int i = 0; i < len; i++) {
int ch = readChar() ;
if ( ch == EOF )
- return (i==0)? EOF : i ;
- cbuf[i+off] = (char)ch ;
+ return (i == 0) ? EOF : i ;
+ cbuf[i + off] = (char)ch ;
}
return len ;
}
- public final boolean eof() { return peekChar() == EOF ; }
+ public final boolean eof() {
+ return peekChar() == EOF ;
+ }
// ----------------
// The methods below are the only ones to manipulate the character buffers.
// Other methods may read the state of variables.
-
- private final void unreadChar(int ch)
- {
+
+ private final void unreadChar(int ch) {
// The push back buffer is in the order where [0] is the oldest.
- // Does not alter the line number, column number or position count.
-
- if ( idxPushback >= pushbackChars.length )
- {
+ // Does not alter the line number, column number or position count
+ // not does reading a pushback charcater.
+
+ if ( idxPushback >= pushbackChars.length ) {
// Enlarge pushback buffer.
- char[] pushbackChars2 = new char[pushbackChars.length*2] ;
+ char[] pushbackChars2 = new char[pushbackChars.length * 2] ;
System.arraycopy(pushbackChars, 0, pushbackChars2, 0, pushbackChars.length) ;
pushbackChars = pushbackChars2 ;
- //throw new JenaException("Pushback buffer overflow") ;
+ // throw new JenaException("Pushback buffer overflow") ;
}
if ( ch == EOF || ch == UNSET )
- throw new JenaException("Illegal character to push back: "+ch) ;
-
+ throw new JenaException("Illegal character to push back: " + ch) ;
+
idxPushback++ ;
pushbackChars[idxPushback] = (char)ch ;
}
-
- private final void init()
- {
+
+ private final void init() {
advanceAndSet() ;
if ( currChar == UNSET )
setCurrChar(EOF) ;
}
- private final void advanceAndSet()
- {
+ private final void advanceAndSet() {
int ch = source.advance() ;
setCurrChar(ch) ;
}
-
-
+
// Invariants.
// currChar is either chars[idx-1] or pushbackChars[idxPushback]
-
- /** Return the next character, moving on one place and resetting the peek character */
- private final int nextChar()
- {
+
+ /**
+ * Return the next character, moving on one place and resetting the peek
+ * character
+ */
+ private final int nextChar() {
int ch = peekChar() ;
-
+
if ( ch == EOF )
return EOF ;
-
- if ( idxPushback >= 0 )
- {
+
+ if ( idxPushback >= 0 ) {
char ch2 = pushbackChars[idxPushback] ;
idxPushback-- ;
return ch2 ;
}
posn++ ;
-
- if (ch == '\n')
- {
- lineNum++;
+
+ if ( ch == '\n' ) {
+ lineNum++ ;
colNum = INIT_COL ;
- }
- else
- colNum++;
-
+ } else
+ colNum++ ;
+
advanceAndSet() ;
return ch ;
}
Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/tokens/TokenizerText.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/tokens/TokenizerText.java?rev=1542235&r1=1542234&r2=1542235&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/tokens/TokenizerText.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/tokens/TokenizerText.java Fri Nov 15 11:23:12 2013
@@ -64,15 +64,13 @@ public final class TokenizerText impleme
this(reader, false) ;
}
- /*package*/ TokenizerText(PeekReader reader, boolean lineMode)
- {
+ /* package */TokenizerText(PeekReader reader, boolean lineMode) {
this.reader = reader ;
- this.lineMode = lineMode ;
+ this.lineMode = lineMode ;
}
@Override
- public final boolean hasNext()
- {
+ public final boolean hasNext() {
if ( finished )
return false ;
if ( token != null )
@@ -80,159 +78,141 @@ public final class TokenizerText impleme
try {
skip() ;
- if (reader.eof())
- {
- //close() ;
+ if ( reader.eof() ) {
+ // close() ;
finished = true ;
return false ;
}
token = parseToken() ;
- if ( token == null )
- {
- //close() ;
+ if ( token == null ) {
+ // close() ;
finished = true ;
return false ;
}
return true ;
- } catch (AtlasException ex)
- {
- if ( ex.getCause() != null )
- {
+ } catch (AtlasException ex) {
+ if ( ex.getCause() != null ) {
if ( ex.getCause().getClass() == java.nio.charset.MalformedInputException.class )
throw new RiotParseException("Bad character encoding", reader.getLineNum(), reader.getColNum()) ;
- throw new RiotParseException("Bad input stream ["+ex.getCause()+"]", reader.getLineNum(), reader.getColNum()) ;
+ throw new RiotParseException("Bad input stream [" + ex.getCause() + "]", reader.getLineNum(),
+ reader.getColNum()) ;
}
throw new RiotParseException("Bad input stream", reader.getLineNum(), reader.getColNum()) ;
}
- }
+ }
@Override
- public final boolean eof()
- {
+ public final boolean eof() {
return hasNext() ;
}
@Override
- public final Token next()
- {
- if ( ! hasNext() )
+ public final Token next() {
+ if ( !hasNext() )
throw new NoSuchElementException() ;
Token t = token ;
token = null ;
return t ;
}
-
+
@Override
- public final Token peek()
- {
- if ( ! hasNext() ) return null ;
- return token ;
+ public final Token peek() {
+ if ( !hasNext() )
+ return null ;
+ return token ;
}
@Override
- public void remove()
- { throw new UnsupportedOperationException() ; }
+ public void remove() { throw new UnsupportedOperationException() ; }
- public TokenChecker getChecker() { return checker ; }
- public void setChecker(TokenChecker checker) { this.checker = checker ; }
+ public TokenChecker getChecker() { return checker ; }
+ public void setChecker(TokenChecker checker) { this.checker = checker ; }
@Override
- public void close()
- {
+ public void close() {
IO.close(reader) ;
}
// ---- Machinary
- private void skip()
- {
+ private void skip() {
int ch = EOF ;
- for ( ;; )
- {
+ for (;;) {
if ( reader.eof() )
return ;
-
+
ch = reader.peekChar() ;
- if ( ch == CH_HASH )
- {
+ if ( ch == CH_HASH ) {
reader.readChar() ;
- // Comment. Skip to NL
- for ( ;; )
- {
+ // Comment. Skip to NL
+ for (;;) {
ch = reader.peekChar() ;
if ( ch == EOF || isNewlineChar(ch) )
break ;
reader.readChar() ;
}
}
-
+
// Including excess newline chars from comment.
if ( lineMode ) {
- if ( ! isHorizontalWhitespace(ch) )
+ if ( !isHorizontalWhitespace(ch) )
break ;
} else {
- if ( ! isWhitespace(ch) )
+ if ( !isWhitespace(ch) )
break ;
}
reader.readChar() ;
}
}
- private Token parseToken()
- {
+ private Token parseToken() {
token = new Token(getLine(), getColumn()) ;
-
+
int ch = reader.peekChar() ;
// ---- IRI
- if ( ch == CH_LT )
- {
+ if ( ch == CH_LT ) {
reader.readChar() ;
token.setImage(readIRI()) ;
token.setType(TokenType.IRI) ;
- if ( Checking ) checkURI(token.getImage()) ;
+ if ( Checking )
+ checkURI(token.getImage()) ;
return token ;
}
// ---- Literal
- if ( ch == CH_QUOTE1 || ch == CH_QUOTE2 )
- {
+ if ( ch == CH_QUOTE1 || ch == CH_QUOTE2 ) {
reader.readChar() ;
int ch2 = reader.peekChar() ;
- if (ch2 == ch )
- {
+ if ( ch2 == ch ) {
reader.readChar() ; // Read potential second quote.
int ch3 = reader.peekChar() ;
- if ( ch3 == ch )
- {
+ if ( ch3 == ch ) {
reader.readChar() ;
token.setImage(readLongString(ch, false)) ;
TokenType tt = (ch == CH_QUOTE1) ? TokenType.LONG_STRING1 : TokenType.LONG_STRING2 ;
token.setType(tt) ;
- }
- else
- {
+ } else {
// Two quotes then a non-quote.
// Must be '' or ""
- // No need to pushback characters as we know the lexical form is the empty string.
- //if ( ch2 != EOF ) reader.pushbackChar(ch2) ;
- //if ( ch1 != EOF ) reader.pushbackChar(ch1) ; // Must be '' or ""
+ // No need to pushback characters as we know the lexical
+ // form is the empty string.
+ // if ( ch2 != EOF ) reader.pushbackChar(ch2) ;
+ // if ( ch1 != EOF ) reader.pushbackChar(ch1) ; // Must be
+ // '' or ""
token.setImage("") ;
- token.setType( (ch == CH_QUOTE1) ? TokenType.STRING1 : TokenType.STRING2 ) ;
+ token.setType((ch == CH_QUOTE1) ? TokenType.STRING1 : TokenType.STRING2) ;
}
- }
- else
- {
+ } else {
// Single quote character.
token.setImage(readString(ch, ch, true)) ;
// Single quoted string.
- token.setType( (ch == CH_QUOTE1) ? TokenType.STRING1 : TokenType.STRING2 ) ;
+ token.setType((ch == CH_QUOTE1) ? TokenType.STRING1 : TokenType.STRING2) ;
}
-
- // Literal. Is it @ or ^^
- if ( reader.peekChar() == CH_AT )
- {
+
+ // Literal. Is it @ or ^^
+ if ( reader.peekChar() == CH_AT ) {
reader.readChar() ;
Token mainToken = new Token(token) ;
@@ -240,49 +220,39 @@ public final class TokenizerText impleme
mainToken.setSubToken1(token) ;
mainToken.setImage2(langTag()) ;
token = mainToken ;
-
-// token.setImage2(langTag()) ;
-// token.setType(TokenType.LITERAL_LANG) ;
- if ( Checking ) checkLiteralLang(token.getImage(), token.getImage2()) ;
- }
- else if ( reader.peekChar() == '^' )
- {
+ if ( Checking )
+ checkLiteralLang(token.getImage(), token.getImage2()) ;
+ } else if ( reader.peekChar() == '^' ) {
expect("^^") ;
-
- // Recursive call!
// Check no whitespace.
int nextCh = reader.peekChar() ;
if ( isWhitespace(nextCh) )
exception("No whitespace after ^^ in literal with datatype") ;
-// // Now done by getting the next token and checking what type it is.
-// if ( nextCh != '<' && ! isAlpha(nextCh) && nextCh != ':' )
-// exception("Datatype URI required after ^^ - URI or prefixed name expected") ;
-
// Stash current token.
Token mainToken = new Token(token) ;
mainToken.setSubToken1(token) ;
- mainToken.setImage(token.getImage()) ;
-
+ mainToken.setImage(token.getImage()) ;
+
Token subToken = parseToken() ;
- if ( ! subToken.isIRI() )
+ if ( !subToken.isIRI() )
exception("Datatype URI required after ^^ - URI or prefixed name expected") ;
-
+
mainToken.setSubToken2(subToken) ;
mainToken.setType(TokenType.LITERAL_DT) ;
-
+
token = mainToken ;
- if ( Checking ) checkLiteralDT(token.getImage(), subToken) ;
- }
- else
- {
+ if ( Checking )
+ checkLiteralDT(token.getImage(), subToken) ;
+ } else {
// Was a simple string.
- if ( Checking ) checkString(token.getImage()) ;
+ if ( Checking )
+ checkString(token.getImage()) ;
}
return token ;
}
- if ( ch == CH_UNDERSCORE ) // Blank node :label must be at least one char
- {
+ if ( ch == CH_UNDERSCORE ) {
+ // Blank node :label must be at least one char
expect("_:") ;
token.setImage(readBlankNodeLabel()) ;
token.setType(TokenType.BNODE) ;
@@ -292,39 +262,39 @@ public final class TokenizerText impleme
// TODO remove and make a symbol/keyword.
// Control
- if ( ch == CTRL_CHAR )
- {
+ if ( ch == CTRL_CHAR ) {
reader.readChar() ;
token.setType(TokenType.CNTRL) ;
ch = reader.readChar() ;
if ( ch == EOF )
- exception("EOF found after "+CTRL_CHAR) ;
+ exception("EOF found after " + CTRL_CHAR) ;
if ( RiotChars.isWhitespace(ch) )
token.cntrlCode = -1 ;
else
token.cntrlCode = (char)ch ;
- if ( Checking ) checkControl(token.cntrlCode) ;
+ if ( Checking )
+ checkControl(token.cntrlCode) ;
return token ;
}
// A directive (not part of a literal as lang tag)
- if ( ch == CH_AT )
- {
+ if ( ch == CH_AT ) {
reader.readChar() ;
token.setType(TokenType.DIRECTIVE) ;
- token.setImage(readWord(false)) ;
- if ( Checking ) checkDirective(token.cntrlCode) ;
+ token.setImage(readWord(false)) ;
+ if ( Checking )
+ checkDirective(token.cntrlCode) ;
return token ;
}
-
+
// Variable
- if ( ch == CH_QMARK )
- {
+ if ( ch == CH_QMARK ) {
reader.readChar() ;
token.setType(TokenType.VAR) ;
// Character set?
- token.setImage(readVarName()) ;
- if ( Checking ) checkVariable(token.getImage()) ;
+ token.setImage(readVarName()) ;
+ if ( Checking )
+ checkVariable(token.getImage()) ;
return token ;
}
@@ -335,12 +305,12 @@ public final class TokenizerText impleme
case CH_DOT:
reader.readChar() ;
ch = reader.peekChar() ;
- if ( range(ch, '0', '9') )
- {
+ if ( range(ch, '0', '9') ) {
// Not a DOT after all.
reader.pushbackChar(CH_DOT) ;
readNumber() ;
- if ( Checking ) checkNumber(token.getImage(), token.getImage2() ) ;
+ if ( Checking )
+ checkNumber(token.getImage(), token.getImage2()) ;
return token ;
}
token.setType(TokenType.DOT) ;
@@ -393,16 +363,14 @@ public final class TokenizerText impleme
// TODO readNumberNoSign
int signCh = 0 ;
-
- if ( ch == CH_PLUS || ch == CH_MINUS )
- {
+
+ if ( ch == CH_PLUS || ch == CH_MINUS ) {
reader.readChar() ;
int ch2 = reader.peekChar() ;
-
- if ( ! range(ch2, '0', '9') )
- {
+
+ if ( !range(ch2, '0', '9') ) {
// ch was end of symbol.
- //reader.readChar() ;
+ // reader.readChar() ;
if ( ch == CH_PLUS )
token.setType(TokenType.PLUS) ;
else
@@ -412,24 +380,22 @@ public final class TokenizerText impleme
// Already got a + or - ...
// readNumberNoSign
-
// Because next, old code proceses signs.
- // FIXME
reader.pushbackChar(ch) ;
signCh = ch ;
// Drop to next "if"
}
-
- if ( ch == CH_PLUS || ch == CH_MINUS || range(ch, '0', '9') )
- {
+
+ if ( ch == CH_PLUS || ch == CH_MINUS || range(ch, '0', '9') ) {
// readNumberNoSign
readNumber() ;
- if ( Checking ) checkNumber(token.getImage(), token.getImage2() ) ;
+ if ( Checking )
+ checkNumber(token.getImage(), token.getImage2()) ;
return token ;
}
if ( isNewlineChar(ch) ) {
- //** - If collecting tokne image.
+ //** - If collecting token image.
//** stringBuilder.setLength(0) ;
// Any number of NL and CR become one "NL" token.
do {
@@ -454,57 +420,43 @@ public final class TokenizerText impleme
private static final boolean VeryVeryLax = false ;
- //static char[] badIRIchars = { '<', '>', '{', '}', '|', '\\', '`', '^', ' ' } ;
- private String readIRI()
- {
- //token.setImage(readString(CH_LT, CH_GT, false)) ;
+ private String readIRI() {
stringBuilder.setLength(0) ;
- for(;;)
- {
+ for (;;) {
int ch = reader.readChar() ;
- if ( ch == EOF )
- {
- //if ( endNL ) return stringBuilder.toString() ;
- exception("Broken IRI: "+stringBuilder.toString()) ;
+ if ( ch == EOF ) {
+ exception("Broken IRI: " + stringBuilder.toString()) ;
}
if ( ch == '\n' )
- exception("Broken IRI (newline): "+stringBuilder.toString()) ;
-
- if ( ch == CH_GT )
- {
- //sb.append(((char)ch)) ;
+ exception("Broken IRI (newline): " + stringBuilder.toString()) ;
+
+ if ( ch == CH_GT ) {
return stringBuilder.toString() ;
}
-
- if ( ch == '\\' )
- {
- // N-Triples strictly allows \t\n etc in IRIs (grammar says "string escapes")
- // ch = strEscapes ? readLiteralEscape() : readUnicodeEscape() ;
-
+
+ if ( ch == '\\' ) {
if ( VeryVeryLax )
ch = readCharEscapeAnyURI() ;
else
- // NORMAL
+ // NORMAL
ch = readUnicodeEscape() ;
// Drop through.
}
// Ban certain very bad characters
if ( !VeryVeryLax && ch == '<' )
- exception("Broken IRI (bad character: '%c'): %s",ch,stringBuilder.toString()) ;
+ exception("Broken IRI (bad character: '%c'): %s", ch, stringBuilder.toString()) ;
insertCodepoint(stringBuilder, ch) ;
}
}
private final
- int readCharEscapeAnyURI()
- {
+ int readCharEscapeAnyURI() {
int c = reader.readChar();
if ( c==EOF )
exception("Escape sequence not completed") ;
- switch (c)
- {
+ switch (c) {
case 'u': return readUnicode4Escape();
case 'U': return readUnicode8Escape();
default:
@@ -513,28 +465,29 @@ public final class TokenizerText impleme
}
}
- private void readPrefixedNameOrKeyword(Token token)
- {
+ private void readPrefixedNameOrKeyword(Token token) {
long posn = reader.getPosition() ;
- String prefixPart = readPrefixPart() ; // Prefix part or keyword
+ String prefixPart = readPrefixPart() ; // Prefix part or keyword
token.setImage(prefixPart) ;
token.setType(TokenType.KEYWORD) ;
int ch = reader.peekChar() ;
- if ( ch == CH_COLON )
- {
+ if ( ch == CH_COLON ) {
reader.readChar() ;
token.setType(TokenType.PREFIXED_NAME) ;
String ln = readLocalPart() ; // Local part
token.setImage2(ln) ;
- if ( Checking ) checkPrefixedName(token.getImage(), token.getImage2()) ;
+ if ( Checking )
+ checkPrefixedName(token.getImage(), token.getImage2()) ;
}
- // If we made no progress, nothing found, not even a keyword -- it's an error.
- if ( posn == reader.getPosition() )
- exception("Unknown char: %c(%d;0x%04X)",ch,ch,ch) ;
+ // If we made no progress, nothing found, not even a keyword -- it's an
+ // error.
+ if ( posn == reader.getPosition() )
+ exception("Unknown char: %c(%d;0x%04X)", ch, ch, ch) ;
+
+ if ( Checking )
+ checkKeyword(token.getImage()) ;
- if ( Checking ) checkKeyword(token.getImage()) ;
-
}
/*
@@ -560,64 +513,54 @@ public final class TokenizerText impleme
private String readLocalPart()
{ return readSegment(true) ; }
- private String readSegment(boolean isLocalPart)
- {
+ private String readSegment(boolean isLocalPart) {
// Prefix: PN_CHARS_BASE ((PN_CHARS|'.')* PN_CHARS)?
// Local: ( PN_CHARS_U | ':' | [0-9] | PLX ) ((PN_CHARS | '.' | ':' | PLX)* (PN_CHARS | ':' | PLX) )?
// RiotChars has isPNChars_U_N for ( PN_CHARS_U | [0-9] )
stringBuilder.setLength(0) ;
-
+
// -- Test first character
int ch = reader.peekChar() ;
if ( ch == EOF )
return "" ;
- if ( isLocalPart )
- {
- if ( ch == CH_COLON )
- {
+ if ( isLocalPart ) {
+ if ( ch == CH_COLON ) {
reader.readChar() ;
stringBuilder.append((char)ch) ;
}
-
+
// processPLX
- else if ( ch == CH_PERCENT|| ch == CH_RSLASH )
- {
+ else if ( ch == CH_PERCENT || ch == CH_RSLASH ) {
reader.readChar() ;
processPLX(ch) ;
- }
- else if ( RiotChars.isPNChars_U_N(ch) )
- {
+ } else if ( RiotChars.isPNChars_U_N(ch) ) {
stringBuilder.append((char)ch) ;
reader.readChar() ;
- }
- else
+ } else
+ return "" ;
+ } else {
+ if ( !RiotChars.isPNCharsBase(ch) )
return "" ;
- }
- else
- {
- if ( ! RiotChars.isPNCharsBase(ch) ) return "" ;
stringBuilder.append((char)ch) ;
reader.readChar() ;
}
// Done first character
int chDot = 0 ;
-
- for (;;)
- {
+
+ for (;;) {
ch = reader.peekChar() ;
boolean valid = false ;
- if ( isLocalPart && ( ch == CH_PERCENT|| ch == CH_RSLASH ) )
- {
+ if ( isLocalPart && (ch == CH_PERCENT || ch == CH_RSLASH) ) {
reader.readChar() ;
if ( chDot != 0 )
stringBuilder.append((char)chDot) ;
processPLX(ch) ;
chDot = 0 ;
continue ;
- }
-
+ }
+
// Single valid characters
if ( isLocalPart && ch == CH_COLON )
valid = true ;
@@ -628,25 +571,24 @@ public final class TokenizerText impleme
else
valid = false ;
- if ( ! valid )
+ if ( !valid )
break ; // Exit loop
// Valid character.
reader.readChar() ;
// Was there also a DOT previous loop?
- if ( chDot != 0 )
- {
+ if ( chDot != 0 ) {
stringBuilder.append((char)chDot) ;
chDot = 0 ;
}
-
+
if ( ch != CH_DOT )
stringBuilder.append((char)ch) ;
else
- //DOT - delay until next loop.
+ // DOT - delay until next loop.
chDot = ch ;
}
-
+
// On exit, chDot may hold a character.
if ( chDot == CH_DOT )
@@ -686,38 +628,29 @@ public final class TokenizerText impleme
// Get characters between two markers.
// strEscapes may be processed
// endNL end of line as an ending is OK
- private String readString(int startCh, int endCh, boolean strEscapes)
- {
+ private String readString(int startCh, int endCh, boolean strEscapes) {
long y = getLine() ;
long x = getColumn() ;
stringBuilder.setLength(0) ;
+ // Assumes first delimiter char read already.
+ // Reads terminating delimiter
- // Assumes first char read already.
- // int ch0 = reader.readChar() ;
- // if ( ch0 != startCh )
- // exception("Broken parser", y, x) ;
-
-
- for(;;)
- {
+ for (;;) {
int ch = reader.readChar() ;
- if ( ch == EOF )
- {
- //if ( endNL ) return stringBuilder.toString() ;
- exception("Broken token: "+stringBuilder.toString(), y, x) ;
+ if ( ch == EOF ) {
+ // if ( endNL ) return stringBuilder.toString() ;
+ exception("Broken token: " + stringBuilder.toString(), y, x) ;
}
if ( ch == NL )
- exception("Broken token (newline): "+stringBuilder.toString(), y, x) ;
+ exception("Broken token (newline): " + stringBuilder.toString(), y, x) ;
- if ( ch == endCh )
- {
- //sb.append(((char)ch)) ;
+ if ( ch == endCh ) {
+ // sb.append(((char)ch)) ;
return stringBuilder.toString() ;
}
- if ( ch == CH_RSLASH )
- {
+ if ( ch == CH_RSLASH ) {
ch = strEscapes ? readLiteralEscape() : readUnicodeEscape() ;
// Drop through.
}
@@ -725,24 +658,21 @@ public final class TokenizerText impleme
}
}
- private String readLongString(int quoteChar, boolean endNL)
- {
+ private String readLongString(int quoteChar, boolean endNL) {
stringBuilder.setLength(0) ;
- for ( ;; )
- {
+ for (;;) {
int ch = reader.readChar() ;
- if ( ch == EOF )
- {
- if ( endNL ) return stringBuilder.toString() ;
+ if ( ch == EOF ) {
+ if ( endNL )
+ return stringBuilder.toString() ;
exception("Broken long string") ;
}
-
- if ( ch == quoteChar )
- {
+
+ if ( ch == quoteChar ) {
if ( threeQuotes(quoteChar) )
return stringBuilder.toString() ;
}
-
+
if ( ch == CH_RSLASH )
ch = readLiteralEscape() ;
insertCodepoint(stringBuilder, ch) ;
@@ -759,64 +689,56 @@ public final class TokenizerText impleme
static private char[] extraCharsWord = new char[] {'_', '.' , '-'};
- private String readWordSub(boolean leadingDigitAllowed, boolean leadingSignAllowed)
- {
+ private String readWordSub(boolean leadingDigitAllowed, boolean leadingSignAllowed) {
return readCharsAnd(leadingDigitAllowed, leadingSignAllowed, extraCharsWord, false) ;
}
-
- static private char[] extraCharsVar = new char[] {'_', '.' , '-', '?', '@', '+'};
- private String readVarName()
- {
+
+ static private char[] extraCharsVar = new char[]{'_', '.', '-', '?', '@', '+'} ;
+
+ private String readVarName() {
return readCharsAnd(true, true, extraCharsVar, true) ;
}
// See also readBlankNodeLabel
- private String readCharsAnd(boolean leadingDigitAllowed, boolean leadingSignAllowed, char[] extraChars, boolean allowFinalDot)
- {
+ private String readCharsAnd(boolean leadingDigitAllowed, boolean leadingSignAllowed, char[] extraChars,
+ boolean allowFinalDot) {
stringBuilder.setLength(0) ;
int idx = 0 ;
- if ( ! leadingDigitAllowed )
- {
+ if ( !leadingDigitAllowed ) {
int ch = reader.peekChar() ;
if ( Character.isDigit(ch) )
return "" ;
}
-
- // Used for local part of prefix names =>
- if ( ! leadingSignAllowed )
- {
+
+ // Used for local part of prefix names =>
+ if ( !leadingSignAllowed ) {
int ch = reader.peekChar() ;
if ( ch == '-' || ch == '+' )
return "" ;
}
-
- for ( ;; idx++ )
- {
+
+ for (;; idx++) {
int ch = reader.peekChar() ;
-
- if ( isAlphaNumeric(ch) || charInArray(ch, extraChars) )
- {
+
+ if ( isAlphaNumeric(ch) || charInArray(ch, extraChars) ) {
reader.readChar() ;
stringBuilder.append((char)ch) ;
continue ;
- }
- else
+ } else
// Inappropriate character.
break ;
-
+
}
-
- if ( ! allowFinalDot )
- {
+
+ if ( !allowFinalDot ) {
// BAD : assumes pushbackChar is infinite.
// Check is ends in "."
- while ( idx > 0 && stringBuilder.charAt(idx-1) == CH_DOT )
- {
+ while (idx > 0 && stringBuilder.charAt(idx - 1) == CH_DOT) {
// Push back the dot.
reader.pushbackChar(CH_DOT) ;
- stringBuilder.setLength(idx-1) ;
- idx -- ;
+ stringBuilder.setLength(idx - 1) ;
+ idx-- ;
}
}
return stringBuilder.toString() ;
@@ -824,74 +746,67 @@ public final class TokenizerText impleme
// BLANK_NODE_LABEL ::= '_:' (PN_CHARS_U | [0-9]) ((PN_CHARS | '.')* PN_CHARS)?
- private String readBlankNodeLabel()
- {
+ private String readBlankNodeLabel() {
stringBuilder.setLength(0) ;
// First character.
{
int ch = reader.peekChar() ;
if ( ch == EOF )
exception("Blank node label missing (EOF found)") ;
- if ( isWhitespace(ch))
+ if ( isWhitespace(ch) )
exception("Blank node label missing") ;
- //if ( ! isAlpha(ch) && ch != '_' )
+ // if ( ! isAlpha(ch) && ch != '_' )
// Not strict
-
- if ( ! RiotChars.isPNChars_U_N(ch) )
- exception("Blank node label does not start with alphabetic or _ :"+(char)ch) ;
+
+ if ( !RiotChars.isPNChars_U_N(ch) )
+ exception("Blank node label does not start with alphabetic or _ :" + (char)ch) ;
reader.readChar() ;
stringBuilder.append((char)ch) ;
}
-
- // Remainder. DOT can't be last so do a delay on that.
-
+
+ // Remainder. DOT can't be last so do a delay on that.
+
int chDot = 0 ;
-
- for(;;)
- {
+
+ for (;;) {
int ch = reader.peekChar() ;
if ( ch == EOF )
break ;
-
+
// DOT magic.
- if ( ! ( RiotChars.isPNChars(ch) || ch == CH_DOT ) )
+ if ( !(RiotChars.isPNChars(ch) || ch == CH_DOT) )
break ;
reader.readChar() ;
-
- if ( chDot != 0 )
- {
+
+ if ( chDot != 0 ) {
stringBuilder.append((char)chDot) ;
chDot = 0 ;
}
-
+
if ( ch != CH_DOT )
stringBuilder.append((char)ch) ;
else
- //DOT - delay until next loop.
+ // DOT - delay until next loop.
chDot = ch ;
}
-
+
if ( chDot == CH_DOT )
// Unread it.
reader.pushbackChar(chDot) ;
-
- // if ( ! seen )
- // exception("Blank node label missing") ;
- return stringBuilder.toString() ;
+
+ // if ( ! seen )
+ // exception("Blank node label missing") ;
+ return stringBuilder.toString() ;
}
- // Make better!
/*
* [146] INTEGER ::= [0-9]+
* [147] DECIMAL ::= [0-9]* '.' [0-9]+
* [148] DOUBLE ::= [0-9]+ '.' [0-9]* EXPONENT | '.' ([0-9])+ EXPONENT | ([0-9])+ EXPONENT
* [] hex ::= 0x0123456789ABCDEFG
-
- */
- private void readNumber()
- {
+ */
+ private void readNumber() {
// One entry, definitely a number.
- //
// Beware of '.' as a (non) decimal.
/*
maybeSign()
@@ -913,17 +828,14 @@ public final class TokenizerText impleme
readExponent.
*/
-
int x = 0 ; // Digits before a dot.
int ch = reader.peekChar() ;
- if ( ch == '0' )
- {
+ if ( ch == '0' ) {
x++ ;
reader.readChar() ;
stringBuilder.append((char)ch) ;
ch = reader.peekChar() ;
- if ( ch == 'x' || ch == 'X' )
- {
+ if ( ch == 'x' || ch == 'X' ) {
reader.readChar() ;
stringBuilder.append((char)ch) ;
readHex(reader, stringBuilder) ;
@@ -931,52 +843,40 @@ public final class TokenizerText impleme
token.setType(TokenType.HEX) ;
return ;
}
- }
- else if ( ch == '-' || ch == '+' )
- {
+ } else if ( ch == '-' || ch == '+' ) {
readPossibleSign(stringBuilder) ;
}
-
+
x += readDigits(stringBuilder) ;
-// if ( x == 0 )
-// {
-//
-// }
+// if ( x == 0 ) {}
ch = reader.peekChar() ;
- if ( ch == CH_DOT )
- {
+ if ( ch == CH_DOT ) {
reader.readChar() ;
stringBuilder.append(CH_DOT) ;
- isDecimal = true ; // Includes things that will be doubles.
+ isDecimal = true ; // Includes things that will be doubles.
readDigits(stringBuilder) ;
}
-
- if ( x == 0 && ! isDecimal )
- // Possible a tokenizer error - should not have entered readNumber in the first place.
+
+ if ( x == 0 && !isDecimal )
+ // Possible a tokenizer error - should not have entered readNumber
+ // in the first place.
exception("Unrecognized as number") ;
-
- if ( exponent(stringBuilder) )
- {
+
+ if ( exponent(stringBuilder) ) {
isDouble = true ;
isDecimal = false ;
-
}
- //****
// Final part - "decimal" 123. is an integer 123 and a DOT.
- if ( isDecimal )
- {
+ if ( isDecimal ) {
int len = stringBuilder.length() ;
- if ( stringBuilder.charAt(len-1) == CH_DOT )
- {
- stringBuilder.setLength(len-1) ;
+ if ( stringBuilder.charAt(len - 1) == CH_DOT ) {
+ stringBuilder.setLength(len - 1) ;
reader.pushbackChar(CH_DOT) ;
isDecimal = false ;
}
-
}
-
-
+
token.setImage(stringBuilder.toString()) ;
if ( isDouble )
token.setType(TokenType.DOUBLE) ;
@@ -986,44 +886,38 @@ public final class TokenizerText impleme
token.setType(TokenType.INTEGER) ;
}
- private static void readHex(PeekReader reader, StringBuilder sb)
- {
+ private static void readHex(PeekReader reader, StringBuilder sb) {
// Just after the 0x, which are in sb
int x = 0 ;
- for(;;)
- {
+ for (;;) {
int ch = reader.peekChar() ;
- if ( ! isHexChar(ch) )
+ if ( !isHexChar(ch) )
break ;
reader.readChar() ;
sb.append((char)ch) ;
x++ ;
}
if ( x == 0 )
- exception(reader, "No hex characters after "+sb.toString()) ;
+ exception(reader, "No hex characters after " + sb.toString()) ;
}
- private int readDigits(StringBuilder buffer)
- {
+ private int readDigits(StringBuilder buffer) {
int count = 0 ;
- for(;;)
- {
+ for (;;) {
int ch = reader.peekChar() ;
- if ( ! range(ch, '0', '9' ) )
+ if ( !range(ch, '0', '9') )
break ;
reader.readChar() ;
buffer.append((char)ch) ;
- count ++ ;
+ count++ ;
}
return count ;
}
- private void readPossibleSign(StringBuilder sb)
- {
+ private void readPossibleSign(StringBuilder sb) {
int ch = reader.peekChar() ;
- if ( ch == '-' || ch == '+' )
- {
+ if ( ch == '-' || ch == '+' ) {
reader.readChar() ;
sb.append((char)ch) ;
}
@@ -1033,32 +927,28 @@ public final class TokenizerText impleme
// On return:
// If false, have moved over no more characters (due to pushbacks)
// If true, at end of 3 quotes
- private boolean threeQuotes(int ch)
- {
- //reader.readChar() ; // Read first quote.
+ private boolean threeQuotes(int ch) {
+ // reader.readChar() ; // Read first quote.
int ch2 = reader.peekChar() ;
- if (ch2 != ch )
- {
- //reader.pushbackChar(ch2) ;
+ if ( ch2 != ch ) {
+ // reader.pushbackChar(ch2) ;
return false ;
}
-
- reader.readChar() ; // Read second quote.
+
+ reader.readChar() ; // Read second quote.
int ch3 = reader.peekChar() ;
- if ( ch3 != ch )
- {
- //reader.pushbackChar(ch3) ;
+ if ( ch3 != ch ) {
+ // reader.pushbackChar(ch3) ;
reader.pushbackChar(ch2) ;
return false ;
}
-
+
// Three quotes.
- reader.readChar() ; // Read third quote.
+ reader.readChar() ; // Read third quote.
return true ;
}
- private boolean exponent(StringBuilder sb)
- {
+ private boolean exponent(StringBuilder sb) {
int ch = reader.peekChar() ;
if ( ch != 'e' && ch != 'E' )
return false ;
@@ -1067,75 +957,60 @@ public final class TokenizerText impleme
readPossibleSign(sb) ;
int x = readDigits(sb) ;
if ( x == 0 )
- exception("Malformed double: "+sb) ;
+ exception("Malformed double: " + sb) ;
return true ;
}
- private String langTag()
- {
+ private String langTag() {
stringBuilder.setLength(0) ;
a2z(stringBuilder) ;
if ( stringBuilder.length() == 0 )
exception("Bad language tag") ;
- for ( ;; )
- {
+ for (;;) {
int ch = reader.peekChar() ;
- if ( ch == '-' )
- {
+ if ( ch == '-' ) {
reader.readChar() ;
stringBuilder.append('-') ;
- int x = stringBuilder.length();
+ int x = stringBuilder.length() ;
a2zN(stringBuilder) ;
if ( stringBuilder.length() == x )
exception("Bad language tag") ;
- }
- else
+ } else
break ;
}
- return stringBuilder.toString();
+ return stringBuilder.toString() ;
}
// ASCII-only e.g. in lang tags.
- private void a2z(StringBuilder sb2)
- {
- for ( ;; )
- {
+ private void a2z(StringBuilder sb2) {
+ for (;;) {
int ch = reader.peekChar() ;
- if ( isA2Z(ch) )
- {
+ if ( isA2Z(ch) ) {
reader.readChar() ;
stringBuilder.append((char)ch) ;
- }
- else
+ } else
return ;
}
}
-
- private void a2zN(StringBuilder sb2)
- {
- for ( ;; )
- {
+
+ private void a2zN(StringBuilder sb2) {
+ for (;;) {
int ch = reader.peekChar() ;
- if ( isA2ZN(ch) )
- {
+ if ( isA2ZN(ch) ) {
reader.readChar() ;
stringBuilder.append((char)ch) ;
- }
- else
+ } else
return ;
}
}
-
- private void insertCodepoint(StringBuilder buffer, int ch)
- {
+ private void insertCodepoint(StringBuilder buffer, int ch) {
if ( Character.charCount(ch) == 1 )
buffer.append((char)ch) ;
- else
- {
- // Convert to UTF-16. Note that the rest of any system this is used
- // in must also respect codepoints and surrogate pairs.
- if ( ! Character.isDefined(ch) && ! Character.isSupplementaryCodePoint(ch) )
+ else {
+ // Convert to UTF-16. Note that the rest of any system this is used
+ // in must also respect codepoints and surrogate pairs.
+ if ( !Character.isDefined(ch) && !Character.isSupplementaryCodePoint(ch) )
exception("Illegal codepoint: 0x%04X", ch) ;
char[] chars = Character.toChars(ch) ;
buffer.append(chars) ;
@@ -1143,85 +1018,80 @@ public final class TokenizerText impleme
}
@Override
- public long getColumn()
- {
+ public long getColumn() {
return reader.getColNum() ;
}
@Override
- public long getLine()
- {
+ public long getLine() {
return reader.getLineNum() ;
}
// ---- Routines to check tokens
-
- private void checkBlankNode(String blankNodeLabel)
- {
- if ( checker != null ) checker.checkBlankNode(blankNodeLabel) ;
+
+ private void checkBlankNode(String blankNodeLabel) {
+ if ( checker != null )
+ checker.checkBlankNode(blankNodeLabel) ;
}
- private void checkLiteralLang(String lexicalForm, String langTag)
- {
- if ( checker != null ) checker.checkLiteralLang(lexicalForm, langTag) ;
+ private void checkLiteralLang(String lexicalForm, String langTag) {
+ if ( checker != null )
+ checker.checkLiteralLang(lexicalForm, langTag) ;
}
- private void checkLiteralDT(String lexicalForm, Token datatype)
- {
- if ( checker != null ) checker.checkLiteralDT(lexicalForm, datatype) ;
+ private void checkLiteralDT(String lexicalForm, Token datatype) {
+ if ( checker != null )
+ checker.checkLiteralDT(lexicalForm, datatype) ;
}
- private void checkString(String string)
- {
- if ( checker != null ) checker.checkString(string) ;
+ private void checkString(String string) {
+ if ( checker != null )
+ checker.checkString(string) ;
}
- private void checkURI(String uriStr)
- {
- if ( checker != null ) checker.checkURI(uriStr) ;
+ private void checkURI(String uriStr) {
+ if ( checker != null )
+ checker.checkURI(uriStr) ;
}
- private void checkNumber(String image, String datatype)
- {
- if ( checker != null ) checker.checkNumber(image, datatype) ;
+ private void checkNumber(String image, String datatype) {
+ if ( checker != null )
+ checker.checkNumber(image, datatype) ;
}
- private void checkVariable(String tokenImage)
- {
- if ( checker != null ) checker.checkVariable(tokenImage) ;
+ private void checkVariable(String tokenImage) {
+ if ( checker != null )
+ checker.checkVariable(tokenImage) ;
}
- private void checkDirective(int cntrlCode)
- {
- if ( checker != null ) checker.checkDirective(cntrlCode) ;
+ private void checkDirective(int cntrlCode) {
+ if ( checker != null )
+ checker.checkDirective(cntrlCode) ;
}
- private void checkKeyword(String tokenImage)
- {
- if ( checker != null ) checker.checkKeyword(tokenImage) ;
+ private void checkKeyword(String tokenImage) {
+ if ( checker != null )
+ checker.checkKeyword(tokenImage) ;
}
- private void checkPrefixedName(String tokenImage, String tokenImage2)
- {
- if ( checker != null ) checker.checkPrefixedName(tokenImage, tokenImage2) ;
+ private void checkPrefixedName(String tokenImage, String tokenImage2) {
+ if ( checker != null )
+ checker.checkPrefixedName(tokenImage, tokenImage2) ;
}
- private void checkControl(int code)
- {
- if ( checker != null ) checker.checkControl(code) ;
+ private void checkControl(int code) {
+ if ( checker != null )
+ checker.checkControl(code) ;
}
// ---- Escape sequences
-
- private final
- int readLiteralEscape()
- {
- int c = reader.readChar();
- if ( c==EOF )
+
+ private final int readLiteralEscape() {
+ int c = reader.readChar() ;
+ if ( c == EOF )
exception("Escape sequence not completed") ;
- switch (c)
- {
+ switch (c) {
case 'n': return NL ;
case 'r': return CR ;
case 't': return '\t' ;
@@ -1237,18 +1107,17 @@ public final class TokenizerText impleme
return 0 ;
}
}
-
- private final
- int readCharEscape()
- {
- // PN_LOCAL_ESC ::= '\' ( '_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%' )
- int c = reader.readChar();
- if ( c==EOF )
+ private final int readCharEscape() {
+ // PN_LOCAL_ESC ::= '\' ( '_' | '~' | '.' | '-' | '!' | '$' | '&' | "'"
+ // | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' |
+ // '%' )
+
+ int c = reader.readChar() ;
+ if ( c == EOF )
exception("Escape sequence not completed") ;
- switch (c)
- {
+ switch (c) {
case '_': case '~': case '.': case '-': case '!': case '$': case '&':
case '\'':
case '(': case ')': case '*': case '+': case ',': case ';':
@@ -1261,15 +1130,12 @@ public final class TokenizerText impleme
}
- private final
- int readUnicodeEscape()
- {
+ private final int readUnicodeEscape() {
int ch = reader.readChar() ;
if ( ch == EOF )
exception("Broken escape sequence") ;
- switch (ch)
- {
+ switch (ch) {
case '\\': return '\\' ;
case 'u': return readUnicode4Escape();
case 'U': return readUnicode8Escape();
@@ -1282,73 +1148,62 @@ public final class TokenizerText impleme
private final
int readUnicode4Escape() { return readHexSequence(4) ; }
- private final
- int readUnicode8Escape()
- {
+ private final int readUnicode8Escape() {
int ch8 = readHexSequence(8) ;
if ( ch8 > Character.MAX_CODE_POINT )
- exception("illegal code point in \\U sequence value: 0x%08X", ch8);
+ exception("illegal code point in \\U sequence value: 0x%08X", ch8) ;
return ch8 ;
}
-
- private final
- int readHexSequence(int N)
- {
+
+ private final int readHexSequence(int N) {
int x = 0 ;
- for ( int i = 0 ; i < N ; i++ )
- {
+ for (int i = 0; i < N; i++) {
int d = readHexChar() ;
if ( d < 0 )
return -1 ;
- x = (x<<4)+d ;
+ x = (x << 4) + d ;
}
- return x ;
+ return x ;
}
-
- private final
- int readHexChar()
- {
+
+ private final int readHexChar() {
int ch = reader.readChar() ;
if ( ch == EOF )
exception("Not a hexadecimal character (end of file)") ;
- int x = valHexChar(ch) ;
+ int x = valHexChar(ch) ;
if ( x != -1 )
- return x ;
- exception("Not a hexadecimal character: "+(char)ch) ;
- return -1 ;
+ return x ;
+ exception("Not a hexadecimal character: " + (char)ch) ;
+ return -1 ;
}
-
+
private boolean expect(String str) {
for (int i = 0; i < str.length(); i++) {
- char want = str.charAt(i);
- if (reader.eof())
- {
- exception("End of input during expected string: "+str) ;
+ char want = str.charAt(i) ;
+ if ( reader.eof() ) {
+ exception("End of input during expected string: " + str) ;
return false ;
}
- int inChar = reader.readChar();
- if (inChar != want) {
- //System.err.println("N-triple reader error");
- exception("expected \"" + str + "\"");
- return false;
+ int inChar = reader.readChar() ;
+ if ( inChar != want ) {
+ // System.err.println("N-triple reader error");
+ exception("expected \"" + str + "\"") ;
+ return false ;
}
}
- return true;
+ return true ;
}
- private void exception(String message, Object... args)
- {
+ private void exception(String message, Object... args) {
exception$(message, reader.getLineNum(), reader.getColNum(), args) ;
}
-
- private static void exception(PeekReader reader, String message, Object... args)
- {
+
+ private static void exception(PeekReader reader, String message, Object... args) {
exception$(message, reader.getLineNum(), reader.getColNum(), args) ;
}
- private static void exception$(String message, long line, long col, Object... args)
- {
+ private static void exception$(String message, long line, long col, Object... args) {
throw new RiotParseException(String.format(message, args), line, col) ;
}
}