Skip to content

Instantly share code, notes, and snippets.

@evanxg852000
Created December 24, 2018 14:40
Show Gist options
  • Save evanxg852000/3dd52d8b3121773128d0e31a109174d9 to your computer and use it in GitHub Desktop.
Save evanxg852000/3dd52d8b3121773128d0e31a109174d9 to your computer and use it in GitHub Desktop.
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