Author: jmb
Date: Mon Oct 27 00:57:18 2008
New Revision: 5648
URL:
http://source.netsurf-browser.org?rev=5648&view=rev
Log:
Support signs on numbers, percentages, and dimensions
Added:
trunk/libcss/test/data/lex/regression.dat
Modified:
trunk/libcss/src/lex/lex.c
trunk/libcss/test/data/lex/INDEX
Modified: trunk/libcss/src/lex/lex.c
URL:
http://source.netsurf-browser.org/trunk/libcss/src/lex/lex.c?rev=5648&...
==============================================================================
--- trunk/libcss/src/lex/lex.c (original)
+++ trunk/libcss/src/lex/lex.c Mon Oct 27 00:57:18 2008
@@ -130,7 +130,7 @@
css_token **token);
static inline css_error AtKeyword(css_lexer *lexer, css_token **token);
-static inline css_error CDCOrIdentOrFunction(css_lexer *lexer,
+static inline css_error CDCOrIdentOrFunctionOrNPD(css_lexer *lexer,
css_token **token);
static inline css_error CDO(css_lexer *lexer, css_token **token);
static inline css_error Comment(css_lexer *lexer, css_token **token);
@@ -285,7 +285,7 @@
case sCDO:
return CDO(lexer, token);
case sCDC:
- return CDCOrIdentOrFunction(lexer, token);
+ return CDCOrIdentOrFunctionOrNPD(lexer, token);
case sS:
return S(lexer, token);
case sCOMMENT:
@@ -541,7 +541,7 @@
return emitToken(lexer, CSS_TOKEN_ATKEYWORD, token);
}
-css_error CDCOrIdentOrFunction(css_lexer *lexer, css_token **token)
+css_error CDCOrIdentOrFunctionOrNPD(css_lexer *lexer, css_token **token)
{
css_token *t = &lexer->token;
uintptr_t cptr;
@@ -553,10 +553,14 @@
/* CDC = "-->"
* IDENT = [-]? nmstart nmchar*
* FUNCTION = [-]? nmstart nmchar* '('
+ * NUMBER = num = [-+]? ([0-9]+ | [0-9]* '.' [0-9]+)
+ * PERCENTAGE = num '%'
+ * DIMENSION = num ident
*
* The first dash has been consumed. Thus, we must consume the next
* character in the stream. If it's a dash, then we're dealing with
- * CDC. Otherwise, we're dealing with IDENT/FUNCTION.
+ * CDC. If it's a digit or dot, then we're dealing with NPD.
+ * Otherwise, we're dealing with IDENT/FUNCTION.
*/
switch (lexer->substate) {
@@ -572,6 +576,16 @@
}
c = *((uint8_t *) cptr);
+
+ if (isDigit(c) || c == '.') {
+ /* NPD */
+ APPEND(lexer, cptr, clen);
+ lexer->state = sNUMBER;
+ lexer->substate = 0;
+ /* Abuse "first" to store first non-sign character */
+ lexer->context.first = c;
+ return NumberOrPercentageOrDimension(lexer, token);
+ }
if (c != '-' && !startNMStart(c)) {
/* Can only be CHAR */
@@ -975,11 +989,12 @@
enum { Initial = 0, Dot = 1, MoreDigits = 2,
Suffix = 3, NMChars = 4, Escape = 5 };
- /* NUMBER = num = [0-9]+ | [0-9]* '.' [0-9]+
+ /* NUMBER = num = [-+]? ([0-9]+ | [0-9]* '.' [0-9]+)
* PERCENTAGE = num '%'
* DIMENSION = num ident
*
- * The first digit, or '.' has been consumed.
+ * The sign, or sign and first digit or dot,
+ * or first digit, or '.' has been consumed.
*/
switch (lexer->substate) {
@@ -998,7 +1013,8 @@
return CSS_NEEDDATA;
if (cptr == PARSERUTILS_INPUTSTREAM_EOF) {
- if (t->data.len == 1 && lexer->context.first == '.')
+ if (t->data.len == 1 && (lexer->context.first == '.' ||
+ lexer->context.first == '+'))
return emitToken(lexer, CSS_TOKEN_CHAR, token);
else
return emitToken(lexer, CSS_TOKEN_NUMBER,
@@ -1042,7 +1058,8 @@
return CSS_NEEDDATA;
if (cptr == PARSERUTILS_INPUTSTREAM_EOF) {
- if (t->data.len == 1 && lexer->context.first == '.')
+ if (t->data.len == 1 && (lexer->context.first == '.' ||
+ lexer->context.first == '+'))
return emitToken(lexer, CSS_TOKEN_CHAR, token);
else
return emitToken(lexer, CSS_TOKEN_NUMBER,
@@ -1051,8 +1068,9 @@
c = *((uint8_t *) cptr);
- /* A solitary '.' is a CHAR, not numeric */
- if (t->data.len == 1 && lexer->context.first == '.')
+ /* A solitary '.' or '+' is a CHAR, not numeric */
+ if (t->data.len == 1 && (lexer->context.first == '.' ||
+ lexer->context.first == '+'))
return emitToken(lexer, CSS_TOKEN_CHAR, token);
if (c == '%') {
@@ -1183,7 +1201,7 @@
return Hash(lexer, token);
case '0': case '1': case '2': case '3': case
'4':
case '5': case '6': case '7': case '8': case
'9':
- case '.':
+ case '.': case '+':
lexer->state = sNUMBER;
lexer->substate = 0;
lexer->context.first = c;
@@ -1195,7 +1213,7 @@
case '-':
lexer->state = sCDC;
lexer->substate = 0;
- return CDCOrIdentOrFunction(lexer, token);
+ return CDCOrIdentOrFunctionOrNPD(lexer, token);
case ' ': case '\t': case '\r': case '\n': case
'\f':
lexer->state = sS;
lexer->substate = 0;
Modified: trunk/libcss/test/data/lex/INDEX
URL:
http://source.netsurf-browser.org/trunk/libcss/test/data/lex/INDEX?rev=56...
==============================================================================
--- trunk/libcss/test/data/lex/INDEX (original)
+++ trunk/libcss/test/data/lex/INDEX Mon Oct 27 00:57:18 2008
@@ -4,3 +4,4 @@
tests1.dat Basic tests
tests2.dat More complicated tests
+regression.dat Regression tests
Added: trunk/libcss/test/data/lex/regression.dat
URL:
http://source.netsurf-browser.org/trunk/libcss/test/data/lex/regression.d...
==============================================================================
--- trunk/libcss/test/data/lex/regression.dat (added)
+++ trunk/libcss/test/data/lex/regression.dat Mon Oct 27 00:57:18 2008
@@ -1,0 +1,48 @@
+#data
+-1
+#expected
+NUMBER:-1
+S
+EOF
+#reset
+
+#data
++1
+#expected
+NUMBER:+1
+S
+EOF
+#reset
+
+#data
+-1.0
+#expected
+NUMBER:-1.0
+S
+EOF
+#reset
+
+#data
++1.0
+#expected
+NUMBER:+1.0
+S
+EOF
+#reset
+
+#data
+-.5
+#expected
+NUMBER:-.5
+S
+EOF
+#reset
+
+#data
++.5
+#expected
+NUMBER:+.5
+S
+EOF
+#reset
+