feat: implement liquid and echo tags, see #428

This commit is contained in:
James Prior
2021-12-19 21:09:26 +08:00
committed by Jun Yang
parent 5b2ea63b14
commit fde9924ee6
9 changed files with 243 additions and 1 deletions
+33
View File
@@ -0,0 +1,33 @@
import { DelimitedToken } from './delimited-token'
import { TokenizationError } from '../util/error'
import { NormalizedFullOptions } from '../liquid-options'
import { TokenKind } from '../parser/token-kind'
import { Tokenizer } from '../parser/tokenizer'
export class LiquidTagToken extends DelimitedToken {
public name: string
public args: string
public constructor (
input: string,
begin: number,
end: number,
options: NormalizedFullOptions,
file?: string
) {
const value = input.slice(begin, end)
super(TokenKind.Tag, value, input, begin, end, false, false, file)
if (!/\S/.test(value)) {
// A line that contains only whitespace.
this.name = ''
this.args = ''
} else {
const tokenizer = new Tokenizer(this.content, options.operatorsTrie)
this.name = tokenizer.readIdentifier().getText()
if (!this.name) throw new TokenizationError(`illegal liquid tag syntax`, this)
tokenizer.skipBlank()
this.args = tokenizer.remaining()
}
}
}