case/when

This commit is contained in:
harttle
2016-06-15 14:55:00 +08:00
parent 611882ae10
commit d5ecce9c8b
12 changed files with 98 additions and 41 deletions
+4 -4
View File
@@ -1,3 +1,4 @@
const lexical = require('./lexical.js');
function parse(html){
var tokens = [];
@@ -12,21 +13,21 @@ function parse(html){
htmlFragment = html.slice(idx, result.index);
tokens.push({
type: 'html',
raw: htmlFragment,
value: htmlFragment
});
}
if(result[1]){
var match = result[1].trim().match(lexical.patterns.identifier);
if (!match) throw new Error('illegal tag: ' + result[1]);
tokens.push({
type: 'tag',
raw: result[1],
name: match[0],
value: result[2].trim()
});
}
else{
tokens.push({
type: 'output',
raw: result[3],
value: result[4].trim()
});
}
@@ -37,7 +38,6 @@ function parse(html){
htmlFragment = html.slice(idx, html.length);
tokens.push({
type: 'html',
raw: htmlFragment,
value: htmlFragment
});
}