From 05dc4b7fb2fcbda9e85ba5f5fbf2a9d0a9739c86 Mon Sep 17 00:00:00 2001 From: littell Date: Thu, 15 Aug 2024 10:29:40 -0400 Subject: [PATCH] Cleanup from previous commits I had left a lot of console logging and similar changes in the previous commit, because I wanted to get the solution committed before changing anything further. This cleans that up. --- packages/interpreter/src/interpreter.ts | 18 ------- .../interpreter/src/passes/calculateTapes.ts | 49 ++++--------------- .../interpreter/src/passes/constructExpr.ts | 1 - packages/interpreter/src/passes/createOps.ts | 7 --- .../interpreter/src/passes/resolveVocab.ts | 6 --- packages/interpreter/src/tapes.ts | 4 -- packages/sheets_addon/Code.js | 2 - packages/tests/grammar/testGrammarCursor.ts | 6 --- packages/tests/grammar/testGrammarUtil.ts | 1 - 9 files changed, 9 insertions(+), 85 deletions(-) diff --git a/packages/interpreter/src/interpreter.ts b/packages/interpreter/src/interpreter.ts index 5638e1fd..5fac19c5 100644 --- a/packages/interpreter/src/interpreter.ts +++ b/packages/interpreter/src/interpreter.ts @@ -236,20 +236,11 @@ export class Interpreter { query: Grammar | StringDict[] | StringDict | string = {} ): Expr { - console.log("preparing expression"); - if (this.grammar.tapes.tag == Tapes.Tag.Lit) { - console.log(`grammar vocab map is ${Vocabs.vocabDictToStr(this.grammar.tapes.vocabMap)}`); - } - // qualify the name and select the symbol let targetGrammar: Grammar = new SelectSymbol(symbol) .getEnvAndTransform(this.grammar, this.opt) .msgTo(THROWER); - if (targetGrammar.tapes.tag == Tapes.Tag.Lit) { - console.log(`selection vocab map is ${Vocabs.vocabDictToStr(targetGrammar.tapes.vocabMap)}`); - } - // join the client query to the grammar targetGrammar = new CreateQuery(query) .getEnvAndTransform(targetGrammar, this.opt) @@ -281,19 +272,10 @@ export class Interpreter { public runTests(): void { - console.log(`running tests`); - if (this.grammar.tapes.tag == Tapes.Tag.Lit) { - console.log(`grammar vocab map is ${Vocabs.vocabDictToStr(this.grammar.tapes.vocabMap)}`); - } - let targetGrammar = new SelectSymbol(ALL_SYMBOL) .getEnvAndTransform(this.grammar, this.opt) .msgTo(THROWER); - if (targetGrammar.tapes.tag == Tapes.Tag.Lit) { - console.log(`selection vocab map is ${Vocabs.vocabDictToStr(targetGrammar.tapes.vocabMap)}`); - } - targetGrammar = new ResolveVocab() .getEnvAndTransform(targetGrammar, this.opt) .msgTo(THROWER); diff --git a/packages/interpreter/src/passes/calculateTapes.ts b/packages/interpreter/src/passes/calculateTapes.ts index b135b5dd..7d43c8a4 100644 --- a/packages/interpreter/src/passes/calculateTapes.ts +++ b/packages/interpreter/src/passes/calculateTapes.ts @@ -170,7 +170,6 @@ export class CalculateTapes extends AutoPass { // first get the initial tapes for each symbol let tapeIDs: TapeDict = mapValues(g.symbols, v => v.tapes); - console.log("initial resolution"); tapeIDs = Tapes.resolveAll(tapeIDs); // check for unresolved content, and throw an exception immediately. @@ -186,20 +185,13 @@ export class CalculateTapes extends AutoPass { //const tapePusher = new CalculateTapes(true, tapeIDs); const tapePushEnv = new TapesEnv(env.opt, true, tapeIDs); - console.log(Tapes.tapeDictToStr(tapeIDs)); - console.log("second resolution"); - for (const [k, v] of Object.entries(g.symbols)) { - console.log(`pushing to ${k}`); - const transformed = this.transform(v, tapePushEnv).msgTo(newMsgs); - g.symbols[k] = transformed; - if (transformed.tapes.tag == Tapes.Tag.Lit) { - console.log(`smbol ${k} vocab is ${Vocabs.vocabDictToStr(transformed.tapes.vocabMap)}`); - } - } + //for (const [k, v] of Object.entries(g.symbols)) { + // const transformed = this.transform(v, tapePushEnv).msgTo(newMsgs); + // g.symbols[k] = transformed; + //} - console.log("done resolving"); - //g.symbols = mapValues(g.symbols, v => - // this.transform(v, tapePushEnv).msgTo(newMsgs)); + g.symbols = mapValues(g.symbols, v => + this.transform(v, tapePushEnv).msgTo(newMsgs)); msgs.push(...newMsgs); @@ -207,7 +199,6 @@ export class CalculateTapes extends AutoPass { // if there are any errors, the graph may have changed. we // need to restart the process from scratch. - //const TapeRefresher = new CalculateTapes(true); const tapeRefreshEnv = new TapesEnv(env.opt, true).update(g); // update resets the references g.symbols = mapValues(g.symbols, v => @@ -215,15 +206,6 @@ export class CalculateTapes extends AutoPass { } return updateTapes(g, Tapes.Lit()).msg(msgs); - - // TODO: The following interpretation of tapes is incorrect, - // but matches what we've been doing previously. I'm going to - // get it "working" exactly like the old way, before fixing it to be - // semantically sound. - const result = getTapesDefault(g, true).msg(msgs); - console.log(`done with default`); - return result; - } } @@ -231,15 +213,11 @@ function updateTapes(g: Grammar, tapes: TapeSet): Grammar { return update(g, { tapes }); } -function getChildTapes(g: Grammar, verbose: boolean = false): TapeSet { +function getChildTapes(g: Grammar): TapeSet { const childTapes: TapeSet[] = []; const cs = children(g); - if (verbose) console.log(`grammar has ${cs.length} children`); for (const child of cs) { const tapes = child.tapes; - if (verbose) { - console.log(`tapes of child ${child.tag}`); - } childTapes.push(tapes); } @@ -248,11 +226,8 @@ function getChildTapes(g: Grammar, verbose: boolean = false): TapeSet { return foldRight(childTapes.slice(1), Tapes.Sum, childTapes[0]); } -function getTapesDefault( - g: Grammar, - verbose: boolean = false -): Grammar { - return updateTapes(g, getChildTapes(g, verbose)); +function getTapesDefault(g: Grammar): Grammar { + return updateTapes(g, getChildTapes(g)); } function getTapesShort(g: ShortGrammar): Grammar { @@ -407,9 +382,6 @@ function getTapesEmbed( if (env.tapeMap === undefined || !(g.symbol in env.tapeMap)) throw new Error(`Unknown symbol during tapecalc: ${g.symbol}, env contains ${env.tapeMap?.keys}`); // should already be in there - const ref = env.tapeMap[g.symbol]; - console.log(`embed tape is ${Tapes.toStr(ref)}`); - return updateTapes(g, env.tapeMap[g.symbol]); } @@ -556,8 +528,6 @@ function getTapesCursor( g: CursorGrammar | GreedyCursorGrammar, env: TapesEnv ): Grammar { - console.log(`tapes for cursor ${g.tapeName} are a ${g.child.tapes.tag}`); - if (g.child.tapes.tag !== Tapes.Tag.Lit) { // can't do anything right now const tapes = Tapes.Cursor(g.child.tapes, g.tapeName); @@ -572,7 +542,6 @@ function getTapesCursor( let vocab = g.vocab; if (vocab.tag !== Vocabs.Tag.Lit) { vocab = g.child.tapes.vocabMap[g.tapeName]; - console.log(`vocab map is ${Vocabs.vocabDictToStr(g.child.tapes.vocabMap)}`); } const tapes = Tapes.Cursor(g.child.tapes, g.tapeName) // this handles deleting for us return update(g, {tapes, vocab}); diff --git a/packages/interpreter/src/passes/constructExpr.ts b/packages/interpreter/src/passes/constructExpr.ts index f3889e10..74a747da 100644 --- a/packages/interpreter/src/passes/constructExpr.ts +++ b/packages/interpreter/src/passes/constructExpr.ts @@ -164,7 +164,6 @@ function constructExprCursor( g: CursorGrammar ): Expr { const childExpr = constructExpr(env, g.child); - console.log(`vocab for cursor ${g.tapeName} is ${g.vocab}`) if (g.vocab.tag !== Vocab.Tag.Lit) { throw new Error(`Constructing cursor ${g.tapeName} with unresolved vocab: ${Vocab.toStr(g.vocab)}`); } diff --git a/packages/interpreter/src/passes/createOps.ts b/packages/interpreter/src/passes/createOps.ts index c32674dc..221a2545 100644 --- a/packages/interpreter/src/passes/createOps.ts +++ b/packages/interpreter/src/passes/createOps.ts @@ -69,13 +69,6 @@ import { PassEnv } from "../components"; "You can't assign to a name that contains a period."); } - /* - if (assignment.child instanceof TstEmpty) { - console.log(`throwing a content warning`); - throw TstError("Warning -- This symbol won't contain any content.", - assignment); - } */ - return assignment; } diff --git a/packages/interpreter/src/passes/resolveVocab.ts b/packages/interpreter/src/passes/resolveVocab.ts index 819ead5e..0b971c06 100644 --- a/packages/interpreter/src/passes/resolveVocab.ts +++ b/packages/interpreter/src/passes/resolveVocab.ts @@ -35,8 +35,6 @@ export class ResolveVocab extends Pass { throw new Error("Unresolved tapes at vocab resolution"); } - console.log(`resolving tapes for ${g.tag}`); - console.log(`vocab map is ${Vocabs.vocabDictToStr(g.tapes.vocabMap)}`); const newEnv = new ResolveVocabEnv(env.opt, g.tapes.vocabMap); const child = new ResolveVocabAux(); return child.transform(g, newEnv); @@ -60,8 +58,6 @@ export class ResolveVocabAux extends AutoPass { g: CursorGrammar | GreedyCursorGrammar, env: ResolveVocabEnv): Grammar { - console.log(`resolving vocab for cursor ${g.tapeName}`); - if (g.vocab.tag === Vocabs.Tag.Lit) { // we're done already return g; @@ -70,8 +66,6 @@ export class ResolveVocabAux extends AutoPass { const vocab = Vocabs.getFromVocabDict(env.vocabs, g.vocab.key); if (vocab == undefined) { throw new Error(`resolved vocab for ${g.tapeName}, key = ${g.vocab.key}, is undefined! map is ${Vocabs.vocabDictToStr(env.vocabs)}`); - } else { - console.log(`resolved vocab for ${g.tapeName}, key = ${g.vocab.key}, is ${Vocabs.toStr(vocab)}. map is ${Vocabs.vocabDictToStr(env.vocabs)}`); } return update(g, {vocab}); } diff --git a/packages/interpreter/src/tapes.ts b/packages/interpreter/src/tapes.ts index c22eea67..7c98551b 100644 --- a/packages/interpreter/src/tapes.ts +++ b/packages/interpreter/src/tapes.ts @@ -161,14 +161,10 @@ export function Match( inputTape: string, outputTape: string ): TapeSet { - console.log(`handling match`); if (child.tag === Tag.Lit) { - console.log(`tapes are a lit`); const newTapes = new Set(child.tapeNames); newTapes.add(outputTape); - console.log(`child vocab was ${Vocabs.vocabDictToStr(child.vocabMap)}`); const newVocabs = Vocabs.mergeKeys(child.vocabMap, inputTape, outputTape); - console.log(`new vocabs are ${Vocabs.vocabDictToStr(newVocabs)}`); return Lit(newTapes, newVocabs); } diff --git a/packages/sheets_addon/Code.js b/packages/sheets_addon/Code.js index 8bf01970..65313835 100644 --- a/packages/sheets_addon/Code.js +++ b/packages/sheets_addon/Code.js @@ -151,12 +151,10 @@ class GoogleSheetsDevEnvironment { } loadSource(sheetName) { - console.log(`loading ${sheetName}`); let sheet = SpreadsheetApp.getActive().getSheetByName(sheetName); if (sheet == undefined) { throw new Error(`There is no sheet named ${sheetName}`); } - console.log(`loaded ${sheetName}`); const range = sheet.getDataRange(); const values = range.getDisplayValues(); return values; diff --git a/packages/tests/grammar/testGrammarCursor.ts b/packages/tests/grammar/testGrammarCursor.ts index 41818c3f..f9646c66 100644 --- a/packages/tests/grammar/testGrammarCursor.ts +++ b/packages/tests/grammar/testGrammarCursor.ts @@ -29,8 +29,6 @@ describe(`${grammarTestSuiteName(module)}`, function() { logTestSuite(this.title); - /* - testGrammar({ desc: '1. T_t1(t1:hello)', grammar: Cursor("t1", t1("hello")), @@ -421,7 +419,6 @@ describe(`${grammarTestSuiteName(module)}`, function() { {t1: "hip"}, ], }); - */ testGrammar({ desc: '18a. Cursor around a join-match', @@ -429,13 +426,11 @@ describe(`${grammarTestSuiteName(module)}`, function() { Join(t1("h"), Match(Dot("t1"), "t1", "t2"))), ////tapes: [], - //priority: ["t2", "t1"], results: [ {t1: 'h', t2: 'h'}, ], }); - /* testGrammar({ desc: '18b. Cursor around a join-match, opposite direction', grammar: Cursor(["t1", "t2"], @@ -556,5 +551,4 @@ describe(`${grammarTestSuiteName(module)}`, function() { {t1: 'h', t2: 'hih'}, ], }); - */ }); diff --git a/packages/tests/grammar/testGrammarUtil.ts b/packages/tests/grammar/testGrammarUtil.ts index 24ccfd84..f3a80f7c 100644 --- a/packages/tests/grammar/testGrammarUtil.ts +++ b/packages/tests/grammar/testGrammarUtil.ts @@ -101,7 +101,6 @@ export function testGrammarAux({ testHasVocab(grammar, vocab, symbol, stripHidden); } - console.log("preparing interpreter"); const interpreter = prepareInterpreter(grammar, opt); interpreter.runTests(); testNumErrors(interpreter, numErrors);