aboutsummaryrefslogtreecommitdiff
path: root/lib/style-reader.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-05-03 22:01:34 +0100
committerMichael Williamson <mike@zwobble.org>2013-05-03 22:01:34 +0100
commit9f2a2399cdabf91d0766c9a6ddbeed0a4e2597cf (patch)
treeb94b0e78f88fb1b68a1045ca3b7dba8d1ad0ef1f /lib/style-reader.js
parent4746d8f52c7287f9f71f393f6a5220130ed3d984 (diff)
Add parsing for styles
Diffstat (limited to 'lib/style-reader.js')
-rw-r--r--lib/style-reader.js39
1 files changed, 32 insertions, 7 deletions
diff --git a/lib/style-reader.js b/lib/style-reader.js
index be5ab20..423d9d0 100644
--- a/lib/style-reader.js
+++ b/lib/style-reader.js
@@ -6,9 +6,33 @@ var htmlPaths = require("./html-paths");
exports.readHtmlPath = readHtmlPath;
exports.readDocumentMatcher = readDocumentMatcher;
+exports.readStyle = readStyle;
+function readStyle(string) {
+ return parseString(styleRule(), string);
+}
+
+function styleRule() {
+ return lop.rules.sequence(
+ lop.rules.sequence.capture(documentMatcherRule()),
+ lop.rules.tokenOfType("whitespace"),
+ lop.rules.tokenOfType("arrow"),
+ lop.rules.tokenOfType("whitespace"),
+ lop.rules.sequence.capture(htmlPathRule())
+ ).map(function(documentMatcher, htmlPath) {
+ return {
+ from: documentMatcher,
+ to: htmlPath
+ };
+ });
+}
+
function readDocumentMatcher(string) {
+ return parseString(documentMatcherRule(), string);
+}
+
+function documentMatcherRule() {
var sequence = lop.rules.sequence;
var paragraphRule = lop.rules.then(
@@ -30,18 +54,19 @@ function readDocumentMatcher(string) {
runRule
);
- var matcherRule = sequence(
+ return sequence(
sequence.capture(elementTypeRule),
sequence.capture(lop.rules.optional(classRule))
).map(function(createMatcher, styleName) {
return createMatcher(styleName.valueOrElse());
});
-
- return parseString(matcherRule, string);
}
-
function readHtmlPath(string) {
+ return parseString(htmlPathRule(), string);
+}
+
+function htmlPathRule() {
var capture = lop.rules.sequence.capture;
var whitespaceRule = lop.rules.tokenOfType("whitespace");
var freshRule = lop.rules.then(
@@ -72,7 +97,7 @@ function readHtmlPath(string) {
return htmlPaths.element(tagName, attributes, options);
});
- var styleRule = lop.rules.then(
+ return lop.rules.then(
lop.rules.zeroOrMoreWithSeparator(
styleElementRule,
lop.rules.sequence(
@@ -83,7 +108,6 @@ function readHtmlPath(string) {
),
htmlPaths.elements
);
- return parseString(styleRule, string);
}
var identifierRule = lop.rules.tokenOfType("identifier");
@@ -117,7 +141,8 @@ function tokenise(string) {
{name: "dot", regex: /\./},
{name: "colon", regex: /:/},
{name: "gt", regex: />/},
- {name: "whitespace", regex: /\s+/}
+ {name: "whitespace", regex: /\s+/},
+ {name: "arrow", regex: /=>/}
]);
return tokeniser.tokenise(string);
}