Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,776 changes: 998 additions & 778 deletions org/w3c/css/parser/analyzer/CssParser.java

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions org/w3c/css/parser/analyzer/CssParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import org.w3c.css.values.CssCalc;
import org.w3c.css.values.CssCheckableValue;
import org.w3c.css.values.CssColor;
import org.w3c.css.values.CssComparator;
import org.w3c.css.values.CssEnv;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssFlexibleLength;
import org.w3c.css.values.CssFrequency;
Expand Down Expand Up @@ -429,6 +430,10 @@ public abstract class CssParser {
if (v.getType() == CssTypes.CSS_VARIABLE) {
expr.markCssVariable();
}
} else if ( token == FUNCTIONENV ) {
if (v.getType() == CssTypes.CSS_ENV) {
expr.markCssVariable();
}
} else if ( token == FUNCTIONCALC ) {
CssCalc c = (CssCalc) v;
if (c.hasCssVariable()) {
Expand Down Expand Up @@ -781,6 +786,7 @@ TOKEN [IGNORE_CASE] :
| <FUNCTIONCLAMP : "clamp(" >
| <FUNCTIONATTR : "attr(" >
| <FUNCTIONVAR : "var(" >
| <FUNCTIONENV : "env(" >
}

<DEFAULT>
Expand Down Expand Up @@ -3191,6 +3197,7 @@ void term(CssExpression exp) :
| func=mathclamp() { setValue(func, exp, operator, null, FUNCTION); }
| func=attr() { setValue(func, exp, operator, null, FUNCTION); }
| func=functionvar() { setValue(func, exp, operator, null, FUNCTIONVAR); }
| func=functionenv() { setValue(func, exp, operator, null, FUNCTIONENV); }
| func=function() { setValue(func, exp, operator, null, FUNCTION); }
| n=<STRING> { setValue(new CssString(), exp, operator, n, STRING); }
| n=<DIV> { setValue(new CssSwitch(), exp, operator, n, DIV); }
Expand Down Expand Up @@ -3510,6 +3517,11 @@ CssCheckableValue mathproduct() :
c.markCssVariable();
}
}
| v2=functionenv() {
if (v2.getType() == CssTypes.CSS_ENV) {
c.markCssVariable();
}
}
)
)
) {
Expand Down Expand Up @@ -3621,6 +3633,7 @@ char operator = ' ';
| v=mathclamp()
| v=attr()
| v=functionvar()
| v=functionenv()
) {
return v;
}
Expand All @@ -3646,6 +3659,38 @@ CssExpression exp = null;
}
}

CssCheckableValue functionenv() :
{ Token n;
CssExpression exp = null;
CssExpression e;
CssEnv env = null;
String skipped = null;
}
{
<FUNCTIONENV> ( <S> )* n=<IDENT> ( <S> )* {
env = new CssEnv(ac, convertIdent(n.image));
e = new CssExpression();
}
( term(e) )*
( <COMMA> ( <S> )* try {
exp = expr()
} catch (ParseException pe) {
skipped = skip_to_matching_paren();
// FIXME do something meaningful with that string
exp = null;
}
)? <RPAREN>
{
env.setNumberExp(e);
if (exp != null) {
env.setDeclaration(exp);
} else if (skipped != null) {
// do something fancy here
}
return env;
}
}

