/* Generated By:JavaCC: Do not edit this line. ShellString.java */ package org.turtleshell.strings; import java.io.*; import java.util.*; import org.turtleshell.*; /** * An object to wrap strings within the turtle shell internal string system. ** * @author Graham Alvare * @author Brian Fristensky */ public class ShellString implements TString, ShellStringConstants { /** * The string value to wrap within the turtle shell internal string system */ private String value; /** * Constructs a new turtle shell Java string wrapper ** * @param value the string value to wrap within the turtle shell internal string system */ public ShellString (String value) { this(new StringReader(value)); this.value = value; } /** * Returns the contained/wrapped Java string ** * @param env the Turtle shell environment to read any necessary variable values from. * @return the string value wrapped by this object */ public String getValue(TEnv env) { String result = ""; try { ReInit(new StringReader(value)); result = parse(env).toString(); } catch (ParseException pe) { pe.printStackTrace(System.err); } return result; } /** * Returns the unmodified contained/wrapped Java string (for debug) ** * @return the unmodified string value wrapped by this object */ public String toString() { return value; } final public StringBuilder parse(TEnv env) throws ParseException { Token t; String string; StringBuilder exec = new StringBuilder(); StringBuilder result = new StringBuilder(); label_1: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case DS: case VAR: case ESCAPE: case SQSTART: case DQSTART: case EQSTART: case CHAR: ; break; default: jj_la1[0] = jj_gen; break label_1; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case DS: case VAR: case ESCAPE: string = quoteShare(env); result.append(string); break; case CHAR: t = jj_consume_token(CHAR); result.append(t.image); break; case SQSTART: jj_consume_token(SQSTART); t = jj_consume_token(SCHAR); result.append(t.image); jj_consume_token(SQEND); break; case DQSTART: jj_consume_token(DQSTART); label_2: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case DS: case VAR: case ESCAPE: string = quoteShare(env); result.append(string); break; case DCHAR: t = jj_consume_token(DCHAR); result.append(t.image); break; default: jj_la1[1] = jj_gen; jj_consume_token(-1); throw new ParseException(); } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case DS: case VAR: case ESCAPE: case DCHAR: ; break; default: jj_la1[2] = jj_gen; break label_2; } } jj_consume_token(DQEND); break; case EQSTART: jj_consume_token(EQSTART); exec = new StringBuilder(); label_3: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case DS: case VAR: case ESCAPE: string = quoteShare(env); exec.append(string); break; case ECHAR: t = jj_consume_token(ECHAR); exec.append(t.image); break; default: jj_la1[3] = jj_gen; jj_consume_token(-1); throw new ParseException(); } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case DS: case VAR: case ESCAPE: case ECHAR: ; break; default: jj_la1[4] = jj_gen; break label_3; } } jj_consume_token(EQEND); try { result.append(new DoubleExecString(exec.toString()).getValue(env)); } catch (org.turtleshell.ParseException pe) { pe.printStackTrace(System.err); } break; default: jj_la1[5] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } jj_consume_token(0); {if (true) return result;} throw new Error("Missing return statement in function"); } final public String quoteShare(TEnv env) throws ParseException { Token t; String string; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ESCAPE: t = jj_consume_token(ESCAPE); string = t.image.substring(1); break; case VAR: t = jj_consume_token(VAR); string = env.envreplace(t.image); break; case DS: t = jj_consume_token(DS); string = "$"; break; default: jj_la1[6] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return string;} throw new Error("Missing return statement in function"); } /** Generated Token Manager. */ public ShellStringTokenManager 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[] {0xfe,0x80e,0x80e,0x200e,0x200e,0xfe,0xe,}; } /** Constructor with InputStream. */ public ShellString(java.io.InputStream stream) { this(stream, null); } /** Constructor with InputStream and supplied encoding */ public ShellString(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 ShellStringTokenManager(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 ShellString(java.io.Reader stream) { jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new ShellStringTokenManager(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 ShellString(ShellStringTokenManager 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(ShellStringTokenManager 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[14]; 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<