lexer.ts -> fixed type errors

This commit is contained in:
tel0065 2022-03-25 11:05:38 -05:00 committed by GitHub
parent 2f4800448b
commit ca3a5163fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,7 +95,6 @@ export default class Lexer {
restart(text ? : string): void { restart(text ? : string): void {
this.pos = 0; this.pos = 0;
this._currToken = EOFTOKEN; // if no input, already on EOFTOKEN this._currToken = EOFTOKEN; // if no input, already on EOFTOKEN
if (text) { if (text) {
this.textLines = text.split('\n'); this.textLines = text.split('\n');
this.next(); // advance to the first token this.next(); // advance to the first token
@ -132,7 +131,7 @@ export default class Lexer {
// Yes... // Yes...
if (match.groups) { if (match.groups) {
token = new LineToken(r.type, this.pos, indent, match.groups["attr"]); token = new LineToken(r.type, this.pos, indent, match.groups["attr"]);
} }
else { else {
token = new LineToken(r.type, this.pos, indent); token = new LineToken(r.type, this.pos, indent);
} }
@ -149,7 +148,7 @@ export default class Lexer {
if (/^\s*(#.*)?$/.test(line)) { if (/^\s*(#.*)?$/.test(line)) {
// "empty" line // "empty" line
token = new LineToken(Symbol.EMPTY, this.pos, 999999); token = new LineToken(Symbol.EMPTY, this.pos, 999999);
} }
else { else {
// This is an INDENT token // This is an INDENT token
token = new LineToken(Symbol.INDENT, this.pos, indent); token = new LineToken(Symbol.INDENT, this.pos, indent);
@ -219,7 +218,7 @@ export default class Lexer {
if (tabFmt.hard) { if (tabFmt.hard) {
// used tabs // used tabs
indent = leadingSpace; indent = leadingSpace;
} }
else { else {
// use spaces // use spaces
indent = Math.ceil(leadingSpace / tabFmt.size!); indent = Math.ceil(leadingSpace / tabFmt.size!);
@ -229,9 +228,9 @@ export default class Lexer {
} }
/** /**
* Calculates leading spaces for a line. * Calculates leading spaces for a line.
* This method uses arithmetic to calculate the number of leading spaces * This method uses arithmetic to calculate the number of leading spaces
* *
* @param `line` The line of text. * @param `line` The line of text.
* @return The number of leading spaces of `text`. * @return The number of leading spaces of `text`.
*/ */
@ -242,11 +241,11 @@ export default class Lexer {
} }
/** /**
* Calculates leading spaces for a line. * Calculates leading spaces for a line.
* This method finds the index position of the first non-whitespace character * This method finds the index position of the first non-whitespace character
* Since the index is built using a 0-index, the position of this character * Since the index is built using a 0-index, the position of this character
* will equal the number of spaces preceding the character. * will equal the number of spaces preceding the character.
* *
* @param `text` The line of text. * @param `text` The line of text.
* @return The number of leading spaces of `text` with respect to the index position of the first non-whitespace character. * @return The number of leading spaces of `text` with respect to the index position of the first non-whitespace character.
*/ */