Skip to content

Commit

Permalink
Cleanup from previous commits
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
littell committed Aug 15, 2024
1 parent 06b4ea5 commit 05dc4b7
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 85 deletions.
18 changes: 0 additions & 18 deletions packages/interpreter/src/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
49 changes: 9 additions & 40 deletions packages/interpreter/src/passes/calculateTapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export class CalculateTapes extends AutoPass<Grammar> {
// 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.
Expand All @@ -186,60 +185,39 @@ export class CalculateTapes extends AutoPass<Grammar> {
//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);

if (newMsgs.length === 0) break;

// 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 =>
this.transform(v, tapeRefreshEnv).msgTo(newMsgs));
}

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;

}
}

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);
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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]);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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});
Expand Down
1 change: 0 additions & 1 deletion packages/interpreter/src/passes/constructExpr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
Expand Down
7 changes: 0 additions & 7 deletions packages/interpreter/src/passes/createOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 0 additions & 6 deletions packages/interpreter/src/passes/resolveVocab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export class ResolveVocab extends Pass<Grammar, Grammar> {
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);
Expand All @@ -60,8 +58,6 @@ export class ResolveVocabAux extends AutoPass<Grammar> {
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;
Expand All @@ -70,8 +66,6 @@ export class ResolveVocabAux extends AutoPass<Grammar> {
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});
}
Expand Down
4 changes: 0 additions & 4 deletions packages/interpreter/src/tapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 0 additions & 2 deletions packages/sheets_addon/Code.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions packages/tests/grammar/testGrammarCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ describe(`${grammarTestSuiteName(module)}`, function() {

logTestSuite(this.title);

/*
testGrammar({
desc: '1. T_t1(t1:hello)',
grammar: Cursor("t1", t1("hello")),
Expand Down Expand Up @@ -421,21 +419,18 @@ describe(`${grammarTestSuiteName(module)}`, function() {
{t1: "hip"},
],
});
*/

testGrammar({
desc: '18a. Cursor around a join-match',
grammar: Cursor(["t2", "t1"],
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"],
Expand Down Expand Up @@ -556,5 +551,4 @@ describe(`${grammarTestSuiteName(module)}`, function() {
{t1: 'h', t2: 'hih'},
],
});
*/
});
1 change: 0 additions & 1 deletion packages/tests/grammar/testGrammarUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 05dc4b7

Please sign in to comment.