CssCheckableValue functionvar() :
{ Token n;
CssExpression exp = null;
Expand Down Expand Up @@ -3946,6 +3991,7 @@ String skip_to_matching_paren() {
case FUNCTIONROUND:
case FUNCTIONATTR:
case FUNCTIONVAR:
case FUNCTIONENV:
s.append(tok.image);
nesting++;
getNextToken();
Expand Down
9 changes: 6 additions & 3 deletions org/w3c/css/parser/analyzer/CssParserConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,13 @@ public interface CssParserConstants {
/** RegularExpression Id. */
int FUNCTIONVAR = 142;
/** RegularExpression Id. */
int FUNCTION = 143;
int FUNCTIONENV = 143;
/** RegularExpression Id. */
int HTMLSTARTTAG = 144;
int FUNCTION = 144;
/** RegularExpression Id. */
int HTMLENDTAG = 145;
int HTMLSTARTTAG = 145;
/** RegularExpression Id. */
int HTMLENDTAG = 146;

/** Lexical state. */
int DEFAULT = 0;
Expand Down Expand Up @@ -449,6 +451,7 @@ public interface CssParserConstants {
"\"clamp(\"",
"\"attr(\"",
"\"var(\"",
"\"env(\"",
"<FUNCTION>",
"<HTMLSTARTTAG>",
"<HTMLENDTAG>",
Expand Down
56 changes: 35 additions & 21 deletions org/w3c/css/parser/analyzer/CssParserTokenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.w3c.css.values.CssCheckableValue;
import org.w3c.css.values.CssColor;
import org.w3c.css.values.CssComparator;
import org.w3c.css.values.CssEnv;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssFlexibleLength;
import org.w3c.css.values.CssFrequency;
Expand Down Expand Up @@ -79,6 +80,7 @@
import java.util.ArrayList;

/** Token Manager. */
@SuppressWarnings ("unused")
public class CssParserTokenManager implements CssParserConstants {

/** Debug output. */
Expand All @@ -95,16 +97,16 @@ private int jjMoveStringLiteralDfa0_0(){
switch(curChar)
{
case 33:
jjmatchedKind = 146;
jjmatchedKind = 147;
return jjMoveNfa_0(7, 0);
case 36:
jjmatchedKind = 147;
jjmatchedKind = 148;
return jjMoveStringLiteralDfa1_0(0x1000000000000L, 0x0L, 0x0L);
case 37:
jjmatchedKind = 148;
jjmatchedKind = 149;
return jjMoveNfa_0(7, 0);
case 38:
jjmatchedKind = 149;
jjmatchedKind = 150;
return jjMoveNfa_0(7, 0);
case 40:
jjmatchedKind = 58;
Expand All @@ -131,13 +133,13 @@ private int jjMoveStringLiteralDfa0_0(){
jjmatchedKind = 51;
return jjMoveNfa_0(7, 0);
case 60:
jjmatchedKind = 152;
return jjMoveStringLiteralDfa1_0(0x800000L, 0x0L, 0x4000000L);
jjmatchedKind = 153;
return jjMoveStringLiteralDfa1_0(0x800000L, 0x0L, 0x8000000L);
case 61:
jjmatchedKind = 50;
return jjMoveNfa_0(7, 0);
case 63:
jjmatchedKind = 151;
jjmatchedKind = 152;
return jjMoveNfa_0(7, 0);
case 64:
return jjMoveStringLiteralDfa1_0(0x0L, 0x1fffffff8000L, 0x0L);
Expand All @@ -150,7 +152,7 @@ private int jjMoveStringLiteralDfa0_0(){
case 94:
return jjMoveStringLiteralDfa1_0(0x800000000000L, 0x0L, 0x0L);
case 96:
jjmatchedKind = 150;
jjmatchedKind = 151;
return jjMoveNfa_0(7, 0);
case 65:
case 97:
Expand All @@ -161,6 +163,9 @@ private int jjMoveStringLiteralDfa0_0(){
case 68:
case 100:
return jjMoveStringLiteralDfa1_0(0x0L, 0x200000000000000L, 0x0L);
case 69:
case 101:
return jjMoveStringLiteralDfa1_0(0x0L, 0x0L, 0x8000L);
case 72:
case 104:
return jjMoveStringLiteralDfa1_0(0x0L, 0xd000000000000000L, 0x0L);
Expand Down Expand Up @@ -189,7 +194,7 @@ private int jjMoveStringLiteralDfa0_0(){
case 119:
return jjMoveStringLiteralDfa1_0(0x0L, 0x800000000000000L, 0x0L);
case 124:
jjmatchedKind = 153;
jjmatchedKind = 154;
return jjMoveStringLiteralDfa1_0(0x4000000L, 0x0L, 0x0L);
case 125:
jjmatchedKind = 46;
Expand Down Expand Up @@ -244,9 +249,9 @@ else if ((active0 & 0x2000000000000L) != 0L)
jjmatchedKind = 49;
jjmatchedPos = 1;
}
else if ((active2 & 0x4000000L) != 0L)
else if ((active2 & 0x8000000L) != 0L)
{
jjmatchedKind = 154;
jjmatchedKind = 155;
jjmatchedPos = 1;
}
break;
Expand Down Expand Up @@ -279,7 +284,7 @@ else if ((active2 & 0x4000000L) != 0L)
return jjMoveStringLiteralDfa2_0(active0, 0L, active1, 0x800000000L, active2, 0L);
case 78:
case 110:
return jjMoveStringLiteralDfa2_0(active0, 0x2800000000L, active1, 0x400000000L, active2, 0L);
return jjMoveStringLiteralDfa2_0(active0, 0x2800000000L, active1, 0x400000000L, active2, 0x8000L);
case 79:
case 111:
return jjMoveStringLiteralDfa2_0(active0, 0x4000000000L, active1, 0xc000000000000000L, active2, 0x840L);
Expand Down Expand Up @@ -382,6 +387,9 @@ private int jjMoveStringLiteralDfa2_0(long old0, long active0, long old1, long a
case 85:
case 117:
return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0x80000000000L, active2, 0x800L);
case 86:
case 118:
return jjMoveStringLiteralDfa3_0(active0, 0L, active1, 0L, active2, 0x8000L);
default :
break;
}
Expand Down Expand Up @@ -417,6 +425,11 @@ else if ((active2 & 0x4000L) != 0L)
jjmatchedKind = 142;
jjmatchedPos = 3;
}
else if ((active2 & 0x8000L) != 0L)
{
jjmatchedKind = 143;
jjmatchedPos = 3;
}
break;
case 45:
if ((active0 & 0x800000L) != 0L)
Expand Down Expand Up @@ -1747,8 +1760,8 @@ else if (curChar == 62)
jjstateSet[jjnewStateCnt++] = 90;
break;
case 98:
if (curChar == 62 && kind > 144)
kind = 144;
if (curChar == 62 && kind > 145)
kind = 145;
break;
case 100:
if ((0xfc00ffffffffcbffL & l) != 0L)
Expand Down Expand Up @@ -2148,8 +2161,8 @@ else if (curChar == 62)
jjstateSet[jjnewStateCnt++] = 209;
break;
case 217:
if (curChar == 62 && kind > 145)
kind = 145;
if (curChar == 62 && kind > 146)
kind = 146;
break;
case 219:
if ((0xfc00ffffffffcbffL & l) != 0L)
Expand Down Expand Up @@ -3069,8 +3082,8 @@ else if (curChar == 62)
{ jjCheckNAddStates(1259, 1261); }
break;
case 452:
if (curChar == 40 && kind > 143)
kind = 143;
if (curChar == 40 && kind > 144)
kind = 144;
break;
case 454:
if ((0xfc00ffffffffcbffL & l) != 0L)
Expand Down Expand Up @@ -7986,7 +7999,8 @@ else if (jjmatchedPos == strPos && jjmatchedKind > strKind)
null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, "\41", "\44", "\45", "\46", "\140", "\77", "\74", "\174", "\74\75", };
null, null, null, "\41", "\44", "\45", "\46", "\140", "\77", "\74", "\174",
"\74\75", };
protected Token jjFillToken()
{
final Token t;
Expand Down Expand Up @@ -8373,10 +8387,10 @@ public void SwitchTo(int lexState)
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1,
};
static final long[] jjtoToken = {
0xffffffffffe00001L, 0xff803fffffffffffL, 0x7ffffffL,
0xffffffffffe00001L, 0xff803fffffffffffL, 0xfffffffL,
};
static final long[] jjtoSkip = {
0x2L, 0x0L, 0x0L,
Expand Down
42 changes: 22 additions & 20 deletions org/w3c/css/parser/analyzer/ParseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ParseException(String message) {
/**
* This is the last token that has been consumed successfully. If
* this object has been created due to a parse error, the token
* followng this token will (therefore) be the first error token.
* following this token will (therefore) be the first error token.
*/
public Token currentToken;

Expand Down Expand Up @@ -94,7 +94,7 @@ private static String initialise(Token currentToken,
int[][] expectedTokenSequences,
String[] tokenImage) {

StringBuffer expected = new StringBuffer();
StringBuilder expected = new StringBuilder();
int maxSize = 0;
for (int i = 0; i < expectedTokenSequences.length; i++) {
if (maxSize < expectedTokenSequences[i].length) {
Expand All @@ -108,36 +108,38 @@ private static String initialise(Token currentToken,
}
expected.append(EOL).append(" ");
}
String retval = "Encountered \"";
StringBuilder retval = new StringBuilder("Encountered \"");
Token tok = currentToken.next;
for (int i = 0; i < maxSize; i++) {
if (i != 0) retval += " ";
if (i != 0) retval.append(" ");
if (tok.kind == 0) {
retval += tokenImage[0];
retval.append(tokenImage[0]);
break;
}
retval += " " + tokenImage[tok.kind];
retval += " \"";
retval += add_escapes(tok.image);
retval += " \"";
retval.append(' ').append(tokenImage[tok.kind]);
retval.append(" \"");
retval.append(add_escapes(tok.image));
retval.append(" \"");
tok = tok.next;
}
retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
retval += "." + EOL;


if (currentToken.next != null) {
retval.append("\" at line ").append(currentToken.next.beginLine).append(", column ").append(currentToken.next.beginColumn);
}
retval.append('.').append(EOL);


if (expectedTokenSequences.length == 0) {
// Nothing to add here
} else {
if (expectedTokenSequences.length == 1) {
retval += "Was expecting:" + EOL + " ";
retval.append("Was expecting:").append(EOL).append(" ");
} else {
retval += "Was expecting one of:" + EOL + " ";
retval.append("Was expecting one of:").append(EOL).append(" ");
}
retval += expected.toString();
retval.append(expected.toString());
}
return retval;

return retval.toString();
}


Expand All @@ -147,7 +149,7 @@ private static String initialise(Token currentToken,
* string literal.
*/
static String add_escapes(String str) {
StringBuffer retval = new StringBuffer();
StringBuilder retval = new StringBuilder();
char ch;
for (int i = 0; i < str.length(); i++) {
switch (str.charAt(i))
Expand Down Expand Up @@ -190,4 +192,4 @@ static String add_escapes(String str) {
}

}
/* JavaCC - OriginalChecksum=7d68a6a068da3c9ac8d23a9a0983a253 (do not edit this line) */
/* JavaCC - OriginalChecksum=0131ff0db19134fe366be6509cf664b5 (do not edit this line) */
Loading