📄 css2.jj
字号:
t = <IDENT> { arg = unescape(t.image); } ( <S> )* <RROUND> { if (function.equalsIgnoreCase("lang(")) { c = _conditionFactory.createLangCondition(unescape(arg)); return (pred == null) ? c : _conditionFactory.createAndCondition(pred, c); } else { throw new CSSParseException( "Invalid pseudo function name " + function, getLocator()); } } ) )}Condition hash(Condition pred) :{ Token t;}{ t = <HASH> { Condition c = _conditionFactory.createIdCondition(t.image.substring(1)); return (pred == null) ? c : _conditionFactory.createAndCondition(pred, c); }}void styleDeclaration() :{}{ <LBRACE> ( <S> )* ( declaration() )? ( <SEMICOLON> ( <S> )* ( declaration() )? )* <RBRACE>}//// declaration// : property ':' S* expr prio?// |// ;//void declaration() :{ String p; LexicalUnit e; boolean priority = false;// CSSValue e; boolean noError = true;}{ try { p = property() <COLON> ( <S> )* e = expr() ( priority = prio() )? { _docHandler.property(p, e, priority); } } catch (ParseException ex) { System.err.println("Exception in declaration()"); noError = false; error_skipdecl(); }}//// prio// : IMPORTANT_SYM S*// ;//boolean prio() :{}{ <IMPORTANT_SYM> ( <S> )* { return true; }}//// expr// : term [ operator term ]*// ;//// TODO: Deal with the operator//LexicalUnit expr() :{ LexicalUnit head; LexicalUnit body;}{ head = term(null) { body = head; } ( ( body = operator(body) )? body = term(body) )* { return head; }}//// term// : unary_operator?// [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |// TIME S* | FREQ S* | function ]// | STRING S* | IDENT S* | URI S* | RGB S* | UNICODERANGE S* | hexcolor// ;//LexicalUnit term(LexicalUnit prev) :{ Token t; char op = ' '; String s; LexicalUnit value = null;// RGBColor color;// HexColor h;// CSSValueImpl value = null;}{/* ( ( op = unaryOperator() )? ( ( t = <NUMBER> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_NUMBER, new Float( op + t.image ) ); } | t = <PERCENTAGE> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PERCENTAGE, new Float( op + t.image ) ); } | t = <LENGTH_PX> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PX, new Float( op + t.image ) ); } | t = <LENGTH_CM> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_CM, new Float( op + t.image ) ); } | t = <LENGTH_MM> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_MM, new Float( op + t.image ) ); } | t = <LENGTH_IN> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IN, new Float( op + t.image ) ); } | t = <LENGTH_PT> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PT, new Float( op + t.image ) ); } | t = <LENGTH_PC> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PC, new Float( op + t.image ) ); } | t = <EMS> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_EMS, new Float( op + t.image ) ); } | t = <EXS> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_EXS, new Float( op + t.image ) ); } | t = <ANGLE_DEG> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_DEG, new Float( op + t.image ) ); } | t = <ANGLE_RAD> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RAD, new Float( op + t.image ) ); } | t = <ANGLE_GRAD> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_GRAD, new Float( op + t.image ) ); } | t = <TIME_MS> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_MS, new Float( op + t.image ) ); } | t = <TIME_S> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_S, new Float( op + t.image ) ); } | t = <FREQ_HZ> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_HZ, new Float( op + t.image ) ); } | t = <FREQ_KHZ> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_KHZ, new Float( op + t.image ) ); } | s = function() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + s ); } ) | t = <STRING> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_STRING, op + t.image ); } | t = <IDENT> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + t.image ); } | t = <URI> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_URI, op + t.image ); } | t = <UNICODERANGE> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + t.image ); } | color = rgb() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RGBCOLOR, color ); } | color = hexcolor() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RGBCOLOR, color ); } | t = <DIMEN> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_DIMENSION, new Float( op + t.image ) ); } | t = <INHERIT> { value = new CSSValueImpl( CSSPrimitiveValue.CSS_INHERIT, op + t.image ); } ) ( <S> )* ) { return value; }*/ ( op = unaryOperator() )? ( ( t = <NUMBER> { value = LexicalUnitImpl.createNumber(prev, value(op, t.image)); } | t = <PERCENTAGE> { value = LexicalUnitImpl.createPercentage(prev, value(op, t.image)); } | t = <LENGTH_PX> { value = LexicalUnitImpl.createPixel(prev, value(op, t.image)); } | t = <LENGTH_CM> { value = LexicalUnitImpl.createCentimeter(prev, value(op, t.image)); } | t = <LENGTH_MM> { value = LexicalUnitImpl.createMillimeter(prev, value(op, t.image)); } | t = <LENGTH_IN> { value = LexicalUnitImpl.createInch(prev, value(op, t.image)); } | t = <LENGTH_PT> { value = LexicalUnitImpl.createPoint(prev, value(op, t.image)); } | t = <LENGTH_PC> { value = LexicalUnitImpl.createPica(prev, value(op, t.image)); } | t = <EMS> { value = LexicalUnitImpl.createEm(prev, value(op, t.image)); } | t = <EXS> { value = LexicalUnitImpl.createEx(prev, value(op, t.image)); } | t = <ANGLE_DEG> { value = LexicalUnitImpl.createDegree(prev, value(op, t.image)); } | t = <ANGLE_RAD> { value = LexicalUnitImpl.createRadian(prev, value(op, t.image)); } | t = <ANGLE_GRAD> { value = LexicalUnitImpl.createGradian(prev, value(op, t.image)); } | t = <TIME_MS> { value = LexicalUnitImpl.createMillisecond(prev, value(op, t.image)); } | t = <TIME_S> { value = LexicalUnitImpl.createSecond(prev, value(op, t.image)); } | t = <FREQ_HZ> { value = LexicalUnitImpl.createHertz(prev, value(op, t.image)); } | t = <FREQ_KHZ> { value = LexicalUnitImpl.createKiloHertz(prev, value(op, t.image)); } | value = function(prev) ) | t = <STRING> { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_STRING_VALUE, t.image); } | t = <IDENT> { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_IDENT, t.image); } | t = <URI> { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_URI, t.image); } | t = <UNICODERANGE> { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_UNICODERANGE, t.image); } | value = rgb(prev) | value = hexcolor(prev) | t = <DIMEN> { int n = getLastNumPos(t.image); value = LexicalUnitImpl.createDimension( prev, value(op, t.image.substring(0, n+1)), t.image.substring(n+1)); } | t = <INHERIT> { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_INHERIT, t.image); } ) ( <S> )* { return value; }}//// function// : FUNCTION S* expr ')' S*// ;//LexicalUnit function(LexicalUnit prev) :{ Token t; LexicalUnit params;}{ t = <FUNCTION> ( <S> )* params = expr() <RROUND> { if (t.image.equalsIgnoreCase("counter(")) { return LexicalUnitImpl.createCounter(prev, params); } else if (t.image.equalsIgnoreCase("counters(")) { return LexicalUnitImpl.createCounters(prev, params); } else if (t.image.equalsIgnoreCase("attr(")) { return LexicalUnitImpl.createAttr(prev, params); } else if (t.image.equalsIgnoreCase("rect(")) { return LexicalUnitImpl.createRect(prev, params); } return LexicalUnitImpl.createFunction( prev, t.image.substring(0, t.image.length() - 1), params); }}//// rgb// : RGB S* expr ')' S*// ;//LexicalUnit rgb(LexicalUnit prev) :{ Token t; LexicalUnit params;}{ t = <RGB> ( <S> )* params = expr() <RROUND> { return LexicalUnitImpl.createRgbColor(prev, params); }}//// hexcolor// : HASH S*// ;//LexicalUnit hexcolor(LexicalUnit prev) :{ Token t;}{ t = <HASH> { // Step past the hash at the beginning int i = 1; int r = 0; int g = 0; int b = 0; int len = t.image.length() - 1; if (len == 3) { r = Integer.parseInt(t.image.substring(i + 0, i + 1), 16); g = Integer.parseInt(t.image.substring(i + 1, i + 2), 16); b = Integer.parseInt(t.image.substring(i + 2, i + 3), 16); r = (r << 4) | r; g = (g << 4) | g; b = (b << 4) | b; } else if (len == 6) { r = Integer.parseInt(t.image.substring(i + 0, i + 2), 16); g = Integer.parseInt(t.image.substring(i + 2, i + 4), 16); b = Integer.parseInt(t.image.substring(i + 4, i + 6), 16); } else { // Error } // Turn into an "rgb()" LexicalUnit lr = LexicalUnitImpl.createNumber(null, r); LexicalUnit lc1 = LexicalUnitImpl.createComma(lr); LexicalUnit lg = LexicalUnitImpl.createNumber(lc1, g); LexicalUnit lc2 = LexicalUnitImpl.createComma(lg); LexicalUnit lb = LexicalUnitImpl.createNumber(lc2, b); return LexicalUnitImpl.createRgbColor(prev, lr); }}JAVACODEfloat value(char op, String s) { return ((op == '-') ? -1 : 1) * Float.parseFloat(s);}JAVACODEint getLastNumPos(String s) { int i; for (i = 0; i < s.length(); i++) { if (Character.isLetter(s.charAt(i))) { break; } } return i - 1;}JAVACODEString unescape(String s) { int len = s.length(); StringBuffer buf = new StringBuffer(len); int index = 0; while (index < len) { char c = s.charAt(index); if (c == '\\') { if (++index < len) { c = s.charAt(index); switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': int numValue = Character.digit(c, 16); int count = 0; int p = 16; while (index + 1 < len && count < 6) { c = s.charAt(index+1); if (Character.digit(c, 16) != -1) { numValue = (numValue * 16) + Character.digit(c, 16); p *= 16; index++; } else { if (c == ' ') { // skip the latest white space index++; } break; } } buf.append((char) numValue); break; case '\n': case '\f': break; case '\r': if (index + 1 < len) { if (s.charAt(index + 1) == '\n') { index ++; } } break; default: buf.append(c); } } else { throw new CSSParseException("invalid string " + s, getLocator()); } } else { buf.append(c); } index++; } return buf.toString();}JAVACODEvoid skipSelector() { Token t = getToken(1); while (t.kind != COMMA && t.kind != SEMICOLON && t.kind != LBRACE && t.kind != EOF ) { getNextToken(); t = getToken(1); }}JAVACODEString skip() { StringBuffer sb = new StringBuffer(); int nesting = 0; Token t = getToken(0); if (t.image != null) { sb.append(t.image); } do { t = getNextToken(); if (t.kind == EOF) break; sb.append(t.image); if (t.kind == LBRACE) nesting++; else if (t.kind == RBRACE) nesting--; else if (t.kind == SEMICOLON && nesting <= 0) break; } while ((t.kind != RBRACE) || (nesting > 0)); return sb.toString();}JAVACODEvoid error_skipblock() { if (!_quiet) { ParseException e = generateParseException(); System.err.println( "** error_skipblock **\n" + e.toString() ); } Token t; int nesting = 0; do { t = getNextToken(); if( t.kind == LBRACE ) nesting++; else if( t.kind == RBRACE ) nesting--; else if( t.kind == EOF ) break; } while ((t.kind != RBRACE) || (nesting > 0));}JAVACODEvoid error_skipdecl() { if (!_quiet) { ParseException e = generateParseException(); System.err.println("** error_skipdecl **\n" + e.toString()); } Token t = getToken(1); while (t.kind != SEMICOLON && t.kind != RBRACE && t.kind != EOF ) { getNextToken(); t = getToken(1); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -