All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sindicetech.siren.analysis.ConciseJsonScanner Maven / Gradle / Ivy

The newest version!
/* The following code was generated by JFlex 1.4.3 on 11/17/14 12:41 PM */

/**
 * Copyright (c) 2014, Sindice Limited. All Rights Reserved.
 *
 * This file is part of the SIREn project.
 *
 * SIREn is a free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * SIREn is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this program. If not, see .
 */

package com.sindicetech.siren.analysis;

import static com.sindicetech.siren.analysis.ExtendedJsonTokenizer.*;

import java.util.Stack;
import java.util.Arrays;
import java.util.Deque;
import java.util.ArrayDeque;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.util.IntsRef;
import com.sindicetech.siren.util.ArrayUtils;
import com.sindicetech.siren.util.XSDDatatype;
import com.sindicetech.siren.util.JSONDatatype;

/**
 * A scanner for JSON document that maps a JSON tree to a concise tree model using a depth-first traversal approach.
 * 

* A concise tree model creates one token per attribute-object and attribute-value pair. A token represents the content * of a node. The attribute-object token has an empty content. To be able to distinguish between multiple objects, it * duplicates the attribute-object token for each attribute-object pair and increments its node identifiers. * Nested arrays are not flattened and will be mapped to an empty node. */ public final class ConciseJsonScanner { /** This character denotes the end of file */ public static final int YYEOF = -1; /** initial size of the lookahead buffer */ private static final int ZZ_BUFFERSIZE = 16384; /** lexical states */ public static final int sDATATYPE = 12; public static final int sOBJECT = 2; public static final int sARRAY = 10; public static final int YYINITIAL = 0; public static final int sSTRING = 8; public static final int sFIELD = 4; public static final int sVALUE = 6; public static final int sDATATYPE_LABEL = 16; public static final int sDATATYPE_FIELD = 14; public static final int sDATATYPE_VALUE = 18; /** * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l * at the beginning of a line * l is of the form l = 2*k, k a non negative integer */ private static final int ZZ_LEXSTATE[] = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9 }; /** * Translates characters to character classes */ private static final String ZZ_CMAP_PACKED = "\11\0\1\22\1\21\1\0\1\22\1\20\22\0\1\22\1\0\1\31"+ "\10\0\1\15\1\33\1\11\1\13\1\0\12\12\1\34\6\0\4\36"+ "\1\14\1\36\24\0\1\37\1\35\1\40\1\0\1\23\1\0\1\6"+ "\2\36\1\24\1\4\1\5\5\0\1\7\1\0\1\17\1\0\1\26"+ "\1\0\1\2\1\10\1\1\1\3\1\27\2\0\1\25\1\0\1\30"+ "\1\16\1\32\uff82\0"; /** * Translates characters to character classes */ private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); /** * Translates DFA states to action switch labels. */ private static final int [] ZZ_ACTION = zzUnpackAction(); private static final String ZZ_ACTION_PACKED_0 = "\12\0\1\1\2\2\1\3\1\4\1\5\1\6\1\7"+ "\1\10\1\11\2\12\3\0\1\13\1\0\1\14\1\15"+ "\1\16\1\17\1\20\1\21\1\22\1\23\1\24\1\25"+ "\1\26\1\27\1\30\1\31\1\26\1\32\1\33\1\34"+ "\1\35\1\36\2\0\1\37\2\11\1\40\7\0\2\20"+ "\1\41\1\0\2\32\1\42\6\0\1\13\1\43\11\0"+ "\1\44\2\0\1\45\11\0\1\46\1\0\1\43\10\0"+ "\1\47\2\0\1\50\2\0\1\51\7\0\1\52\10\0"+ "\1\53\3\0\1\54\2\0\1\55"; private static int [] zzUnpackAction() { int [] result = new int[139]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; } private static int zzUnpackAction(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** * Translates a state to a row index in the transition table */ private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\41\0\102\0\143\0\204\0\245\0\306\0\347"+ "\0\u0108\0\u0129\0\u014a\0\u016b\0\u014a\0\u014a\0\u014a\0\u014a"+ "\0\u018c\0\u014a\0\u014a\0\u01ad\0\u01ce\0\u01ef\0\u0210\0\u0231"+ "\0\u0252\0\u0273\0\u0294\0\u02b5\0\u014a\0\u014a\0\u014a\0\u02d6"+ "\0\u014a\0\u02f7\0\u014a\0\u014a\0\u014a\0\u014a\0\u014a\0\u014a"+ "\0\u014a\0\u0318\0\u0339\0\u014a\0\u035a\0\u014a\0\u02f7\0\u037b"+ "\0\u01ce\0\u014a\0\u014a\0\u039c\0\u014a\0\u03bd\0\u03de\0\u03ff"+ "\0\u0420\0\u0441\0\u02b5\0\u0462\0\u014a\0\u0483\0\u014a\0\u04a4"+ "\0\u014a\0\u04c5\0\u014a\0\u04e6\0\u0507\0\u0528\0\u0549\0\u056a"+ "\0\u058b\0\u058b\0\u05ac\0\u05cd\0\u05ee\0\u060f\0\u0630\0\u0651"+ "\0\u0672\0\u0693\0\u06b4\0\u06d5\0\u014a\0\u06f6\0\u0717\0\u014a"+ "\0\u0738\0\u0759\0\u077a\0\u079b\0\u07bc\0\u07dd\0\u07fe\0\u081f"+ "\0\u0840\0\u014a\0\u0861\0\u0861\0\u0882\0\u08a3\0\u08c4\0\u08e5"+ "\0\u0906\0\u0927\0\u0948\0\u0969\0\u014a\0\u098a\0\u09ab\0\u014a"+ "\0\u09cc\0\u09ed\0\u014a\0\u0a0e\0\u0a2f\0\u0a50\0\u0a71\0\u0a92"+ "\0\u0ab3\0\u0ad4\0\u014a\0\u0af5\0\u0b16\0\u0b37\0\u0b58\0\u0b79"+ "\0\u0b9a\0\u0bbb\0\u0bdc\0\u014a\0\u0bfd\0\u0c1e\0\u0c3f\0\u014a"+ "\0\u0c60\0\u0c81\0\u014a"; private static int [] zzUnpackRowMap() { int [] result = new int[139]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; } private static int zzUnpackRowMap(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int high = packed.charAt(i++) << 16; result[j++] = high | packed.charAt(i++); } return j; } /** * The transition table of the DFA */ private static final int [] ZZ_TRANS = zzUnpackTrans(); private static final String ZZ_TRANS_PACKED_0 = "\20\13\1\14\2\15\5\13\1\16\10\13\20\17\1\14"+ "\2\15\5\17\1\20\1\21\1\22\1\23\5\17\31\24"+ "\1\25\3\24\1\26\3\24\1\0\1\27\3\0\1\30"+ "\3\0\1\31\1\32\4\0\1\33\1\14\2\15\5\0"+ "\1\34\1\35\5\0\1\36\1\37\31\40\1\41\3\40"+ "\1\42\3\40\20\43\1\14\2\15\10\43\1\44\3\43"+ "\1\45\1\37\20\46\1\14\2\15\5\46\1\47\1\46"+ "\1\50\1\51\25\46\1\14\2\15\6\46\1\52\7\46"+ "\31\53\1\54\3\53\1\55\3\53\31\40\1\56\3\40"+ "\1\57\3\40\62\0\1\15\42\0\1\60\15\0\31\24"+ "\1\0\3\24\1\0\3\24\20\0\3\61\11\0\1\62"+ "\4\0\3\63\1\64\15\63\1\0\7\63\1\65\7\63"+ "\2\0\1\66\44\0\1\67\44\0\1\32\32\0\1\70"+ "\5\0\1\32\1\71\1\70\1\0\1\70\25\0\1\72"+ "\55\0\3\73\6\0\1\74\7\0\31\40\1\0\3\40"+ "\1\0\3\40\3\75\1\76\15\75\1\0\7\75\1\77"+ "\7\75\23\0\1\100\15\0\31\53\1\0\3\53\1\0"+ "\3\53\3\101\1\102\15\101\1\0\7\101\1\103\7\101"+ "\24\0\1\104\2\0\1\105\15\0\3\106\3\0\1\106"+ "\1\0\1\106\7\0\1\106\11\0\1\106\5\0\1\107"+ "\44\0\1\110\42\0\1\111\1\112\2\0\2\111\34\0"+ "\1\113\35\0\1\114\54\0\1\115\21\0\3\116\3\0"+ "\1\116\1\0\1\116\7\0\1\116\11\0\1\116\26\0"+ "\1\117\2\0\1\120\15\0\3\121\3\0\1\121\1\0"+ "\1\121\7\0\1\121\11\0\1\121\10\0\1\122\40\0"+ "\1\123\36\0\3\124\3\0\1\124\1\0\1\124\7\0"+ "\1\124\11\0\1\124\6\0\1\125\44\0\1\126\42\0"+ "\1\112\32\0\1\127\5\0\1\113\1\0\1\127\1\0"+ "\1\127\31\0\1\130\55\0\1\131\2\0\1\132\15\0"+ "\3\133\3\0\1\133\1\0\1\133\7\0\1\133\11\0"+ "\1\133\10\0\1\134\40\0\1\135\36\0\3\136\3\0"+ "\1\136\1\0\1\136\7\0\1\136\11\0\1\136\3\0"+ "\1\137\46\0\1\140\35\0\3\141\3\0\1\141\1\0"+ "\1\141\7\0\1\141\11\0\1\141\6\0\1\142\45\0"+ "\1\143\1\144\2\0\2\143\30\0\1\145\40\0\1\146"+ "\36\0\3\147\3\0\1\147\1\0\1\147\7\0\1\147"+ "\11\0\1\147\3\0\1\150\46\0\1\151\35\0\3\152"+ "\3\0\1\152\1\0\1\152\7\0\1\152\11\0\1\152"+ "\10\0\1\153\35\0\1\154\41\0\3\155\3\0\1\155"+ "\1\0\1\155\7\0\1\155\11\0\1\155\14\0\1\144"+ "\27\0\1\156\46\0\1\157\35\0\3\160\3\0\1\160"+ "\1\0\1\160\7\0\1\160\11\0\1\160\10\0\1\161"+ "\35\0\1\162\41\0\3\163\3\0\1\163\1\0\1\163"+ "\7\0\1\163\11\0\1\163\3\0\1\164\43\0\1\165"+ "\42\0\1\166\35\0\1\167\36\0\1\170\43\0\1\171"+ "\61\0\1\172\36\0\1\173\16\0\1\174\43\0\1\175"+ "\61\0\1\176\36\0\1\177\43\0\1\154\37\0\1\200"+ "\36\0\1\201\43\0\1\202\43\0\1\203\35\0\1\167"+ "\43\0\1\204\13\0\1\205\54\0\3\203\11\0\1\206"+ "\27\0\1\207\35\0\3\206\6\0\1\210\40\0\1\211"+ "\27\0\3\211\11\0\1\212\24\0\3\212\6\0\1\213"+ "\7\0"; private static int [] zzUnpackTrans() { int [] result = new int[3234]; int offset = 0; offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); return result; } private static int zzUnpackTrans(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); value--; do result[j++] = value; while (--count > 0); } return j; } /* error codes */ private static final int ZZ_UNKNOWN_ERROR = 0; private static final int ZZ_NO_MATCH = 1; private static final int ZZ_PUSHBACK_2BIG = 2; /* error messages for the codes above */ private static final String ZZ_ERROR_MSG[] = { "Unkown internal scanner error", "Error: could not match input", "Error: pushback value was too large" }; /** * ZZ_ATTRIBUTE[aState] contains the attributes of state aState */ private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); private static final String ZZ_ATTRIBUTE_PACKED_0 = "\12\0\1\11\1\1\4\11\1\1\2\11\3\1\3\0"+ "\1\1\1\0\1\1\3\11\1\1\1\11\1\1\7\11"+ "\2\1\1\11\1\1\1\11\1\1\2\0\2\11\1\1"+ "\1\11\7\0\1\11\1\1\1\11\1\0\1\11\1\1"+ "\1\11\6\0\2\1\11\0\1\11\2\0\1\11\11\0"+ "\1\11\1\0\1\1\10\0\1\11\2\0\1\11\2\0"+ "\1\11\7\0\1\11\10\0\1\11\3\0\1\11\2\0"+ "\1\11"; private static int [] zzUnpackAttribute() { int [] result = new int[139]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; } private static int zzUnpackAttribute(String packed, int offset, int [] result) { int i = 0; /* index in packed string */ int j = offset; /* index in unpacked array */ int l = packed.length(); while (i < l) { int count = packed.charAt(i++); int value = packed.charAt(i++); do result[j++] = value; while (--count > 0); } return j; } /** the input device */ private java.io.Reader zzReader; /** the current state of the DFA */ private int zzState; /** the current lexical state */ private int zzLexicalState = YYINITIAL; /** this buffer contains the current text to be matched and is the source of the yytext() string */ private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; /** the textposition at the last accepting state */ private int zzMarkedPos; /** the current text position in the buffer */ private int zzCurrentPos; /** startRead marks the beginning of the yytext() string in the buffer */ private int zzStartRead; /** endRead marks the last character in the buffer, that has been read from input */ private int zzEndRead; /** number of newlines encountered up to the start of the matched text */ private int yyline; /** the number of characters up to the start of the matched text */ private int yychar; /** * the number of characters from the last newline up to the start of the * matched text */ private int yycolumn; /** * zzAtBOL == true <=> the scanner is currently at the beginning of a line */ private boolean zzAtBOL = true; /** zzAtEOF == true <=> the scanner is at the EOF */ private boolean zzAtEOF; /** denotes if the user-EOF-code has already been executed */ private boolean zzEOFDone; /* user code: */ /** * Buffer containing literal or number value */ private final StringBuilder buffer = new StringBuilder(); // OBJECT /** * Flag to indicate if the current object is empty, i.e., if it does not contain at least one field */ private boolean isObjectEmpty = true; // NODE IDENTIFIERS /** * The size of the path buffer */ private final static int BUFFER_SIZE = 1024; /** * The path to a node */ private final IntsRef nodePath = new IntsRef(BUFFER_SIZE); /** * Stack of lexical states. *

* It is used to (1) verify that objects and arrays are correctly closed, and (2) to be able to resume the previous * state during the traversal of the tree. */ private final Deque states = new ArrayDeque(); // DATATYPES /** * Datatype representing xsd:string */ private static final char[] XSD_STRING = XSDDatatype.XSD_STRING.toCharArray(); /** * Datatype representing json:field */ private static final char[] JSON_FIELD = JSONDatatype.JSON_FIELD.toCharArray(); /** * Datatype representing xsd:double */ private static final char[] XSD_DOUBLE = XSDDatatype.XSD_DOUBLE.toCharArray(); /** * Datatype representing xsd:long */ private static final char[] XSD_LONG = XSDDatatype.XSD_LONG.toCharArray(); /** * Datatype representing xsd:boolean */ private static final char[] XSD_BOOLEAN = XSDDatatype.XSD_BOOLEAN.toCharArray(); /** * Buffer used to build the datatype label */ private final StringBuilder dtLabel = new StringBuilder(); /** * A reference to the current datatype URI */ private char[] datatype; /** * Flags to indicate if the datatype object has a datatype label and value. */ private boolean hasLabel, hasValue; // FIELDS /** * Buffer used to build the field label */ private final StringBuilder fieldLabel = new StringBuilder(); /** * Queue of field labels */ private final Deque paths = new ArrayDeque(); // ARRAY private boolean mustFlattenNestedArray = false; /** * If set to true, the nested arrays will be flattened. */ public void setMustFlattenNestedArray(boolean mustFlattenNestedArray) { this.mustFlattenNestedArray = mustFlattenNestedArray; } /** * Return a copy of the current path. */ public final String[] getPath() { return paths.toArray(new String[paths.size()]); } /** * Return the datatype URI. */ public final char[] getDatatypeURI() { return datatype; } public final int yychar() { return yychar; } /** * Fills Lucene TermAttribute with the current string buffer. */ public final void getLiteralText(CharTermAttribute t) { char[] chars = new char[buffer.length()]; buffer.getChars(0, buffer.length(), chars, 0); t.copyBuffer(chars, 0, chars.length); } /** * Returns the node path of the token */ public final IntsRef getNodePath() { return nodePath; } /** * Initialise inner variables */ private void reset() { states.clear(); Arrays.fill(nodePath.ints, -1); nodePath.offset = 0; nodePath.length = 0; datatype = null; } /** * Helper method to print an error while scanning a JSON * document with line and column information. */ private String errorMessage(String msg) { return "Error parsing JSON document at [line=" + yyline + ", column=" + yycolumn + "]: " + msg; } /** * Called when entering into a new object. Adds a {@link #sOBJECT} state to the stack. Set the flag for empty object * to true. */ private void newObject() { states.push(sOBJECT); this.incrNodeObjectPath(); this.isObjectEmpty = true; } /** * Add an object to the current node path */ private void incrNodeObjectPath() { ArrayUtils.growAndCopy(nodePath, nodePath.length + 1); nodePath.length++; // Initialise node setLastNode(-1); } /** * Update the path of the current values of the current object node */ private void setLastNode(int val) { nodePath.ints[nodePath.length - 1] = val; } /** * Called when leaving an object: *

    *
  • decrement the tree level of 1; and *
  • remove {@link #sOBJECT} from the stack of states. *
*/ private void closeObject() { final int state = states.pop(); if (state != sOBJECT) { throw new IllegalStateException(errorMessage("Object is not properly closed")); } decrNodeObjectPath(); } /** * Decrement the tree level of 1. */ private void decrNodeObjectPath() { nodePath.length--; } /** * Called for each new number value. Return the {@link #NUMBER} token type. */ private int newNumber(char[] datatype) { this.datatype = datatype; buffer.setLength(0); buffer.append(yytext()); return NUMBER; } /** * Called for each new boolean value. Return the {@link #NUMBER} token type. */ private int newBoolean(boolean b) { this.datatype = XSD_BOOLEAN; return b ? TRUE : FALSE; } /** * Update the path of the current values of the current object node */ private void addToLastNode(int val) { nodePath.ints[nodePath.length - 1] += val; } /** * Creates a new scanner * There is also a java.io.InputStream version of this constructor. * * @param in the java.io.Reader to read input from. */ public ConciseJsonScanner(java.io.Reader in) { this.zzReader = in; } /** * Creates a new scanner. * There is also java.io.Reader version of this constructor. * * @param in the java.io.Inputstream to read input from. */ public ConciseJsonScanner(java.io.InputStream in) { this(new java.io.InputStreamReader(in)); } /** * Unpacks the compressed character translation table. * * @param packed the packed character translation table * @return the unpacked character translation table */ private static char [] zzUnpackCMap(String packed) { char [] map = new char[0x10000]; int i = 0; /* index in packed string */ int j = 0; /* index in unpacked array */ while (i < 106) { int count = packed.charAt(i++); char value = packed.charAt(i++); do map[j++] = value; while (--count > 0); } return map; } /** * Refills the input buffer. * * @return false, iff there was new input. * * @exception java.io.IOException if any I/O-Error occurs */ private boolean zzRefill() throws java.io.IOException { /* first: make room (if you can) */ if (zzStartRead > 0) { System.arraycopy(zzBuffer, zzStartRead, zzBuffer, 0, zzEndRead-zzStartRead); /* translate stored positions */ zzEndRead-= zzStartRead; zzCurrentPos-= zzStartRead; zzMarkedPos-= zzStartRead; zzStartRead = 0; } /* is the buffer big enough? */ if (zzCurrentPos >= zzBuffer.length) { /* if not: blow it up */ char newBuffer[] = new char[zzCurrentPos*2]; System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); zzBuffer = newBuffer; } /* finally: fill the buffer with new input */ int numRead = zzReader.read(zzBuffer, zzEndRead, zzBuffer.length-zzEndRead); if (numRead > 0) { zzEndRead+= numRead; return false; } // unlikely but not impossible: read 0 characters, but not at end of stream if (numRead == 0) { int c = zzReader.read(); if (c == -1) { return true; } else { zzBuffer[zzEndRead++] = (char) c; return false; } } // numRead < 0 return true; } /** * Closes the input stream. */ public final void yyclose() throws java.io.IOException { zzAtEOF = true; /* indicate end of file */ zzEndRead = zzStartRead; /* invalidate buffer */ if (zzReader != null) zzReader.close(); } /** * Resets the scanner to read from a new input stream. * Does not close the old reader. * * All internal variables are reset, the old input stream * cannot be reused (internal buffer is discarded and lost). * Lexical state is set to ZZ_INITIAL. * * @param reader the new input stream */ public final void yyreset(java.io.Reader reader) { zzReader = reader; zzAtBOL = true; zzAtEOF = false; zzEOFDone = false; zzEndRead = zzStartRead = 0; zzCurrentPos = zzMarkedPos = 0; yyline = yychar = yycolumn = 0; zzLexicalState = YYINITIAL; } /** * Returns the current lexical state. */ public final int yystate() { return zzLexicalState; } /** * Enters a new lexical state * * @param newState the new lexical state */ public final void yybegin(int newState) { zzLexicalState = newState; } /** * Returns the text matched by the current regular expression. */ public final String yytext() { return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead ); } /** * Returns the character at position pos from the * matched text. * * It is equivalent to yytext().charAt(pos), but faster * * @param pos the position of the character to fetch. * A value from 0 to yylength()-1. * * @return the character at position pos */ public final char yycharat(int pos) { return zzBuffer[zzStartRead+pos]; } /** * Returns the length of the matched text region. */ public final int yylength() { return zzMarkedPos-zzStartRead; } /** * Reports an error that occured while scanning. * * In a wellformed scanner (no or only correct usage of * yypushback(int) and a match-all fallback rule) this method * will only be called with things that "Can't Possibly Happen". * If this method is called, something is seriously wrong * (e.g. a JFlex bug producing a faulty scanner etc.). * * Usual syntax/scanner level error handling should be done * in error fallback rules. * * @param errorCode the code of the errormessage to display */ private void zzScanError(int errorCode) { String message; try { message = ZZ_ERROR_MSG[errorCode]; } catch (ArrayIndexOutOfBoundsException e) { message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; } throw new Error(message); } /** * Pushes the specified amount of characters back into the input stream. * * They will be read again by then next call of the scanning method * * @param number the number of characters to be read again. * This number must not be greater than yylength()! */ public void yypushback(int number) { if ( number > yylength() ) zzScanError(ZZ_PUSHBACK_2BIG); zzMarkedPos -= number; } /** * Resumes scanning until the next regular expression is matched, * the end of input is encountered or an I/O-Error occurs. * * @return the next token * @exception java.io.IOException if any I/O-Error occurs */ public int getNextToken() throws java.io.IOException, java.lang.IllegalStateException { int zzInput; int zzAction; // cached fields: int zzCurrentPosL; int zzMarkedPosL; int zzEndReadL = zzEndRead; char [] zzBufferL = zzBuffer; char [] zzCMapL = ZZ_CMAP; int [] zzTransL = ZZ_TRANS; int [] zzRowMapL = ZZ_ROWMAP; int [] zzAttrL = ZZ_ATTRIBUTE; while (true) { zzMarkedPosL = zzMarkedPos; yychar+= zzMarkedPosL-zzStartRead; zzAction = -1; zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; zzState = ZZ_LEXSTATE[zzLexicalState]; zzForAction: { while (true) { if (zzCurrentPosL < zzEndReadL) zzInput = zzBufferL[zzCurrentPosL++]; else if (zzAtEOF) { zzInput = YYEOF; break zzForAction; } else { // store back cached positions zzCurrentPos = zzCurrentPosL; zzMarkedPos = zzMarkedPosL; boolean eof = zzRefill(); // get translated positions and possibly new buffer zzCurrentPosL = zzCurrentPos; zzMarkedPosL = zzMarkedPos; zzBufferL = zzBuffer; zzEndReadL = zzEndRead; if (eof) { zzInput = YYEOF; break zzForAction; } else { zzInput = zzBufferL[zzCurrentPosL++]; } } int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; if (zzNext == -1) break zzForAction; zzState = zzNext; int zzAttributes = zzAttrL[zzState]; if ( (zzAttributes & 1) == 1 ) { zzAction = zzState; zzMarkedPosL = zzCurrentPosL; if ( (zzAttributes & 8) == 8 ) break zzForAction; } } } // store back cached position zzMarkedPos = zzMarkedPosL; switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { case 40: { buffer.append(Character.toChars(Integer.parseInt(new String(zzBufferL, zzStartRead+2, zzMarkedPos - zzStartRead - 2 ), 16))); } case 46: break; case 7: { if (!isObjectEmpty) { paths.removeLast(); } this.closeObject(); // while stack of states is non empty, unroll states if (!states.isEmpty()) { yybegin(states.peek()); } } case 47: break; case 8: { if (!isObjectEmpty) { paths.removeLast(); } } case 48: break; case 11: { addToLastNode(1); yybegin(states.peek()); return newNumber(XSD_LONG); } case 49: break; case 4: { throw new IllegalStateException(errorMessage("Found invalid character while scanning an object: [" + yytext() + "]")); } case 50: break; case 26: { dtLabel.append(yytext()); } case 51: break; case 27: { datatype = new char[dtLabel.length()]; dtLabel.getChars(0, dtLabel.length(), datatype, 0); yybegin(sDATATYPE); } case 52: break; case 3: { reset(); yypushback(1); yybegin(sOBJECT); } case 53: break; case 44: { hasValue = true; buffer.setLength(0); yybegin(sDATATYPE_VALUE); } case 54: break; case 36: { addToLastNode(1); yybegin(states.peek()); return newBoolean(true); } case 55: break; case 24: { if (!hasLabel) { throw new IllegalStateException(errorMessage("Invalid datatype object: no _datatype_ attribute.")); } if (!hasValue) { throw new IllegalStateException(errorMessage("Invalid datatype object: no _value_ attribute.")); } int state = states.pop(); if (state != sDATATYPE) { throw new IllegalStateException(errorMessage("Datatype object is not properly closed")); } yybegin(states.peek()); return LITERAL; } case 56: break; case 2: { /* ignore white space. */ } case 57: break; case 21: { // if the previous state is an array, this is a nested array, // we need to increase the node identifier if (!mustFlattenNestedArray && states.peek() == sARRAY) { addToLastNode(1); this.incrNodeObjectPath(); } states.push(sARRAY); yybegin(sVALUE); } case 58: break; case 13: { datatype = XSD_STRING; addToLastNode(1); buffer.setLength(0); yybegin(sSTRING); } case 59: break; case 19: { throw new IllegalStateException(errorMessage("Found invalid character while scanning an array: [" + yytext() + "]")); } case 60: break; case 12: { addToLastNode(1); yypushback(1); yybegin(sOBJECT); // return an empty token for the field datatype = XSD_STRING; buffer.setLength(0); return LITERAL; } case 61: break; case 30: { throw new IllegalStateException(errorMessage("Found invalid character while scanning a datatype string: [" + yytext() + "]")); } case 62: break; case 25: { yybegin(sDATATYPE_FIELD); } case 63: break; case 43: // lookahead expression with fixed base length zzMarkedPos = zzStartRead + 1; { addToLastNode(1); yypushback(1); yybegin(sDATATYPE); } case 64: break; case 33: { buffer.append('\"'); } case 65: break; case 5: { this.newObject(); } case 66: break; case 10: { throw new IllegalStateException(errorMessage("Found invalid character while scanning a field: [" + yytext() + "]")); } case 67: break; case 22: { throw new IllegalStateException(errorMessage("Found invalid character while scanning a datatype: [" + yytext() + "]")); } case 68: break; case 31: { paths.addLast(fieldLabel.toString()); yybegin(sVALUE); } case 69: break; case 39: { fieldLabel.append(Character.toChars(Integer.parseInt(new String(zzBufferL, zzStartRead+2, zzMarkedPos - zzStartRead - 2 ), 16))); } case 70: break; case 23: { hasLabel = hasValue = false; states.push(sDATATYPE); yybegin(sDATATYPE_FIELD); } case 71: break; case 9: { fieldLabel.append(yytext()); } case 72: break; case 16: { buffer.append(yytext()); } case 73: break; case 17: { yybegin(states.peek()); return LITERAL; } case 74: break; case 18: { throw new IllegalStateException(errorMessage("Found invalid character while scanning a string: [" + yytext() + "]")); } case 75: break; case 20: { yybegin(sVALUE); } case 76: break; case 1: { throw new IllegalStateException(errorMessage("Found invalid character while scanning start of the json input: [" + yytext() + "]")); } case 77: break; case 14: { yypushback(1); yybegin(sARRAY); } case 78: break; case 35: { addToLastNode(1); yybegin(states.peek()); return newNumber(XSD_DOUBLE); } case 79: break; case 42: { // Throws exception if object uses restricted field names throw new IllegalStateException(errorMessage("Restricted field name found while scanning an object: [" + yytext() + "]")); } case 80: break; case 37: { datatype = XSD_STRING; addToLastNode(1); yybegin(states.peek()); return NULL; } case 81: break; case 34: { dtLabel.append('\"'); } case 82: break; case 6: { this.isObjectEmpty = false; fieldLabel.setLength(0); yybegin(sFIELD); } case 83: break; case 45: { hasLabel = true; dtLabel.setLength(0); yybegin(sDATATYPE_LABEL); } case 84: break; case 28: { throw new IllegalStateException(errorMessage("Found invalid character while scanning a datatype label: [" + yytext() + "]")); } case 85: break; case 38: { addToLastNode(1); yybegin(states.peek()); return newBoolean(false); } case 86: break; case 32: { fieldLabel.append('\"'); } case 87: break; case 29: { yybegin(sDATATYPE); } case 88: break; case 15: { int state = states.pop(); if (state != sARRAY) { throw new IllegalStateException(errorMessage("Array is not properly closed")); } state = states.peek(); if (!mustFlattenNestedArray && state == sARRAY) { // we were in a nested array, decrease the node identifier this.decrNodeObjectPath(); } yybegin(state); } case 89: break; case 41: { dtLabel.append(Character.toChars(Integer.parseInt(new String(zzBufferL, zzStartRead+2, zzMarkedPos - zzStartRead - 2 ), 16))); } case 90: break; default: if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { zzAtEOF = true; { if (!states.isEmpty()) { throw new IllegalStateException(errorMessage("Arrays/objects/strings are not properly closed")); } return YYEOF; } } else { zzScanError(ZZ_NO_MATCH); } } } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy