Implement take command and comments (--) + misc cleanup
This commit is contained in:
@@ -22,6 +22,7 @@ export const tokenIsLVal = (input: LexInput): boolean =>
|
||||
|
||||
export class Lexer extends BehaviorSubject<LexToken> {
|
||||
private isEscape: boolean = false
|
||||
private inComment: boolean = false
|
||||
private inQuote?: '"'|"'"
|
||||
private tokenAccumulator: string = ''
|
||||
|
||||
@@ -57,6 +58,11 @@ export class Lexer extends BehaviorSubject<LexToken> {
|
||||
const c = inputChars.shift()!
|
||||
this.logState(c)
|
||||
|
||||
// We're in a comment. Ignore everything except newlines.
|
||||
if ( this.inComment && c !== '\n' ) {
|
||||
continue
|
||||
}
|
||||
|
||||
// We got the 2nd character after an escape
|
||||
if ( this.isEscape ) {
|
||||
this.tokenAccumulator += LITERAL_MAP[c] || c
|
||||
@@ -75,6 +81,7 @@ export class Lexer extends BehaviorSubject<LexToken> {
|
||||
if ( this.tokenAccumulator ) {
|
||||
await this.emitToken('terminator')
|
||||
}
|
||||
this.inComment = false
|
||||
await this.next({ type: 'terminator' })
|
||||
continue
|
||||
}
|
||||
@@ -87,6 +94,13 @@ export class Lexer extends BehaviorSubject<LexToken> {
|
||||
continue
|
||||
}
|
||||
|
||||
// Comments start with --
|
||||
if ( this.tokenAccumulator === '-' && c === '-' && !this.inQuote ) {
|
||||
this.tokenAccumulator = ''
|
||||
this.inComment = true
|
||||
continue
|
||||
}
|
||||
|
||||
// We are either starting or ending an unescaped matching quote.
|
||||
// For now, only parse single quotes. Makes it nicer to type " in commands.
|
||||
if ( c === `'` ) {
|
||||
|
||||
Reference in New Issue
Block a user