|
|
|
@ -144,60 +144,49 @@ export class TokenStream {
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_readStatement() { |
|
|
|
|
_missingFullLineSpaceError(tag) { |
|
|
|
|
throw new TemplateSyntaxError( |
|
|
|
|
this._cs, |
|
|
|
|
`Full-Line Tag: "${tag}" must be followed by a whitespace` |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_readFullLineGeneric(tokenType, tag) { |
|
|
|
|
// Skip whitespace
|
|
|
|
|
this._cs.nextWhile(this._isWhitespace); |
|
|
|
|
|
|
|
|
|
// Skip STATEMENT
|
|
|
|
|
this._cs.next(); |
|
|
|
|
// Skip tag
|
|
|
|
|
this._cs.next(tag.length); |
|
|
|
|
|
|
|
|
|
// Check for mandatory space
|
|
|
|
|
if (this._cs.peek() !== ' ') { |
|
|
|
|
throw new TemplateSyntaxError( |
|
|
|
|
this._cs, |
|
|
|
|
`Statement character: "${TokenStream.STATEMENT}" must be ` + |
|
|
|
|
`followed by a whitespace` |
|
|
|
|
); |
|
|
|
|
this._missingFullLineSpaceError(tag); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Consume space
|
|
|
|
|
this._cs.next(); |
|
|
|
|
|
|
|
|
|
// Remainder of line is statement
|
|
|
|
|
// Remainder of line is value
|
|
|
|
|
const value = this._cs.nextWhile((c) => c !== '\n'); |
|
|
|
|
|
|
|
|
|
// Swallow new line
|
|
|
|
|
// Skip new line
|
|
|
|
|
this._cs.next(); |
|
|
|
|
|
|
|
|
|
return {type: 'statement', value}; |
|
|
|
|
return {type: tokenType, value}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_readComment() { |
|
|
|
|
// Skip whitespace
|
|
|
|
|
this._cs.nextWhile(this._isWhitespace); |
|
|
|
|
|
|
|
|
|
// Skip COMMENT
|
|
|
|
|
this._cs.next(); |
|
|
|
|
|
|
|
|
|
// Check for mandatory space
|
|
|
|
|
if (this._cs.peek() !== ' ') { |
|
|
|
|
throw new TemplateSyntaxError( |
|
|
|
|
this._cs, |
|
|
|
|
`Comment character: "${TokenStream.COMMENT}" must be followed by a ` + |
|
|
|
|
`whitespace` |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Consume space
|
|
|
|
|
this._cs.next(); |
|
|
|
|
|
|
|
|
|
// Remainder of line is comment
|
|
|
|
|
const value = this._cs.nextWhile((c) => c !== '\n'); |
|
|
|
|
|
|
|
|
|
// Swallow new line
|
|
|
|
|
this._cs.next(); |
|
|
|
|
_readStatement() { |
|
|
|
|
return this._readFullLineGeneric( |
|
|
|
|
'statement', |
|
|
|
|
TokenStream.STATEMENT |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return {type: 'comment', value}; |
|
|
|
|
_readComment() { |
|
|
|
|
return this._readFullLineGeneric( |
|
|
|
|
'comment', |
|
|
|
|
TokenStream.COMMENT |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Utility methods
|
|
|
|
|