/* Generated By:JavaCC: Do not edit this line. HtmlTokenParser.java */
/*
* Priki - Prevalent Wiki
* Copyright (c) 2005 Priki
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*
* @author Vitor Fernando Pamplona - vitor@babaxp.org
*
*/
package org.priki.format.compiler;
import java.io.StringReader;
import org.priki.utils.WikiwordUtils;
import org.priki.bo.*;
import java.util.*;
/**
* Generated by JavaCC
* -OUTPUT_DIRECTORY=src/org/priki/format/compiler src/org/priki/format/compiler/priki-parser.jj
*
* @author Vitor Fernando Pamplona
*/
public class HtmlTokenParser implements HtmlTokenParserConstants {
private Wiki wiki;
private boolean readonly;
public HtmlTokenParser(Wiki wiki, String textToParse) {
this(new StringReader(textToParse));
this.wiki = wiki;
this.readonly= false;
}
/*******************************************************************
* The SQL syntatic grammar starts here !
*******************************************************************/
final public void parseString(Text text) throws ParseException {
Element e;
label_1:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case A_TAG:
case CODE_TAG:
case PRE_TAG:
case HTMLTAG:
case SYMBOL:
case EMAIL:
case LINK:
case WIKIWORD:
case NUMBER:
case TIME:
case DATE:
case CODE:
;
break;
default:
jj_la1[0] = jj_gen;
break label_1;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case A_TAG:
case CODE_TAG:
case PRE_TAG:
case NUMBER:
case TIME:
case DATE:
e = notChangeTag();
text.add(e);
break;
case HTMLTAG:
e = htmlTag();
text.add(e);
break;
case EMAIL:
e = emailTag();
text.add(e);
break;
case CODE:
e = code();
text.add(e);
break;
case LINK:
e = link();
text.add(e);
break;
case SYMBOL:
e = symbol();
text.add(e);
break;
case WIKIWORD:
e = wikiword();
text.add(e);
break;
default:
jj_la1[1] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
}
final public void parseStringInReadOnlyMode(Text text) throws ParseException {
Element e;
readonly = true;
label_2:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case A_TAG:
case CODE_TAG:
case PRE_TAG:
case HTMLTAG:
case SYMBOL:
case EMAIL:
case LINK:
case WIKIWORD:
case NUMBER:
case TIME:
case DATE:
case CODE:
;
break;
default:
jj_la1[2] = jj_gen;
break label_2;
}
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case A_TAG:
case CODE_TAG:
case PRE_TAG:
case NUMBER:
case TIME:
case DATE:
e = notChangeTag();
text.add(e);
break;
case HTMLTAG:
e = htmlTag();
text.add(e);
break;
case EMAIL:
e = emailTag();
text.add(e);
break;
case CODE:
e = code();
text.add(e);
break;
case LINK:
e = link();
text.add(e);
break;
case SYMBOL:
e = symbol();
text.add(e);
break;
case WIKIWORD:
e = wikiword();
text.add(e);
break;
default:
jj_la1[3] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
}
final public void getWikiwords(List<Wikiword> list) throws ParseException {
Wikiword word;
label_3:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case WIKIWORD:
;
break;
default:
jj_la1[4] = jj_gen;
break label_3;
}
word = wikiword();
if (word != null) list.add(word);
}
}
final public void splitWikiword(List<Wikiword> list) throws ParseException {
Wikiword word;
readonly = true;
label_4:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case WIKIWORD:
;
break;
default:
jj_la1[5] = jj_gen;
break label_4;
}
word = singleWikiword();
if (word != null) list.add(word);
}
}
final public Wikiword singleWikiword() throws ParseException {
Wikiword word;
jj_consume_token(WIKIWORD);
{if (true) return readonlyWikiwordStrategy(token.image);}
throw new Error("Missing return statement in function");
}
final public Wikiword wikiword() throws ParseException {
Wikiword word;
jj_consume_token(WIKIWORD);
word = recursiveWikiwordSearcher(token.image, 1);
if (word == null) {
// Consider only the first word
word = readonlyWikiwordStrategy(token.image);
}
{if (true) return word;}
throw new Error("Missing return statement in function");
}
final public Wikiword recursiveWikiwordSearcher(String name, int index) throws ParseException {
String temp;
Wikiword word;
Collection<Wikiword> coll = wiki.wordsStartingWith(name);
if (coll.size() == 0) {
// Can't exists this wikiword.
{if (true) return null;}
}
if (coll.size() == 1) {
// Check if the wikiword is equals the key.
word = coll.iterator().next();
if (WikiwordUtils.equalsKeyword(name, word)) {
// Remove from tokens list
{if (true) return word;}
}
}
// There are many possibles to this key.
// Try with more tokens
temp = getToken(index).image;
if (temp != null) {
word = recursiveWikiwordSearcher(name + " " + temp, index+1);
// Remove from tokens list
if (word != null) {
getNextToken();
{if (true) return word;}
} else {
for (Wikiword compositeWord : coll) {
if (WikiwordUtils.equalsKeyword(name, compositeWord)) {
{if (true) return compositeWord;}
}
}
}
}
{if (true) return null;}
throw new Error("Missing return statement in function");
}
final public Wikiword readonlyWikiwordStrategy(String key) throws ParseException {
Wikiword ret = wiki.getWikiwordIgnoreCase(key);
if (ret != null) {
{if (true) return ret;}
} else {
if (readonly)
{if (true) return new Wikiword(key);}
else
{if (true) return wiki.newWikiword(key);}
}
throw new Error("Missing return statement in function");
}
final public Element readonlyElementStrategy(String key) throws ParseException {
if (wiki.hasElement(key)) {
{if (true) return wiki.getElement(key);}
} else {
if (readonly)
{if (true) return new Element(key);}
else
{if (true) return wiki.newElement(key);}
}
throw new Error("Missing return statement in function");
}
final public Element code() throws ParseException {
jj_consume_token(CODE);
{if (true) return readonlyElementStrategy(token.image);}
throw new Error("Missing return statement in function");
}
final public Element htmlTag() throws ParseException {
jj_consume_token(HTMLTAG);
{if (true) return readonlyElementStrategy(token.image);}
throw new Error("Missing return statement in function");
}
final public Element emailTag() throws ParseException {
jj_consume_token(EMAIL);
{if (true) return readonlyElementStrategy(token.image);}
throw new Error("Missing return statement in function");
}
final public Element notChangeTag() throws ParseException {
String ret;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case A_TAG:
jj_consume_token(A_TAG);
break;
case PRE_TAG:
jj_consume_token(PRE_TAG);
break;
case CODE_TAG:
jj_consume_token(CODE_TAG);
break;
case NUMBER:
jj_consume_token(NUMBER);
break;
case DATE:
jj_consume_token(DATE);
break;
case TIME:
jj_consume_token(TIME);
break;
default:
jj_la1[6] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return readonlyElementStrategy(token.image);}
throw new Error("Missing return statement in function");
}
final public Element symbol() throws ParseException {
jj_consume_token(SYMBOL);
{if (true) return readonlyElementStrategy(token.image);}
throw new Error("Missing return statement in function");
}
final public Element link() throws ParseException {
jj_consume_token(LINK);
{if (true) return readonlyElementStrategy(token.image.trim());}
throw new Error("Missing return statement in function");
}
/** Generated Token Manager. */
public HtmlTokenParserTokenManager token_source;
SimpleCharStream jj_input_stream;
/** Current token. */
public Token token;
/** Next token. */
public Token jj_nt;
private int jj_ntk;
private int jj_gen;
final private int[] jj_la1 = new int[7];
static private int[] jj_la1_0;
static {
jj_la1_init_0();
}
private static void jj_la1_init_0() {
jj_la1_0 = new int[] {0xff8e0,0xff8e0,0xff8e0,0xff8e0,0x8000,0x8000,0x700e0,};
}
/** Constructor with InputStream. */
public HtmlTokenParser(java.io.InputStream stream) {
this(stream, null);
}
/** Constructor with InputStream and supplied encoding */
public HtmlTokenParser(java.io.InputStream stream, String encoding) {
try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
token_source = new HtmlTokenParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
public void ReInit(java.io.InputStream stream) {
ReInit(stream, null);
}
/** Reinitialise. */
public void ReInit(java.io.InputStream stream, String encoding) {
try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Constructor. */
public HtmlTokenParser(java.io.Reader stream) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
token_source = new HtmlTokenParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
public void ReInit(java.io.Reader stream) {
jj_input_stream.ReInit(stream, 1, 1);
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Constructor with generated Token Manager. */
public HtmlTokenParser(HtmlTokenParserTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
public void ReInit(HtmlTokenParserTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 7; i++) jj_la1[i] = -1;
}
private Token jj_consume_token(int kind) throws ParseException {
Token oldToken;
if ((oldToken = token).next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
if (token.kind == kind) {
jj_gen++;
return token;
}
token = oldToken;
jj_kind = kind;
throw generateParseException();
}
/** Get the next Token. */
final public Token getNextToken() {
if (token.next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
jj_gen++;
return token;
}
/** Get the specific Token. */
final public Token getToken(int index) {
Token t = token;
for (int i = 0; i < index; i++) {
if (t.next != null) t = t.next;
else t = t.next = token_source.getNextToken();
}
return t;
}
private int jj_ntk() {
if ((jj_nt=token.next) == null)
return (jj_ntk = (token.next=token_source.getNextToken()).kind);
else
return (jj_ntk = jj_nt.kind);
}
private java.util.List jj_expentries = new java.util.ArrayList();
private int[] jj_expentry;
private int jj_kind = -1;
/** Generate ParseException. */
public ParseException generateParseException() {
jj_expentries.clear();
boolean[] la1tokens = new boolean[30];
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 7; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<<j)) != 0) {
la1tokens[j] = true;
}
}
}
}
for (int i = 0; i < 30; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;
jj_expentries.add(jj_expentry);
}
}
int[][] exptokseq = new int[jj_expentries.size()][];
for (int i = 0; i < jj_expentries.size(); i++) {
exptokseq[i] = (int[])jj_expentries.get(i);
}
return new ParseException(token, exptokseq, tokenImage);
}
/** Enable tracing. */
final public void enable_tracing() {
}
/** Disable tracing. */
final public void disable_tracing() {
}
}