about summary refs log tree commit diff stats
path: root/src/css/cssparser.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/css/cssparser.nim')
-rw-r--r--src/css/cssparser.nim16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/css/cssparser.nim b/src/css/cssparser.nim
index 5ecb470a..5e76bcc0 100644
--- a/src/css/cssparser.nim
+++ b/src/css/cssparser.nim
@@ -6,6 +6,8 @@ import unicode
 import streams
 import math
 import options
+import sequtils
+import sugar
 
 import ../io/twtio
 
@@ -464,6 +466,8 @@ func curr(state: CSSParseState): CSSParsedItem =
 func has(state: CSSParseState): bool =
   return state.at < state.tokens.len
 
+proc consumeComponentValue(state: var CSSParseState): CSSComponentValue
+
 proc consumeSimpleBlock(state: var CSSParseState): CSSSimpleBlock =
   state.reconsume()
   let t = CSSToken(state.consume())
@@ -483,11 +487,10 @@ proc consumeSimpleBlock(state: var CSSParseState): CSSSimpleBlock =
       if t == CSS_LBRACE_TOKEN or t == CSS_LBRACKET_TOKEN or t == CSS_LPAREN_TOKEN:
         result.value.add(state.consumeSimpleBlock())
       else:
-        result.value.add(CSSComponentValue(t))
+        state.reconsume()
+        result.value.add(state.consumeComponentValue())
   return result
 
-proc consumeComponentValue*(state: var CSSParseState): CSSComponentValue
-
 proc consumeFunction(state: var CSSParseState): CSSFunction =
   let t = (CSSToken)state.consume()
   result = CSSFunction(name: t.value)
@@ -691,6 +694,13 @@ proc parseCSSDeclaration*(inputStream: Stream): CSSDeclaration =
 proc parseListOfDeclarations(state: var CSSParseState): seq[CSSParsedItem] =
   return state.consumeListOfDeclarations()
 
+proc parseCSSListOfDeclarations*(cvals: seq[CSSComponentValue]): seq[CSSParsedItem] =
+  var state = CSSParseState()
+  state.tokens = collect(newSeq):
+    for cval in cvals:
+      CSSParsedItem(cval)
+  return state.consumeListOfDeclarations()
+
 proc parseCSSListOfDeclarations*(inputStream: Stream): seq[CSSParsedItem] =
   var state = CSSParseState()
   state.tokens = tokenizeCSS(inputStream)