diff options
author | dkolovos | 2015-07-19 15:05:33 +0000 |
---|---|---|
committer | dkolovos | 2015-07-19 15:05:33 +0000 |
commit | 41b5ad9899dfe6420503eb99ed5f8731f1a7fde4 (patch) | |
tree | 2ed79e3cda4bc126f44b63ba1319f4d47bb23aff | |
parent | 0467950974ff544bda117570cb3ae04116a329c8 (diff) | |
download | org.eclipse.emfatic-41b5ad9899dfe6420503eb99ed5f8731f1a7fde4.tar.gz org.eclipse.emfatic-41b5ad9899dfe6420503eb99ed5f8731f1a7fde4.tar.xz org.eclipse.emfatic-41b5ad9899dfe6420503eb99ed5f8731f1a7fde4.zip |
Added support for Unicode characters
7 files changed, 644 insertions, 474 deletions
diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/Emfatic2.jj b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/Emfatic2.jj index 10742ff..4a424f5 100644 --- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/Emfatic2.jj +++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/Emfatic2.jj @@ -6,7 +6,8 @@ options { JDK_VERSION = "1.5"; STATIC = false ; LOOKAHEAD=4; - FORCE_LA_CHECK = true; + FORCE_LA_CHECK = true; + UNICODE_INPUT = true; } PARSER_BEGIN(EmfaticParser) @@ -112,7 +113,22 @@ TOKEN : | < STRING_LITERAL : <DOUBLEQUOTE> (<ESC> | ~["\""])* <DOUBLEQUOTE> > | < CHAR_LITERAL : <SINGLEQUOTE> (<ESC> | (~["'"])) <SINGLEQUOTE> > -| < #LETTERORUNDERSCORE : ["a"-"z", "A"-"Z", "_"] > +//| < #LETTERORUNDERSCORE : ["a"-"z", "A"-"Z", "_"] > +| < #LETTERORUNDERSCORE : [ + "\u0041"-"\u005a" , + "\u005f" , + "\u0061"-"\u007a" , + "\u00c0"-"\u00d6" , + "\u00d8"-"\u00f6" , + "\u00f8"-"\u00ff" , + "\u0100"-"\u1fff" , + "\u3040"-"\u318f" , + "\u3300"-"\u337f" , + "\u3400"-"\u3d2d" , + "\u4e00"-"\u9fff" , + "\uf900"-"\ufaff" +] > + | < #LETTERORUNDERSCOREORDIGIT : ( <LETTERORUNDERSCORE> | <DIGIT> ) > | < INT_LITERAL : (<DIGIT>)+ > diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParser.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParser.java index 2cc72e0..0d05ef6 100644 --- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParser.java +++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParser.java @@ -1610,96 +1610,6 @@ public class EmfaticParser implements EmfaticParserConstants { finally { jj_save(75, xla); } } - private boolean jj_3_67() { - if (jj_scan_token(MINUS)) return true; - return false; - } - - private boolean jj_3R_47() { - Token xsp; - xsp = jj_scanpos; - if (jj_3_67()) jj_scanpos = xsp; - if (jj_scan_token(INT_LITERAL)) return true; - return false; - } - - private boolean jj_3_27() { - if (jj_scan_token(AMP)) return true; - if (jj_3R_30()) return true; - return false; - } - - private boolean jj_3R_15() { - if (jj_scan_token(STRING_LITERAL)) return true; - return false; - } - - private boolean jj_3_19() { - if (jj_3R_28()) return true; - return false; - } - - private boolean jj_3R_64() { - if (jj_3R_30()) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3_27()) { jj_scanpos = xsp; break; } - } - return false; - } - - private boolean jj_3_66() { - if (jj_scan_token(FALSEKW)) return true; - return false; - } - - private boolean jj_3R_69() { - Token xsp; - xsp = jj_scanpos; - if (jj_3_65()) { - jj_scanpos = xsp; - if (jj_3_66()) return true; - } - return false; - } - - private boolean jj_3_5() { - if (jj_3R_16()) return true; - return false; - } - - private boolean jj_3_26() { - if (jj_3R_32()) return true; - return false; - } - - private boolean jj_3_47() { - if (jj_scan_token(HASH)) return true; - if (jj_scan_token(ID)) return true; - return false; - } - - private boolean jj_3_65() { - if (jj_scan_token(TRUEKW)) return true; - return false; - } - - private boolean jj_3_4() { - if (jj_3R_15()) return true; - return false; - } - - private boolean jj_3R_57() { - Token xsp; - xsp = jj_scanpos; - if (jj_3_4()) { - jj_scanpos = xsp; - if (jj_3_5()) return true; - } - return false; - } - private boolean jj_3R_46() { if (jj_3R_69()) return true; return false; @@ -2557,6 +2467,96 @@ public class EmfaticParser implements EmfaticParserConstants { return false; } + private boolean jj_3_67() { + if (jj_scan_token(MINUS)) return true; + return false; + } + + private boolean jj_3R_47() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_67()) jj_scanpos = xsp; + if (jj_scan_token(INT_LITERAL)) return true; + return false; + } + + private boolean jj_3_27() { + if (jj_scan_token(AMP)) return true; + if (jj_3R_30()) return true; + return false; + } + + private boolean jj_3R_15() { + if (jj_scan_token(STRING_LITERAL)) return true; + return false; + } + + private boolean jj_3_19() { + if (jj_3R_28()) return true; + return false; + } + + private boolean jj_3R_64() { + if (jj_3R_30()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_27()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3_66() { + if (jj_scan_token(FALSEKW)) return true; + return false; + } + + private boolean jj_3R_69() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_65()) { + jj_scanpos = xsp; + if (jj_3_66()) return true; + } + return false; + } + + private boolean jj_3_5() { + if (jj_3R_16()) return true; + return false; + } + + private boolean jj_3_26() { + if (jj_3R_32()) return true; + return false; + } + + private boolean jj_3_47() { + if (jj_scan_token(HASH)) return true; + if (jj_scan_token(ID)) return true; + return false; + } + + private boolean jj_3_65() { + if (jj_scan_token(TRUEKW)) return true; + return false; + } + + private boolean jj_3_4() { + if (jj_3R_15()) return true; + return false; + } + + private boolean jj_3R_57() { + Token xsp; + xsp = jj_scanpos; + if (jj_3_4()) { + jj_scanpos = xsp; + if (jj_3_5()) return true; + } + return false; + } + /** Generated Token Manager. */ public EmfaticParserTokenManager token_source; SimpleCharStream jj_input_stream; diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserTokenManager.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserTokenManager.java index ba82363..14ddae2 100644 --- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserTokenManager.java +++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/EmfaticParserTokenManager.java @@ -581,8 +581,29 @@ private int jjStartNfaWithStates_0(int pos, int kind, int state) return jjMoveNfa_0(state, pos + 1); } static final long[] jjbitVec0 = { + 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +static final long[] jjbitVec2 = { 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL }; +static final long[] jjbitVec3 = { + 0x1ff00000fffffffeL, 0xffffffffffffc000L, 0xffffffffL, 0x600000000000000L +}; +static final long[] jjbitVec4 = { + 0x0L, 0x0L, 0x0L, 0xff7fffffff7fffffL +}; +static final long[] jjbitVec5 = { + 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +static final long[] jjbitVec6 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffL, 0x0L +}; +static final long[] jjbitVec7 = { + 0xffffffffffffffffL, 0xffffffffffffffffL, 0x0L, 0x0L +}; +static final long[] jjbitVec8 = { + 0x3fffffffffffL, 0x0L, 0x0L, 0x0L +}; private int jjMoveNfa_0(int startState, int curPos) { int startsAt = 0; @@ -779,22 +800,34 @@ private int jjMoveNfa_0(int startState, int curPos) } else { + int hiByte = (int)(curChar >> 8); + int i1 = hiByte >> 6; + long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; long l2 = 1L << (curChar & 077); do { switch(jjstateSet[--i]) { + case 5: + case 25: + case 26: + if (!jjCanMove_1(hiByte, i1, i2, l1, l2)) + break; + if (kind > 71) + kind = 71; + jjCheckNAdd(26); + break; case 1: - if ((jjbitVec0[i2] & l2) != 0L) + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(5, 7); break; case 10: - if ((jjbitVec0[i2] & l2) != 0L) + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(2, 4); break; case 22: - if ((jjbitVec0[i2] & l2) != 0L) + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjstateSet[jjnewStateCnt++] = 18; break; default : break; @@ -844,6 +877,38 @@ private int jjMoveStringLiteralDfa1_1(long active0) static final int[] jjnextStates = { 16, 22, 8, 10, 11, 1, 2, 4, 9, 12, 17, 19, }; +private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec2[i2] & l2) != 0L); + default : + if ((jjbitVec0[i1] & l1) != 0L) + return true; + return false; + } +} +private static final boolean jjCanMove_1(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec4[i2] & l2) != 0L); + case 48: + return ((jjbitVec5[i2] & l2) != 0L); + case 49: + return ((jjbitVec6[i2] & l2) != 0L); + case 51: + return ((jjbitVec7[i2] & l2) != 0L); + case 61: + return ((jjbitVec8[i2] & l2) != 0L); + default : + if ((jjbitVec3[i1] & l1) != 0L) + return true; + return false; + } +} /** Token literal values. */ public static final String[] jjstrLiteralImages = { @@ -945,9 +1010,7 @@ protected Token jjFillToken() beginColumn = input_stream.getBeginColumn(); endLine = input_stream.getEndLine(); endColumn = input_stream.getEndColumn(); - t = Token.newToken(jjmatchedKind); - t.kind = jjmatchedKind; - t.image = curTokenImage; + t = Token.newToken(jjmatchedKind, curTokenImage); t.beginLine = beginLine; t.endLine = endLine; diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/ParseException.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/ParseException.java index 8a43495..98299aa 100644 --- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/ParseException.java +++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/ParseException.java @@ -1,4 +1,5 @@ -/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ +/* JavaCCOptions:KEEP_LINE_COL=null */ package org.eclipse.emf.emfatic.core.lang.gen.parser; /** @@ -13,24 +14,24 @@ package org.eclipse.emf.emfatic.core.lang.gen.parser; public class ParseException extends Exception { /** + * The version identifier for this Serializable class. + * Increment only if the <i>serialized</i> form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** * This constructor is used by the method "generateParseException" * in the generated parser. Calling this constructor generates * a new object of this type with the fields "currentToken", - * "expectedTokenSequences", and "tokenImage" set. The boolean - * flag "specialConstructor" is also set to true to indicate that - * this constructor was used to create this object. - * This constructor calls its super class with the empty string - * to force the "toString" method of parent class "Throwable" to - * print the error message in the form: - * ParseException: <result of getMessage> + * "expectedTokenSequences", and "tokenImage" set. */ public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal ) { - super(""); - specialConstructor = true; + super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); currentToken = currentTokenVal; expectedTokenSequences = expectedTokenSequencesVal; tokenImage = tokenImageVal; @@ -48,20 +49,13 @@ public class ParseException extends Exception { public ParseException() { super(); - specialConstructor = false; } + /** Constructor with message. */ public ParseException(String message) { super(message); - specialConstructor = false; } - /** - * This variable determines which constructor was used to create - * this object and thereby affects the semantics of the - * "getMessage" method (see below). - */ - protected boolean specialConstructor; /** * This is the last token that has been consumed successfully. If @@ -85,19 +79,16 @@ public class ParseException extends Exception { public String[] tokenImage; /** - * This method has the standard behavior when this object has been - * created using the standard constructors. Otherwise, it uses - * "currentToken" and "expectedTokenSequences" to generate a parse + * It uses "currentToken" and "expectedTokenSequences" to generate a parse * error message and returns it. If this object has been created * due to a parse error, and you do not catch it (it gets thrown - * from the parser), then this method is called during the printing - * of the final stack trace, and hence the correct error message + * from the parser) the correct error message * gets displayed. */ - public String getMessage() { - if (!specialConstructor) { - return super.getMessage(); - } + private static String initialise(Token currentToken, + int[][] expectedTokenSequences, + String[] tokenImage) { + String eol = System.getProperty("line.separator", "\n"); StringBuffer expected = new StringBuffer(); int maxSize = 0; for (int i = 0; i < expectedTokenSequences.length; i++) { @@ -105,7 +96,7 @@ public class ParseException extends Exception { maxSize = expectedTokenSequences[i].length; } for (int j = 0; j < expectedTokenSequences[i].length; j++) { - expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" "); + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); } if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { expected.append("..."); @@ -120,8 +111,11 @@ public class ParseException extends Exception { retval += tokenImage[0]; break; } + retval += " " + tokenImage[tok.kind]; + retval += " \""; retval += add_escapes(tok.image); - tok = tok.next; + retval += " \""; + tok = tok.next; } retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; retval += "." + eol; @@ -138,13 +132,13 @@ public class ParseException extends Exception { * The end of line string for this machine. */ protected String eol = System.getProperty("line.separator", "\n"); - + /** * Used to convert raw characters to their escaped version * when these raw version cannot be used as part of an ASCII * string literal. */ - protected String add_escapes(String str) { + static String add_escapes(String str) { StringBuffer retval = new StringBuffer(); char ch; for (int i = 0; i < str.length(); i++) { @@ -190,3 +184,4 @@ public class ParseException extends Exception { } } +/* JavaCC - OriginalChecksum=4572e63aae56f6a5bd28d79b2ecf0bea (do not edit this line) */ diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/SimpleCharStream.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/SimpleCharStream.java index 1ae5816..3b7460e 100644 --- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/SimpleCharStream.java +++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/SimpleCharStream.java @@ -1,4 +1,5 @@ -/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.0 */ +/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 5.0 */ +/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ package org.eclipse.emf.emfatic.core.lang.gen.parser; /** @@ -8,10 +9,12 @@ package org.eclipse.emf.emfatic.core.lang.gen.parser; public class SimpleCharStream { +/** Whether parser is static. */ public static final boolean staticFlag = false; int bufsize; int available; int tokenBegin; +/** Position in buffer. */ public int bufpos = -1; protected int bufline[]; protected int bufcolumn[]; @@ -35,210 +38,218 @@ public class SimpleCharStream protected void ExpandBuff(boolean wrapAround) { - char[] newbuffer = new char[bufsize + 2048]; - int newbufline[] = new int[bufsize + 2048]; - int newbufcolumn[] = new int[bufsize + 2048]; + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; - try - { - if (wrapAround) - { - System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - System.arraycopy(buffer, 0, newbuffer, - bufsize - tokenBegin, bufpos); - buffer = newbuffer; - - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); - bufline = newbufline; - - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); - bufcolumn = newbufcolumn; - - maxNextCharInd = (bufpos += (bufsize - tokenBegin)); - } - else - { - System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - buffer = newbuffer; - - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - bufline = newbufline; - - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - bufcolumn = newbufcolumn; - - maxNextCharInd = (bufpos -= tokenBegin); - } - } - catch (Throwable t) - { - throw new Error(t.getMessage()); - } + try + { + if (wrapAround) + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos += (bufsize - tokenBegin)); + } + else + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos -= tokenBegin); + } + } + catch (Throwable t) + { + throw new Error(t.getMessage()); + } - bufsize += 2048; - available = bufsize; - tokenBegin = 0; + bufsize += 2048; + available = bufsize; + tokenBegin = 0; } protected void FillBuff() throws java.io.IOException { - if (maxNextCharInd == available) - { - if (available == bufsize) + if (maxNextCharInd == available) + { + if (available == bufsize) + { + if (tokenBegin > 2048) { - if (tokenBegin > 2048) - { - bufpos = maxNextCharInd = 0; - available = tokenBegin; - } - else if (tokenBegin < 0) - bufpos = maxNextCharInd = 0; - else - ExpandBuff(false); + bufpos = maxNextCharInd = 0; + available = tokenBegin; } - else if (available > tokenBegin) - available = bufsize; - else if ((tokenBegin - available) < 2048) - ExpandBuff(true); + else if (tokenBegin < 0) + bufpos = maxNextCharInd = 0; else - available = tokenBegin; - } + ExpandBuff(false); + } + else if (available > tokenBegin) + available = bufsize; + else if ((tokenBegin - available) < 2048) + ExpandBuff(true); + else + available = tokenBegin; + } - int i; - try { - if ((i = inputStream.read(buffer, maxNextCharInd, - available - maxNextCharInd)) == -1) - { - inputStream.close(); - throw new java.io.IOException(); - } - else - maxNextCharInd += i; - return; - } - catch(java.io.IOException e) { - --bufpos; - backup(0); - if (tokenBegin == -1) - tokenBegin = bufpos; - throw e; - } + int i; + try { + if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) + { + inputStream.close(); + throw new java.io.IOException(); + } + else + maxNextCharInd += i; + return; + } + catch(java.io.IOException e) { + --bufpos; + backup(0); + if (tokenBegin == -1) + tokenBegin = bufpos; + throw e; + } } +/** Start. */ public char BeginToken() throws java.io.IOException { - tokenBegin = -1; - char c = readChar(); - tokenBegin = bufpos; + tokenBegin = -1; + char c = readChar(); + tokenBegin = bufpos; - return c; + return c; } protected void UpdateLineColumn(char c) { - column++; + column++; - if (prevCharIsLF) - { - prevCharIsLF = false; + if (prevCharIsLF) + { + prevCharIsLF = false; + line += (column = 1); + } + else if (prevCharIsCR) + { + prevCharIsCR = false; + if (c == '\n') + { + prevCharIsLF = true; + } + else line += (column = 1); - } - else if (prevCharIsCR) - { - prevCharIsCR = false; - if (c == '\n') - { - prevCharIsLF = true; - } - else - line += (column = 1); - } - - switch (c) - { - case '\r' : - prevCharIsCR = true; - break; - case '\n' : - prevCharIsLF = true; - break; - case '\t' : - column--; - column += (tabSize - (column % tabSize)); - break; - default : - break; - } - - bufline[bufpos] = line; - bufcolumn[bufpos] = column; + } + + switch (c) + { + case '\r' : + prevCharIsCR = true; + break; + case '\n' : + prevCharIsLF = true; + break; + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + break; + default : + break; + } + + bufline[bufpos] = line; + bufcolumn[bufpos] = column; } +/** Read a character. */ public char readChar() throws java.io.IOException { - if (inBuf > 0) - { - --inBuf; + if (inBuf > 0) + { + --inBuf; - if (++bufpos == bufsize) - bufpos = 0; + if (++bufpos == bufsize) + bufpos = 0; - return buffer[bufpos]; - } + return buffer[bufpos]; + } - if (++bufpos >= maxNextCharInd) - FillBuff(); + if (++bufpos >= maxNextCharInd) + FillBuff(); - char c = buffer[bufpos]; + char c = buffer[bufpos]; - UpdateLineColumn(c); - return (c); + UpdateLineColumn(c); + return c; } + @Deprecated /** - * @deprecated + * @deprecated * @see #getEndColumn */ public int getColumn() { - return bufcolumn[bufpos]; + return bufcolumn[bufpos]; } + @Deprecated /** - * @deprecated + * @deprecated * @see #getEndLine */ public int getLine() { - return bufline[bufpos]; + return bufline[bufpos]; } + /** Get token end column number. */ public int getEndColumn() { - return bufcolumn[bufpos]; + return bufcolumn[bufpos]; } + /** Get token end line number. */ public int getEndLine() { return bufline[bufpos]; } + /** Get token beginning column number. */ public int getBeginColumn() { - return bufcolumn[tokenBegin]; + return bufcolumn[tokenBegin]; } + /** Get token beginning line number. */ public int getBeginLine() { - return bufline[tokenBegin]; + return bufline[tokenBegin]; } +/** Backup a number of characters. */ public void backup(int amount) { inBuf += amount; if ((bufpos -= amount) < 0) - bufpos += bufsize; + bufpos += bufsize; } + /** Constructor. */ public SimpleCharStream(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { @@ -252,16 +263,20 @@ public class SimpleCharStream bufcolumn = new int[buffersize]; } + /** Constructor. */ public SimpleCharStream(java.io.Reader dstream, int startline, int startcolumn) { - this(dstream, startline, startcolumn, 4096); + this(dstream, startline, startcolumn, 4096); } + /** Constructor. */ public SimpleCharStream(java.io.Reader dstream) { - this(dstream, 1, 1, 4096); + this(dstream, 1, 1, 4096); } + + /** Reinitialise. */ public void ReInit(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { @@ -281,111 +296,128 @@ public class SimpleCharStream bufpos = -1; } + /** Reinitialise. */ public void ReInit(java.io.Reader dstream, int startline, int startcolumn) { - ReInit(dstream, startline, startcolumn, 4096); + ReInit(dstream, startline, startcolumn, 4096); } + /** Reinitialise. */ public void ReInit(java.io.Reader dstream) { - ReInit(dstream, 1, 1, 4096); + ReInit(dstream, 1, 1, 4096); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { - this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { - this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, int startcolumn) throws java.io.UnsupportedEncodingException { - this(dstream, encoding, startline, startcolumn, 4096); + this(dstream, encoding, startline, startcolumn, 4096); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream, int startline, int startcolumn) { - this(dstream, startline, startcolumn, 4096); + this(dstream, startline, startcolumn, 4096); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { - this(dstream, encoding, 1, 1, 4096); + this(dstream, encoding, 1, 1, 4096); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream) { - this(dstream, 1, 1, 4096); + this(dstream, 1, 1, 4096); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { - ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { - ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { - ReInit(dstream, encoding, 1, 1, 4096); + ReInit(dstream, encoding, 1, 1, 4096); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream) { - ReInit(dstream, 1, 1, 4096); + ReInit(dstream, 1, 1, 4096); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream, String encoding, int startline, int startcolumn) throws java.io.UnsupportedEncodingException { - ReInit(dstream, encoding, startline, startcolumn, 4096); + ReInit(dstream, encoding, startline, startcolumn, 4096); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream, int startline, int startcolumn) { - ReInit(dstream, startline, startcolumn, 4096); + ReInit(dstream, startline, startcolumn, 4096); } + /** Get token literal value. */ public String GetImage() { - if (bufpos >= tokenBegin) - return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); - else - return new String(buffer, tokenBegin, bufsize - tokenBegin) + - new String(buffer, 0, bufpos + 1); + if (bufpos >= tokenBegin) + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + else + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); } + /** Get the suffix. */ public char[] GetSuffix(int len) { - char[] ret = new char[len]; + char[] ret = new char[len]; - if ((bufpos + 1) >= len) - System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); - else - { - System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, - len - bufpos - 1); - System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); - } + if ((bufpos + 1) >= len) + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + else + { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } - return ret; + return ret; } + /** Reset buffer when finished. */ public void Done() { - buffer = null; - bufline = null; - bufcolumn = null; + buffer = null; + bufline = null; + bufcolumn = null; } /** @@ -393,47 +425,47 @@ public class SimpleCharStream */ public void adjustBeginLineColumn(int newLine, int newCol) { - int start = tokenBegin; - int len; - - if (bufpos >= tokenBegin) - { - len = bufpos - tokenBegin + inBuf + 1; - } - else - { - len = bufsize - tokenBegin + bufpos + 1 + inBuf; - } - - int i = 0, j = 0, k = 0; - int nextColDiff = 0, columnDiff = 0; - - while (i < len && - bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) - { - bufline[j] = newLine; - nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; - bufcolumn[j] = newCol + columnDiff; - columnDiff = nextColDiff; - i++; - } - - if (i < len) - { - bufline[j] = newLine++; - bufcolumn[j] = newCol + columnDiff; - - while (i++ < len) - { - if (bufline[j = start % bufsize] != bufline[++start % bufsize]) - bufline[j] = newLine++; - else - bufline[j] = newLine; - } - } + int start = tokenBegin; + int len; + + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0, j = 0, k = 0; + int nextColDiff = 0, columnDiff = 0; + + while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) + { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + bufcolumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + bufline[j] = newLine++; + bufcolumn[j] = newCol + columnDiff; + + while (i++ < len) + { + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + bufline[j] = newLine++; + else + bufline[j] = newLine; + } + } - line = bufline[j]; - column = bufcolumn[j]; + line = bufline[j]; + column = bufcolumn[j]; } } +/* JavaCC - OriginalChecksum=7f1080e3d22bca37bb31b141e8967ae7 (do not edit this line) */ diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/Token.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/Token.java index c1b2351..860e721 100644 --- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/Token.java +++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/Token.java @@ -1,11 +1,19 @@ -/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */ +/* Generated By:JavaCC: Do not edit this line. Token.java Version 5.0 */ +/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ package org.eclipse.emf.emfatic.core.lang.gen.parser; /** * Describes the input token stream. */ -public class Token { +public class Token implements java.io.Serializable { + + /** + * The version identifier for this Serializable class. + * Increment only if the <i>serialized</i> form of the + * class changes. + */ + private static final long serialVersionUID = 1L; /** * An integer that describes the kind of this token. This numbering @@ -14,12 +22,14 @@ public class Token { */ public int kind; - /** - * beginLine and beginColumn describe the position of the first character - * of this token; endLine and endColumn describe the position of the - * last character of this token. - */ - public int beginLine, beginColumn, endLine, endColumn; + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; /** * The string image of the token. @@ -51,11 +61,45 @@ public class Token { public Token specialToken; /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(int kind) + { + this(kind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(int kind, String image) + { + this.kind = kind; + this.image = image; + } + + /** * Returns the image. */ public String toString() { - return image; + return image; } /** @@ -63,19 +107,25 @@ public class Token { * can create and return subclass objects based on the value of ofKind. * Simply add the cases to the switch for all those special cases. * For example, if you have a subclass of Token called IDToken that - * you want to create if ofKind is ID, simlpy add something like : + * you want to create if ofKind is ID, simply add something like : * - * case MyParserConstants.ID : return new IDToken(); + * case MyParserConstants.ID : return new IDToken(ofKind, image); * * to the following switch statement. Then you can cast matchedToken - * variable to the appropriate type and use it in your lexical actions. + * variable to the appropriate type and use sit in your lexical actions. */ - public static final Token newToken(int ofKind) + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) { - switch(ofKind) - { - default : return new Token(); - } + return newToken(ofKind, null); } } +/* JavaCC - OriginalChecksum=550e4292dd7e44b3e51c5c2932ea1fe9 (do not edit this line) */ diff --git a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/TokenMgrError.java b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/TokenMgrError.java index 2641d3b..edeea91 100644 --- a/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/TokenMgrError.java +++ b/plugins/org.eclipse.emf.emfatic.core/src/org/eclipse/emf/emfatic/core/lang/gen/parser/TokenMgrError.java @@ -1,133 +1,147 @@ -/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */ +/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ +/* JavaCCOptions: */ package org.eclipse.emf.emfatic.core.lang.gen.parser; +/** Token Manager Error. */ public class TokenMgrError extends Error { - /* - * Ordinals for various reasons why an Error of this type can be thrown. - */ - /** - * Lexical error occured. - */ - static final int LEXICAL_ERROR = 0; + /** + * The version identifier for this Serializable class. + * Increment only if the <i>serialized</i> form of the + * class changes. + */ + private static final long serialVersionUID = 1L; - /** - * An attempt wass made to create a second instance of a static token manager. - */ - static final int STATIC_LEXER_ERROR = 1; + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ - /** - * Tried to change to an invalid lexical state. - */ - static final int INVALID_LEXICAL_STATE = 2; + /** + * Lexical error occurred. + */ + static final int LEXICAL_ERROR = 0; - /** - * Detected (and bailed out of) an infinite loop in the token manager. - */ - static final int LOOP_DETECTED = 3; + /** + * An attempt was made to create a second instance of a static token manager. + */ + static final int STATIC_LEXER_ERROR = 1; - /** - * Indicates the reason why the exception is thrown. It will have - * one of the above 4 values. - */ - int errorCode; + /** + * Tried to change to an invalid lexical state. + */ + static final int INVALID_LEXICAL_STATE = 2; - /** - * Replaces unprintable characters by their espaced (or unicode escaped) - * equivalents in the given string - */ - protected static final String addEscapes(String str) { - StringBuffer retval = new StringBuffer(); - char ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - case 0 : - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - continue; - } + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; } - return retval.toString(); - } + } + return retval.toString(); + } - /** - * Returns a detailed message for the Error when it is thrown by the - * token manager to indicate a lexical error. - * Parameters : - * EOFSeen : indicates if EOF caused the lexicl error - * curLexState : lexical state in which this error occured - * errorLine : line number when the error occured - * errorColumn : column number when the error occured - * errorAfter : prefix that was seen before this error occured - * curchar : the offending character - * Note: You can customize the lexical error message by modifying this method. - */ - protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { - return("Lexical error at line " + - errorLine + ", column " + - errorColumn + ". Encountered: " + - (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + - "after : \"" + addEscapes(errorAfter) + "\""); - } + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } - /** - * You can also modify the body of this method to customize your error messages. - * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not - * of end-users concern, so you can return something like : - * - * "Internal Error : Please file a bug report .... " - * - * from this method for such cases in the release version of your parser. - */ - public String getMessage() { - return super.getMessage(); - } + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + public String getMessage() { + return super.getMessage(); + } - /* - * Constructors of various flavors follow. - */ + /* + * Constructors of various flavors follow. + */ - public TokenMgrError() { - } + /** No arg constructor. */ + public TokenMgrError() { + } - public TokenMgrError(String message, int reason) { - super(message); - errorCode = reason; - } + /** Constructor with message and reason. */ + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } - public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { - this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); - } + /** Full Constructor. */ + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } } +/* JavaCC - OriginalChecksum=de6ba276c940257f71e59d940ec49b07 (do not edit this line) */ |