Fix some bugs in textual input/ouput

This commit is contained in:
Sam Vervaeck 2023-04-12 19:38:45 +02:00
parent 49a83f9a77
commit 17bdb2d7cb
Signed by: samvv
SSH key fingerprint: SHA256:dIg0ywU1OP+ZYifrYxy8c5esO72cIKB+4/9wkZj1VaY
3 changed files with 5 additions and 7 deletions

View file

@ -39,9 +39,8 @@ export class TextPosition {
} else { } else {
this.column++; this.column++;
} }
this.offset += text.length;
} }
this.offset += text.length;
} }
} }
@ -617,7 +616,7 @@ export class StringLiteral extends TokenBase {
} else if (code <= 127) { } else if (code <= 127) {
out += '\\x' + code.toString(16).padStart(2, '0'); out += '\\x' + code.toString(16).padStart(2, '0');
} else { } else {
out += '\\u' + code.toString(17).padStart(4, '0'); out += '\\u' + code.toString(16).padStart(4, '0');
} }
} }
out += '"'; out += '"';

View file

@ -331,14 +331,14 @@ export class ConsoleDiagnostics implements Diagnostics {
if (leftNode !== null) { if (leftNode !== null) {
this.writer.indent(); this.writer.indent();
this.writer.write(ANSI_FG_YELLOW + ANSI_BOLD + `info: ` + ANSI_RESET); this.writer.write(ANSI_FG_YELLOW + ANSI_BOLD + `info: ` + ANSI_RESET);
this.writer.write(`type ` + ANSI_FG_GREEN + describeType(diagnostic.left) + ANSI_RESET + ` was inferred from diagnostic expression:\n\n`); this.writer.write(`type ` + ANSI_FG_GREEN + describeType(diagnostic.left) + ANSI_RESET + ` was inferred from this expression:\n\n`);
this.writer.write(printNode(leftNode) + '\n'); this.writer.write(printNode(leftNode) + '\n');
this.writer.dedent(); this.writer.dedent();
} }
if (rightNode !== null) { if (rightNode !== null) {
this.writer.indent(); this.writer.indent();
this.writer.write(ANSI_FG_YELLOW + ANSI_BOLD + `info: ` + ANSI_RESET); this.writer.write(ANSI_FG_YELLOW + ANSI_BOLD + `info: ` + ANSI_RESET);
this.writer.write(`type ` + ANSI_FG_GREEN + describeType(diagnostic.right) + ANSI_RESET + ` was inferred from diagnostic expression:\n\n`); this.writer.write(`type ` + ANSI_FG_GREEN + describeType(diagnostic.right) + ANSI_RESET + ` was inferred from this expression:\n\n`);
this.writer.write(printNode(rightNode) + '\n'); this.writer.write(printNode(rightNode) + '\n');
this.writer.dedent(); this.writer.dedent();
} }

View file

@ -46,7 +46,7 @@ import {
InstanceKeyword, InstanceKeyword,
Backslash, Backslash,
} from "./cst" } from "./cst"
import { Diagnostics, UnexpectedCharDiagnostic } from "./diagnostics" import { Diagnostics } from "./diagnostics"
import { Stream, BufferedStream, assert } from "./util"; import { Stream, BufferedStream, assert } from "./util";
const EOF = '\uFFFF' const EOF = '\uFFFF'
@ -182,7 +182,6 @@ export class Scanner extends BufferedStream<Token> {
case '"': case '"':
{ {
const startPos = this.getCurrentPosition();
let contents = ''; let contents = '';
let escaping = false; let escaping = false;
for (;;) { for (;;) {