Updated indention

Indention was incorrect, fixed.
This commit is contained in:
tel0065 2022-05-05 11:56:39 -05:00 committed by GitHub
parent bb0b1be0d4
commit a10200f2bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,7 +3,7 @@ import { Symbol, EOFTOKEN, TabInfo } from './token';
type Rule = {
pattern: RegExp,
type: Symbol,
type : Symbol,
};
/**
@ -11,8 +11,7 @@ type Rule = {
* The first item is a recognition pattern, used to recognize the token
* the second item is the token type
*/
const rules: Rule[] = [
{
const rules: Rule[] = [{
pattern: /^\s*def\s+(?<attr>[a-zA-Z_][a-zA-Z0-9_]*)\(/,
type: Symbol.FUNCTION
},
@ -62,8 +61,8 @@ const rules: Rule[] = [
* Line-By-Line Lexer
*/
export default class Lexer {
private textLines: string[] = []; // array of text lines
private pos: number = 0;
private textLines : string[] = []; // array of text lines
private pos : number = 0;
private _currToken: LineToken = EOFTOKEN;
/**
@ -120,9 +119,9 @@ export default class Lexer {
// Until a LineToken is found, or EOF
while (this.pos < this.textLines.length) {
const line: string = this.textLines[this.pos];
const line : string = this.textLines[this.pos];
const indent: number = Lexer.getIndent(line, this.tabFmt!);
let token: LineToken;
let token : LineToken;
for (var r of rules) {
// Does line match pattern?
@ -131,8 +130,7 @@ export default class Lexer {
// Yes...
if (match.groups) {
token = new LineToken(r.type, this.pos, indent, match.groups["attr"]);
}
else {
} else {
token = new LineToken(r.type, this.pos, indent);
}
@ -148,8 +146,7 @@ export default class Lexer {
if (/^\s*(#.*)?$/.test(line)) {
// "empty" line
token = new LineToken(Symbol.EMPTY, this.pos, 999999);
}
else {
} else {
// This is an INDENT token
token = new LineToken(Symbol.INDENT, this.pos, indent);
}
@ -218,8 +215,7 @@ export default class Lexer {
if (tabFmt.hard) {
// used tabs
indent = leadingSpace;
}
else {
} else {
// use spaces
indent = Math.ceil(leadingSpace / tabFmt.size!);
}