mirror of
https://github.com/We-Dont-Byte/Mind_Reader.git
synced 2024-11-15 03:35:59 +00:00
Updated indention
Indention was incorrect, fixed.
This commit is contained in:
parent
bb0b1be0d4
commit
a10200f2bc
@ -1,9 +1,9 @@
|
||||
import { LineToken } from '.';
|
||||
import { LineToken } from '.';
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -93,8 +92,8 @@ export default class Lexer {
|
||||
* @param `text` The new text to lex.
|
||||
*/
|
||||
restart(text ? : string): void {
|
||||
this.pos = 0;
|
||||
this._currToken = EOFTOKEN; // if no input, already on EOFTOKEN
|
||||
this.pos = 0;
|
||||
this._currToken = EOFTOKEN; // if no input, already on EOFTOKEN
|
||||
if (text) {
|
||||
this.textLines = text.split('\n');
|
||||
this.next(); // advance to the first token
|
||||
@ -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!);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user