1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-23 00:31:31 +00:00

so much progress

This commit is contained in:
Scott Tolksdorf
2016-04-02 17:33:56 -04:00
parent 263257bfb8
commit cb5b63429e
13 changed files with 304 additions and 115 deletions

View File

@@ -49,10 +49,18 @@ var tokenizer = function(input){
current--;
}
else if(LETTERS.test(char)){
tokens.push({
type : 'word',
value : getToken(LETTERS)
});
var word = getToken(LETTERS);
if(word == 'true' || word == 'false'){
tokens.push({
type : 'boolean',
value : word == 'true'
});
}else{
tokens.push({
type : 'word',
value : word
});
}
current--;
}
else if(char == "'"){
@@ -123,24 +131,25 @@ var parser = function(tokens){
var last = null;
while(current < tokens.length && token.type != 'endTag' && token.type != 'closeTag'){
if(!key && token.type == 'word'){
if(last && token.type == 'word'){
props[last] = true;
last = token.value;
}else if(!key && token.type == 'word'){
last = token.value;
}else if(last && token.type == 'equals'){
key = last;
last = null;
}else if(key && (token.type == 'number' || token.type == 'text')){
}else if(key && (token.type == 'number' || token.type == 'text' || token.type == 'boolean')){
props[key] = token.value;
key = null;
last = null;
token = tokens[++current];
continue;
}else if(last && token.type == 'word'){
props[last] = true;
}else{
throw "Invalid property value: " + key + '=' + token.value;
}
token = tokens[++current];
}
if(last) props[last] = true;
return props;
}
@@ -177,20 +186,20 @@ var parser = function(tokens){
}
/*
/*
var test1 = `
<div test="hey there champ" more_cool=shoobydo size=0>
<div test="hey there champ" more_cool=false size=0>
<span>
Hey there!
<a>so fucking cool </span> </a>
<a>so fucking cool </a>
</span>
let's go party
<a href='neato' />
</div>
`
var test2 = "<div>Hey there!</div>"
var test2 = "<div cool=0 same>Hey there!</div>"
var tokens = tokenizer(test1);