Created
December 24, 2018 14:40
-
-
Save evanxg852000/3dd52d8b3121773128d0e31a109174d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compile(file){ | |
let ast = this.parse(this._tokenize(this._readTmplSource(file))) | |
return ast | |
} | |
_tokenize(templateTxt){ | |
const token_regex = /({{.*?}}|{%.*?%})/ | |
return templateTxt.split(token_regex).filter( match => { | |
return match.trim() !== '' | |
}) | |
} | |
parse(tokens){ | |
this._parser = { | |
templater: this, | |
tokens: tokens, | |
pos: 0 | |
} | |
let rootAst = new TemplateNode(this._parser, tokens[0]) | |
this._parse(rootAst) | |
return rootAst | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment