Try fruitlessly to make c2g parsing more tolerant of mistakes

This commit is contained in:
Eevee (Evelyn Woods) 2024-04-20 01:44:32 -06:00
parent 06ceb827f3
commit b44da28020
2 changed files with 6 additions and 3 deletions

View File

@ -159,6 +159,7 @@ export class StoredLevel extends LevelInterface {
export class StoredPack { export class StoredPack {
constructor(identifier, level_loader) { constructor(identifier, level_loader) {
// This isn't very strongly defined, but it's used to distinguish scores for packs and URLs
this.identifier = identifier; this.identifier = identifier;
this.title = ""; this.title = "";
this._level_loader = level_loader; this._level_loader = level_loader;

View File

@ -1775,7 +1775,7 @@ const TOKENIZE_RX = RegExp(
// 2: Comments are preceded by ; or // for some reason and run to the end of the line // 2: Comments are preceded by ; or // for some reason and run to the end of the line
'|(?:;|//)(.*)' + '|(?:;|//)(.*)' +
// 3: Strings are double-quoted (only!) and contain no escapes // 3: Strings are double-quoted (only!) and contain no escapes
'|"([^"]*?)"' + '|"([^"]*?)(?:"|$)' +
// 4: Labels are indicated by a #, including when used with 'goto' // 4: Labels are indicated by a #, including when used with 'goto'
// (the exact set of allowed characters is unclear and i'm fudging it here) // (the exact set of allowed characters is unclear and i'm fudging it here)
'|#(\\w+)' + '|#(\\w+)' +
@ -1790,7 +1790,7 @@ const TOKENIZE_RX = RegExp(
'|([a-zA-Z]\\S*)' + '|([a-zA-Z]\\S*)' +
// 8: Anything else is an error // 8: Anything else is an error
'|(\\S+)' + '|(\\S+)' +
')', 'g'); ')', 'gm');
const DIRECTIVES = { const DIRECTIVES = {
// Important stuff // Important stuff
'chdir': ['string'], 'chdir': ['string'],
@ -1894,6 +1894,7 @@ class ParseError extends Error {
super(`${message} at line ${parser.lineno}`); super(`${message} at line ${parser.lineno}`);
} }
} }
ParseError.prototype.name = 'ParseError';
class Parser { class Parser {
constructor(string) { constructor(string) {
@ -2191,8 +2192,9 @@ const MAX_SIMULTANEOUS_REQUESTS = 5;
if (stmt.kind === 'directive' && stmt.name === 'map') { if (stmt.kind === 'directive' && stmt.name === 'map') {
let path = stmt.args[0].value; let path = stmt.args[0].value;
path = path.replace(/\\/, '/'); path = path.replace(/\\/, '/');
// FIXME can we get away with not downloading all of them eagerly?
fetch_map(path, level_number); fetch_map(path, level_number);
level_number++; level_number += 1;
} }
else if (stmt.kind === 'directive' && stmt.name === 'game') { else if (stmt.kind === 'directive' && stmt.name === 'game') {
// TODO apparently cc2 lets you change this mid-game and will then use a different save // TODO apparently cc2 lets you change this mid-game and will then use a different save