From 180c5bf6665c906015dbeb6fa05b12b301f6b5b9 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 13:59:35 -0500 Subject: [PATCH 01/14] make way for dl2 language specs --- apps/languageWorkbench/main.tsx | 4 ++-- languageWorkbench/benchmarks.ts | 2 +- languageWorkbench/common/types.ts | 14 +++++++++++++- languageWorkbench/ddTests.ts | 18 +++++++++++++----- languageWorkbench/interpCache.ts | 18 ++++++++++++++++-- .../languages/basicBlocks/index.ts | 4 ++-- languageWorkbench/languages/contracts/index.ts | 4 ++-- languageWorkbench/languages/dl/index.ts | 4 ++-- languageWorkbench/languages/dl2/index.ts | 4 ++-- languageWorkbench/languages/dl2/instantiate.ts | 10 +++++----- languageWorkbench/languages/fp/index.ts | 4 ++-- languageWorkbench/languages/grammar/index.ts | 4 ++-- languageWorkbench/languages/json/index.ts | 4 ++-- languageWorkbench/languages/modelica/index.ts | 4 ++-- languageWorkbench/languages/opt/index.ts | 4 ++-- languageWorkbench/languages/plainText/index.ts | 4 ++-- languageWorkbench/languages/sql/index.ts | 4 ++-- languageWorkbench/languages/treeSQL/index.ts | 4 ++-- 18 files changed, 74 insertions(+), 40 deletions(-) diff --git a/apps/languageWorkbench/main.tsx b/apps/languageWorkbench/main.tsx index ef5083ede..97293cbcf 100644 --- a/apps/languageWorkbench/main.tsx +++ b/apps/languageWorkbench/main.tsx @@ -26,7 +26,7 @@ function Workbench() { const curLangSpec: LanguageSpec = { name: versionedLangID, - datalog: curLangState.datalog.source, + logic: curLangState.datalog.source, example: curLangState.example.source, grammar: curLangState.grammar.source, }; @@ -158,7 +158,7 @@ const emptyState: State = mapObj(LANGUAGES, (langID, spec) => ({ version: 1, example: { cursorPos: 1, source: spec.example }, grammar: { cursorPos: 1, source: spec.grammar }, - datalog: { cursorPos: 1, source: spec.datalog }, + datalog: { cursorPos: 1, source: spec.logic }, })); type Action = { type: "UpdateLang"; langID: string; action: LangAction }; diff --git a/languageWorkbench/benchmarks.ts b/languageWorkbench/benchmarks.ts index ae3791d46..ddf4cc770 100644 --- a/languageWorkbench/benchmarks.ts +++ b/languageWorkbench/benchmarks.ts @@ -229,7 +229,7 @@ const flattenedByRule = flattenByRule(ruleTree, input, LEAVES); const langSpec: LanguageSpec = { name: "datalog", - datalog: fs.readFileSync(`languageWorkbench/languages/dl/dl.dl`, "utf8"), + logic: fs.readFileSync(`languageWorkbench/languages/dl/dl.dl`, "utf8"), grammar: fs.readFileSync(`languageWorkbench/languages/dl/dl.grammar`, "utf8"), example: "", }; diff --git a/languageWorkbench/common/types.ts b/languageWorkbench/common/types.ts index 9220c4825..77fe0495e 100644 --- a/languageWorkbench/common/types.ts +++ b/languageWorkbench/common/types.ts @@ -3,7 +3,7 @@ import { Grammar, Span } from "../parserlib/types"; export type LanguageSpec = { name: string; - datalog: string; + logic: LogicSpec; grammar: string; example: string; triggerCharacters?: string[]; // TODO: put into DL itself or derive from grammar @@ -11,6 +11,18 @@ export type LanguageSpec = { leaves?: Set; }; +export type LogicSpec = + | { type: "DL"; source: string } + | { type: "DL2"; source: string }; + +export function dl(source: string): LogicSpec { + return { type: "DL", source }; +} + +export function dl2(source: string): LogicSpec { + return { type: "DL2", source }; +} + export type LangImpl = { grammar: Grammar; scopeDefn: ( diff --git a/languageWorkbench/ddTests.ts b/languageWorkbench/ddTests.ts index ed310bdc0..dcd290695 100644 --- a/languageWorkbench/ddTests.ts +++ b/languageWorkbench/ddTests.ts @@ -9,7 +9,7 @@ import { import { datalogOut, plainTextOut } from "../util/ddTest/types"; import * as fs from "fs"; import { Suite } from "../util/testBench/testing"; -import { LanguageSpec } from "./common/types"; +import { LanguageSpec, dl } from "./common/types"; import { IncrementalInterpreter } from "../core/incremental/interpreter"; import { compile } from "./languages/dl2/compile"; import { extractModule } from "./languages/dl2/extract"; @@ -105,11 +105,17 @@ function dl2RunTest(test: string[]): TestOutput[] { const decls = lines.slice(0, lines.length - 1).join("\n"); const query = lines[lines.length - 1]; + let interp: AbstractInterpreter = new SimpleInterpreter( + BASE_PATH, + fsLoader + ); + // TODO: get parse problems - const [interp, problems] = instantiate(parseMain(decls)); + const [newInterp, problems] = instantiate(interp, decls); if (problems.length > 0) { throw new Error(`problems: ${problems}`); } + interp = newInterp; // Query const res = interp.queryStr(query); @@ -129,9 +135,11 @@ export function testLangQuery( const query = lines[lines.length - 1]; const langSpec: LanguageSpec = { name: langName, - datalog: fs.readFileSync( - `languageWorkbench/languages/${langName}/${langName}.dl`, - "utf8" + logic: dl( + fs.readFileSync( + `languageWorkbench/languages/${langName}/${langName}.dl`, + "utf8" + ) ), grammar: fs.readFileSync( `languageWorkbench/languages/${langName}/${langName}.grammar`, diff --git a/languageWorkbench/interpCache.ts b/languageWorkbench/interpCache.ts index c1509bd37..65e0d452f 100644 --- a/languageWorkbench/interpCache.ts +++ b/languageWorkbench/interpCache.ts @@ -1,5 +1,6 @@ import { AbstractInterpreter } from "../core/abstractInterpreter"; import { LanguageSpec } from "./common/types"; +import { instantiate } from "./languages/dl2/instantiate"; import { parseMain } from "./languages/grammar/parser"; import { declareTables, flatten, getUnionRule } from "./parserlib/flatten"; import { parse, TraceTree } from "./parserlib/parser"; @@ -114,8 +115,21 @@ export class InterpCache { // add datalog try { - if (langSpec.datalog.length > 0) { - interp = interp.evalStr(langSpec.datalog)[1]; + switch (langSpec.logic.type) { + case "DL": { + interp = interp.evalStr(langSpec.logic.source)[1]; + break; + } + case "DL2": { + const [newInterp, problems] = instantiate( + interp, + langSpec.logic.source + ); + // TODO: show in UI + console.error("DL2 extraction problems", problems); + interp = newInterp; + break; + } } interp = interp.evalRawStmts(declareTables(grammar))[1]; interp = interp.evalStmt({ diff --git a/languageWorkbench/languages/basicBlocks/index.ts b/languageWorkbench/languages/basicBlocks/index.ts index 7ea6c1fb8..82a11dda3 100644 --- a/languageWorkbench/languages/basicBlocks/index.ts +++ b/languageWorkbench/languages/basicBlocks/index.ts @@ -1,4 +1,4 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; // @ts-ignore import datalog from "./basicBlocks.dl"; // @ts-ignore @@ -8,7 +8,7 @@ import example from "./example.txt"; export const basicBlocks: LanguageSpec = { name: "basicBlocks", - datalog, + logic: dl(datalog), grammar, example, }; diff --git a/languageWorkbench/languages/contracts/index.ts b/languageWorkbench/languages/contracts/index.ts index 945e4d7a3..2251bff30 100644 --- a/languageWorkbench/languages/contracts/index.ts +++ b/languageWorkbench/languages/contracts/index.ts @@ -1,4 +1,4 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; // @ts-ignore import datalog from "./contracts.dl"; // @ts-ignore @@ -8,7 +8,7 @@ import example from "./example.txt"; export const contracts: LanguageSpec = { name: "contracts", - datalog, + logic: dl(datalog), grammar, example, }; diff --git a/languageWorkbench/languages/dl/index.ts b/languageWorkbench/languages/dl/index.ts index e2644a740..066da536c 100644 --- a/languageWorkbench/languages/dl/index.ts +++ b/languageWorkbench/languages/dl/index.ts @@ -1,4 +1,4 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; import { datalogLangImpl } from "./dl"; // @ts-ignore import datalogTxt from "./dl.dl"; @@ -9,7 +9,7 @@ import example from "./example.txt"; export const datalog: LanguageSpec = { name: "datalog", - datalog: datalogTxt, + logic: dl(datalogTxt), grammar, example, // TODO: derive these from the grammar diff --git a/languageWorkbench/languages/dl2/index.ts b/languageWorkbench/languages/dl2/index.ts index 05acf469d..715fac5af 100644 --- a/languageWorkbench/languages/dl2/index.ts +++ b/languageWorkbench/languages/dl2/index.ts @@ -1,4 +1,4 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; // @ts-ignore import datalog from "./dl2.dl"; // @ts-ignore @@ -8,7 +8,7 @@ import example from "./example.txt"; export const datalog2: LanguageSpec = { name: "datalog2", - datalog, + logic: dl(datalog), grammar, example, }; diff --git a/languageWorkbench/languages/dl2/instantiate.ts b/languageWorkbench/languages/dl2/instantiate.ts index a4c79b5e4..f75146ba3 100644 --- a/languageWorkbench/languages/dl2/instantiate.ts +++ b/languageWorkbench/languages/dl2/instantiate.ts @@ -1,14 +1,15 @@ import { AbstractInterpreter } from "../../../core/abstractInterpreter"; -import { nullLoader } from "../../../core/loaders"; -import { SimpleInterpreter } from "../../../core/simple/interpreter"; import { compile } from "./compile"; import { extractModule } from "./extract"; -import { DL2Main } from "./parser"; +import { parseMain } from "./parser"; import { ExtractionProblem } from "./types"; export function instantiate( - parsed: DL2Main + interp: AbstractInterpreter, + source: string ): [AbstractInterpreter, ExtractionProblem[]] { + const parsed = parseMain(source); + // Extract const problems: ExtractionProblem[] = []; const [mod, extractProblems] = extractModule(parsed); @@ -23,7 +24,6 @@ export function instantiate( } // Instantiate - let interp: AbstractInterpreter = new SimpleInterpreter(".", nullLoader); for (const rule of Object.values(compiled)) { interp = interp.evalStmt({ type: "Rule", rule })[1]; } diff --git a/languageWorkbench/languages/fp/index.ts b/languageWorkbench/languages/fp/index.ts index 2d9f237e2..083088c52 100644 --- a/languageWorkbench/languages/fp/index.ts +++ b/languageWorkbench/languages/fp/index.ts @@ -1,4 +1,4 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; // @ts-ignore import datalog from "./fp.dl"; // @ts-ignore @@ -8,7 +8,7 @@ import example from "./example.txt"; export const fp: LanguageSpec = { name: "fp", - datalog, + logic: dl(datalog), grammar, example, }; diff --git a/languageWorkbench/languages/grammar/index.ts b/languageWorkbench/languages/grammar/index.ts index 3a1825092..eae926eb2 100644 --- a/languageWorkbench/languages/grammar/index.ts +++ b/languageWorkbench/languages/grammar/index.ts @@ -1,4 +1,4 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; // @ts-ignore import datalog from "./grammar.dl"; // @ts-ignore @@ -8,7 +8,7 @@ import example from "./example.txt"; export const grammar: LanguageSpec = { name: "grammar", - datalog, + logic: dl(datalog), grammar: grammarTxt, example, }; diff --git a/languageWorkbench/languages/json/index.ts b/languageWorkbench/languages/json/index.ts index 35dcd4d85..218257c70 100644 --- a/languageWorkbench/languages/json/index.ts +++ b/languageWorkbench/languages/json/index.ts @@ -1,4 +1,4 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; // @ts-ignore import datalog from "./json.dl"; // @ts-ignore @@ -8,7 +8,7 @@ import example from "./example.txt"; export const json: LanguageSpec = { name: "json", - datalog, + logic: dl(datalog), grammar, example, }; diff --git a/languageWorkbench/languages/modelica/index.ts b/languageWorkbench/languages/modelica/index.ts index b19f172f6..2eaec4b0f 100644 --- a/languageWorkbench/languages/modelica/index.ts +++ b/languageWorkbench/languages/modelica/index.ts @@ -1,4 +1,4 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; // @ts-ignore import datalog from "./modelica.dl"; // @ts-ignore @@ -8,7 +8,7 @@ import example from "./example.txt"; export const modelica: LanguageSpec = { name: "modelica", - datalog, + logic: dl(datalog), grammar, example, }; diff --git a/languageWorkbench/languages/opt/index.ts b/languageWorkbench/languages/opt/index.ts index cc248f7f3..c6c459ff7 100644 --- a/languageWorkbench/languages/opt/index.ts +++ b/languageWorkbench/languages/opt/index.ts @@ -1,4 +1,4 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; // @ts-ignore import datalogTxt from "./opt.dl"; // @ts-ignore @@ -8,7 +8,7 @@ import example from "./example.txt"; export const opt: LanguageSpec = { name: "opt", - datalog: datalogTxt, + logic: dl(datalogTxt), grammar, example, leaves: new Set(["ident", "stringLit", "intLit"]), diff --git a/languageWorkbench/languages/plainText/index.ts b/languageWorkbench/languages/plainText/index.ts index 289651f83..0d14a3d6c 100644 --- a/languageWorkbench/languages/plainText/index.ts +++ b/languageWorkbench/languages/plainText/index.ts @@ -1,8 +1,8 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; export const plainText: LanguageSpec = { name: "plainText", - datalog: "", + logic: dl(""), grammar: `main :- repSep(., "").`, example: "", }; diff --git a/languageWorkbench/languages/sql/index.ts b/languageWorkbench/languages/sql/index.ts index a4a19c347..5a6336523 100644 --- a/languageWorkbench/languages/sql/index.ts +++ b/languageWorkbench/languages/sql/index.ts @@ -1,4 +1,4 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; // @ts-ignore import datalog from "./sql.dl"; // @ts-ignore @@ -8,7 +8,7 @@ import example from "./example.txt"; export const sql: LanguageSpec = { name: "sql", - datalog, + logic: dl(datalog), grammar, example, }; diff --git a/languageWorkbench/languages/treeSQL/index.ts b/languageWorkbench/languages/treeSQL/index.ts index 0e0fa34ca..899dfbd4a 100644 --- a/languageWorkbench/languages/treeSQL/index.ts +++ b/languageWorkbench/languages/treeSQL/index.ts @@ -1,4 +1,4 @@ -import { LanguageSpec } from "../../common/types"; +import { LanguageSpec, dl } from "../../common/types"; // @ts-ignore import datalog from "./treeSQL.dl"; // @ts-ignore @@ -8,7 +8,7 @@ import example from "./example.txt"; export const treeSQL: LanguageSpec = { name: "treeSQL", - datalog, + logic: dl(datalog), grammar, example, }; From 80b89b75c66b31dd53986d2b83c4bf599d4eb1b7 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 14:03:15 -0500 Subject: [PATCH 02/14] fixes --- apps/languageWorkbench/main.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/languageWorkbench/main.tsx b/apps/languageWorkbench/main.tsx index 97293cbcf..15b269c77 100644 --- a/apps/languageWorkbench/main.tsx +++ b/apps/languageWorkbench/main.tsx @@ -9,7 +9,7 @@ import useHashParam from "use-hash-param"; import { ErrorList } from "../../uiCommon/ide/errorList"; import { addCursor } from "../../languageWorkbench/interpCache"; import { CollapsibleWithHeading } from "../../uiCommon/generic/collapsible"; -import { LanguageSpec } from "../../languageWorkbench/common/types"; +import { LanguageSpec, dl } from "../../languageWorkbench/common/types"; import { CACHE } from "../../languageWorkbench/vscode/common"; function Main() { @@ -26,7 +26,7 @@ function Workbench() { const curLangSpec: LanguageSpec = { name: versionedLangID, - logic: curLangState.datalog.source, + logic: dl(curLangState.datalog.source), example: curLangState.example.source, grammar: curLangState.grammar.source, }; @@ -158,7 +158,7 @@ const emptyState: State = mapObj(LANGUAGES, (langID, spec) => ({ version: 1, example: { cursorPos: 1, source: spec.example }, grammar: { cursorPos: 1, source: spec.grammar }, - datalog: { cursorPos: 1, source: spec.logic }, + datalog: { cursorPos: 1, source: spec.logic.source }, // TODO: differentiate DL2 })); type Action = { type: "UpdateLang"; langID: string; action: LangAction }; From c0c2d23a5b50be14a3fad3862cae4e424de00ab8 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 14:04:59 -0500 Subject: [PATCH 03/14] update build --- package.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index cc00486de..50028c197 100644 --- a/package.json +++ b/package.json @@ -13,27 +13,27 @@ "repl": "ts-node apps/cmd/repl/main.ts", "build-dist": "tsc --jsx react --outDir dist --declaration --esModuleInterop apps/fiddle/main.tsx && tsc --outDir dist apps/cmd/repl/main.ts", "build-interp-bundle": "esbuild --bundle --outfile=dist/index.mjs --format=esm --target=es6 core/simple/interpreter.ts", - "build-fp-ui": "esbuild apps/fp/main.tsx --bundle --outfile=apps/fp/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --loader:.grammar=text --loader:.dl=text --loader:.css=text --sourcemap --external:path --external:fs --external:crypto", + "build-fp-ui": "esbuild apps/fp/main.tsx --bundle --outfile=apps/fp/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --loader:.grammar=text --loader:.dl=text --loader:.dl2=text --loader:.css=text --sourcemap --external:path --external:fs --external:crypto", "serve-fp-ui": "cd apps/fp/public && http-server -c-1", - "build-fiddle": "esbuild apps/fiddle/main.tsx --bundle --outfile=apps/fiddle/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --loader:.dl=text --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text --loader:.css=text --loader:.grammar=text", + "build-fiddle": "esbuild apps/fiddle/main.tsx --bundle --outfile=apps/fiddle/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --loader:.dl=text --loader:.dl2=text --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text --loader:.dl2=text --loader:.css=text --loader:.grammar=text", "serve-fiddle": "cd apps/fiddle/public && http-server -c-1", "build-notebook-ui": "esbuild apps/notebook/main.tsx --bundle --outfile=apps/notebook/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --sourcemap --external:path --external:fs --external:crypto", "serve-notebook-ui": "cd apps/notebook/public && http-server -c-1", - "build-actors-ui": "esbuild apps/actors/main.tsx --bundle --outfile=apps/actors/public/bundle.js --sourcemap '--define:process.env.NODE_ENV=\"development\"' --loader:.dl=text --external:path --external:fs --external:crypto", + "build-actors-ui": "esbuild apps/actors/main.tsx --bundle --outfile=apps/actors/public/bundle.js --sourcemap '--define:process.env.NODE_ENV=\"development\"' --loader:.dl=text --loader:.dl2=text --external:path --external:fs --external:crypto", "serve-actors-ui": "cd apps/actors/public && http-server -c-1", - "build-language-workbench": "esbuild apps/languageWorkbench/main.tsx --bundle --outfile=apps/languageWorkbench/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text --loader:.css=text --loader:.grammar=text", + "build-language-workbench": "esbuild apps/languageWorkbench/main.tsx --bundle --outfile=apps/languageWorkbench/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text --loader:.dl2=text --loader:.css=text --loader:.grammar=text", "serve-language-workbench": "cd apps/languageWorkbench/public && http-server -c-1", - "build-dl-parser-playground": "esbuild apps/dlParser/main.tsx --bundle --outfile=apps/dlParser/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --loader:.dl=text --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text --loader:.css=text --loader:.grammar=text", + "build-dl-parser-playground": "esbuild apps/dlParser/main.tsx --bundle --outfile=apps/dlParser/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --loader:.dl=text --loader:.dl2=text --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text --loader:.dl2=text --loader:.css=text --loader:.grammar=text", "serve-dl-parser-playground": "cd apps/dlParser/public && http-server -c-1", "build-ddtest-viewer": "esbuild apps/ddTestViewer/main.tsx --bundle --outfile=apps/ddTestViewer/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --sourcemap --external:path --external:fs --external:crypto", "serve-ddtest-viewer": "cd apps/ddTestViewer/public && http-server -c-1", - "build-sim": "esbuild apps/sim/main.tsx --bundle --outfile=apps/sim/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text", + "build-sim": "esbuild apps/sim/main.tsx --bundle --outfile=apps/sim/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text --loader:.dl2=text", "serve-sim": "cd apps/sim/public && http-server -c-1", - "build-execution-visualizer": "esbuild apps/executionVisualizer/main.tsx --bundle --outfile=apps/executionVisualizer/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text --loader:.grammar=text --loader:.ttf=text", + "build-execution-visualizer": "esbuild apps/executionVisualizer/main.tsx --bundle --outfile=apps/executionVisualizer/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text --loader:.dl2=text --loader:.grammar=text --loader:.ttf=text", "serve-execution-visualizer": "cd apps/executionVisualizer/public && http-server -c-1", - "build-opt-playground": "esbuild apps/optPlayground/main.tsx --bundle --outfile=apps/optPlayground/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text --loader:.grammar=text --loader:.ttf=text", + "build-opt-playground": "esbuild apps/optPlayground/main.tsx --bundle --outfile=apps/optPlayground/public/bundle.js '--define:process.env.NODE_ENV=\"development\"' --sourcemap --external:path --external:fs --external:crypto --loader:.dl=text --loader:.dl2=text --loader:.grammar=text --loader:.ttf=text", "serve-opt-playground": "cd apps/optPlayground/public && http-server -c-1", - "build-vscode-extension": "esbuild apps/vscodeExtension/extension.ts --bundle --sourcemap --platform=node --outfile=apps/vscodeExtension/out/extension.js --external:vscode --loader:.dl=text --loader:.grammar=text --loader:.html=text && esbuild apps/vscodeExtension/webView.tsx --bundle --sourcemap '--define:process.env.NODE_ENV=\"development\"' --outfile=apps/vscodeExtension/out/webView.js --external:path --external:fs --external:crypto --loader:.dl=text --loader:.grammar=text --loader:.html=text", + "build-vscode-extension": "esbuild apps/vscodeExtension/extension.ts --bundle --sourcemap --platform=node --outfile=apps/vscodeExtension/out/extension.js --external:vscode --loader:.dl=text --loader:.dl2=text --loader:.grammar=text --loader:.html=text && esbuild apps/vscodeExtension/webView.tsx --bundle --sourcemap '--define:process.env.NODE_ENV=\"development\"' --outfile=apps/vscodeExtension/out/webView.js --external:path --external:fs --external:crypto --loader:.dl=text --loader:.dl2=text --loader:.grammar=text --loader:.html=text", "package-vscode-extension": "cd apps/vscodeExtension && vsce package", "generate-datalog-parser": "ts-node languageWorkbench/parserlib/gen/cli.ts languageWorkbench/languages/dl/dl.grammar languageWorkbench/languages/dl/parser.ts ../../parserlib DL ws && prettier --write languageWorkbench/languages/dl/parser.ts", "generate-datalog2-parser": "ts-node languageWorkbench/parserlib/gen/cli.ts languageWorkbench/languages/dl2/dl2.grammar languageWorkbench/languages/dl2/parser.ts ../../parserlib DL2 ws && prettier --write languageWorkbench/languages/dl2/parser.ts", From ed1afed3fe0a3885e12fba4ee16f045e159ebd8b Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 14:05:07 -0500 Subject: [PATCH 04/14] use dl2 for dl2 --- languageWorkbench/languages/dl2/{dl2.dl => dl2.dl2} | 0 languageWorkbench/languages/dl2/index.ts | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename languageWorkbench/languages/dl2/{dl2.dl => dl2.dl2} (100%) diff --git a/languageWorkbench/languages/dl2/dl2.dl b/languageWorkbench/languages/dl2/dl2.dl2 similarity index 100% rename from languageWorkbench/languages/dl2/dl2.dl rename to languageWorkbench/languages/dl2/dl2.dl2 diff --git a/languageWorkbench/languages/dl2/index.ts b/languageWorkbench/languages/dl2/index.ts index 715fac5af..83d4b14aa 100644 --- a/languageWorkbench/languages/dl2/index.ts +++ b/languageWorkbench/languages/dl2/index.ts @@ -1,6 +1,6 @@ -import { LanguageSpec, dl } from "../../common/types"; +import { LanguageSpec, dl2 } from "../../common/types"; // @ts-ignore -import datalog from "./dl2.dl"; +import datalog from "./dl2.dl2"; // @ts-ignore import grammar from "./dl2.grammar"; // @ts-ignore @@ -8,7 +8,7 @@ import example from "./example.txt"; export const datalog2: LanguageSpec = { name: "datalog2", - logic: dl(datalog), + logic: dl2(datalog), grammar, example, }; From 72fb185bdfec3f967dd9a50fd1531da93bdb0c6c Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 14:16:04 -0500 Subject: [PATCH 05/14] use the right language --- apps/languageWorkbench/main.tsx | 15 ++++++++++++--- languageWorkbench/common/types.ts | 4 ++-- languageWorkbench/interpCache.ts | 6 ++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/languageWorkbench/main.tsx b/apps/languageWorkbench/main.tsx index 15b269c77..8684a1902 100644 --- a/apps/languageWorkbench/main.tsx +++ b/apps/languageWorkbench/main.tsx @@ -9,7 +9,11 @@ import useHashParam from "use-hash-param"; import { ErrorList } from "../../uiCommon/ide/errorList"; import { addCursor } from "../../languageWorkbench/interpCache"; import { CollapsibleWithHeading } from "../../uiCommon/generic/collapsible"; -import { LanguageSpec, dl } from "../../languageWorkbench/common/types"; +import { + LanguageSpec, + dl as dl1, + dl2, +} from "../../languageWorkbench/common/types"; import { CACHE } from "../../languageWorkbench/vscode/common"; function Main() { @@ -26,7 +30,10 @@ function Workbench() { const curLangSpec: LanguageSpec = { name: versionedLangID, - logic: dl(curLangState.datalog.source), + logic: + curLangState.datalogVersion === "DL1" + ? dl1(curLangState.datalog.source) + : dl2(curLangState.datalog.source), example: curLangState.example.source, grammar: curLangState.grammar.source, }; @@ -152,13 +159,15 @@ type LangState = { example: EditorState; grammar: EditorState; datalog: EditorState; + datalogVersion: "DL1" | "DL2"; }; const emptyState: State = mapObj(LANGUAGES, (langID, spec) => ({ version: 1, example: { cursorPos: 1, source: spec.example }, grammar: { cursorPos: 1, source: spec.grammar }, - datalog: { cursorPos: 1, source: spec.logic.source }, // TODO: differentiate DL2 + datalog: { cursorPos: 1, source: spec.logic.source }, + datalogVersion: spec.logic.type, })); type Action = { type: "UpdateLang"; langID: string; action: LangAction }; diff --git a/languageWorkbench/common/types.ts b/languageWorkbench/common/types.ts index 77fe0495e..796c42134 100644 --- a/languageWorkbench/common/types.ts +++ b/languageWorkbench/common/types.ts @@ -12,11 +12,11 @@ export type LanguageSpec = { }; export type LogicSpec = - | { type: "DL"; source: string } + | { type: "DL1"; source: string } | { type: "DL2"; source: string }; export function dl(source: string): LogicSpec { - return { type: "DL", source }; + return { type: "DL1", source }; } export function dl2(source: string): LogicSpec { diff --git a/languageWorkbench/interpCache.ts b/languageWorkbench/interpCache.ts index 65e0d452f..3d34abee6 100644 --- a/languageWorkbench/interpCache.ts +++ b/languageWorkbench/interpCache.ts @@ -116,7 +116,7 @@ export class InterpCache { // add datalog try { switch (langSpec.logic.type) { - case "DL": { + case "DL1": { interp = interp.evalStr(langSpec.logic.source)[1]; break; } @@ -126,7 +126,9 @@ export class InterpCache { langSpec.logic.source ); // TODO: show in UI - console.error("DL2 extraction problems", problems); + if (problems.length > 0) { + console.error("DL2 extraction problems", problems); + } interp = newInterp; break; } From 8d04ef4fa0c9c31cef2503e934d5046369ee52ab Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 14:16:19 -0500 Subject: [PATCH 06/14] a first rule why is hl.mapping broken? --- languageWorkbench/languages/dl2/dl2.dl2 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/languageWorkbench/languages/dl2/dl2.dl2 b/languageWorkbench/languages/dl2/dl2.dl2 index 6a26d4e61..197aef78d 100644 --- a/languageWorkbench/languages/dl2/dl2.dl2 +++ b/languageWorkbench/languages/dl2/dl2.dl2 @@ -1,3 +1,16 @@ +def scope.Defn{scopeID: I, span: S, name: N, kind: K, type: "any"} { + scope.defnRule{scopeID: I, span: S, name: N, kind: K} +} + +def scope.defnRule{scopeID: RuleID, span: S, name: N, kind: "relation"} { + ast.rule{id: RuleID} & + ast.record{id: RecordID, parentID: RuleID} & + ast.qualifier{id: QualifierID, parentID: RecordID, text: N, span: S} +} + +// TODO: extract +table hl.mapping {} + hl.mapping{rule: "ident", type: "ident"}. hl.mapping{rule: "var", type: "typeParameter"}. hl.mapping{rule: "int", type: "number"}. From 01fc1192e97293bdba70e0a8bb52ff6f384a0e0c Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 14:23:15 -0500 Subject: [PATCH 07/14] first rule (support qualifiers in table decls for now) --- languageWorkbench/languages/dl2/dl2.dl2 | 1 - languageWorkbench/languages/dl2/dl2.grammar | 3 ++- languageWorkbench/languages/dl2/parser.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/languageWorkbench/languages/dl2/dl2.dl2 b/languageWorkbench/languages/dl2/dl2.dl2 index 197aef78d..8e1b9db2d 100644 --- a/languageWorkbench/languages/dl2/dl2.dl2 +++ b/languageWorkbench/languages/dl2/dl2.dl2 @@ -8,7 +8,6 @@ def scope.defnRule{scopeID: RuleID, span: S, name: N, kind: "relation"} { ast.qualifier{id: QualifierID, parentID: RecordID, text: N, span: S} } -// TODO: extract table hl.mapping {} hl.mapping{rule: "ident", type: "ident"}. diff --git a/languageWorkbench/languages/dl2/dl2.grammar b/languageWorkbench/languages/dl2/dl2.grammar index 7bf8be8fa..0a090673c 100644 --- a/languageWorkbench/languages/dl2/dl2.grammar +++ b/languageWorkbench/languages/dl2/dl2.grammar @@ -3,8 +3,9 @@ declaration :- (rule | tableDecl | import | fact). comment :- ["#", repSep(commentChar, "")]. import :- [importKW, ws, path]. +# TODO: probably shouldn't allow qualifiers here tableDecl :- [ - tableKW, ws, name:ident, ws, "{", ws, + tableKW, ws, name:qualifier, ws, "{", ws, repSep(tableAttr, commaSpace), ws, "}" ]. diff --git a/languageWorkbench/languages/dl2/parser.ts b/languageWorkbench/languages/dl2/parser.ts index 19438a8d0..b20a6b0bc 100644 --- a/languageWorkbench/languages/dl2/parser.ts +++ b/languageWorkbench/languages/dl2/parser.ts @@ -310,7 +310,7 @@ export type DL2TableDecl = { text: string; span: Span; tableKW: DL2TableKW; - name: DL2Ident; + name: DL2Qualifier; tableAttr: DL2TableAttr[]; commaSpace: DL2CommaSpace[]; }; @@ -1131,7 +1131,7 @@ function extractTableDecl(input: string, node: RuleTree): DL2TableDecl { text: textForSpan(input, node.span), span: node.span, tableKW: extractTableKW(input, childByName(node, "tableKW", null)), - name: extractIdent(input, childByName(node, "ident", "name")), + name: extractQualifier(input, childByName(node, "qualifier", "name")), tableAttr: childrenByName(node, "tableAttr").map((child) => extractTableAttr(input, child) ), @@ -1297,7 +1297,7 @@ const GRAMMAR: Grammar = { { type: "Ref", captureName: "name", - rule: "ident", + rule: "qualifier", }, { type: "Ref", From 0ca377fb68920f63cacb1e0421cd21d0b03da284 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 14:30:48 -0500 Subject: [PATCH 08/14] qualifiers in more places --- languageWorkbench/languages/dl2/compile.ts | 6 +++--- languageWorkbench/languages/dl2/dl2.grammar | 6 +++--- languageWorkbench/languages/dl2/parser.ts | 22 ++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/languageWorkbench/languages/dl2/compile.ts b/languageWorkbench/languages/dl2/compile.ts index 211b22f37..9c9eaec17 100644 --- a/languageWorkbench/languages/dl2/compile.ts +++ b/languageWorkbench/languages/dl2/compile.ts @@ -103,7 +103,7 @@ function extractNested( path: Path ): [Conjunct[], ExtractionProblem[]] { const relation = - path.length === 0 ? nested.ident.text : path[path.length - 1].relation; + path.length === 0 ? nested.qualifier.text : path[path.length - 1].relation; const curRec = rec(relation, {}); if (path.length > 0) { const last = path[path.length - 1]; @@ -127,14 +127,14 @@ function extractNested( case "NormalAttr": continue; case "Nested": { - const attrName = attr.ident.text; + const attrName = attr.qualifier.text; const refSpec = mod.tableDecls[relation].members[attrName]; if (!refSpec) { problems.push({ type: "MissingRefSpec", relation, name: attrName, - span: attr.ident.span, + span: attr.qualifier.span, }); continue; } diff --git a/languageWorkbench/languages/dl2/dl2.grammar b/languageWorkbench/languages/dl2/dl2.grammar index 0a090673c..4243d1a4b 100644 --- a/languageWorkbench/languages/dl2/dl2.grammar +++ b/languageWorkbench/languages/dl2/dl2.grammar @@ -11,8 +11,8 @@ tableDecl :- [ ]. tableAttr :- [ident, (refSpec | "")]. refSpec :- [":", ws, (outRef | inRef)]. -outRef :- ["outRef", "(", table:ident, ".", col:ident, ")"]. -inRef :- ["inRef", "(", table:ident, ".", col:ident, ")"]. +outRef :- ["outRef", "(", table:qualifier, ":", col:ident, ")"]. +inRef :- ["inRef", "(", table:qualifier, ":", col:ident, ")"]. inRefKW :- "inRef". outRefKW :- "outRef". @@ -34,7 +34,7 @@ aggregation :- [aggregation:ident, "[", repSep(var, commaSpace), ":", ws, record comparison :- [left:term, ws, comparisonOp, ws, right:term]. comparisonOp :- ("<=" | ">=" | ">" | "<" | "=" | "!="). -nested :- [ident, ws, "{", ws, repSep(nestedAttr, commaSpace), ws, "}"]. +nested :- [qualifier, ws, "{", ws, repSep(nestedAttr, commaSpace), ws, "}"]. nestedAttr :- (normalAttr | nested). normalAttr :- [ident, ":", ws, term]. diff --git a/languageWorkbench/languages/dl2/parser.ts b/languageWorkbench/languages/dl2/parser.ts index b20a6b0bc..8412e127f 100644 --- a/languageWorkbench/languages/dl2/parser.ts +++ b/languageWorkbench/languages/dl2/parser.ts @@ -157,7 +157,7 @@ export type DL2InRef = { type: "InRef"; text: string; span: Span; - table: DL2Ident; + table: DL2Qualifier; col: DL2Ident; }; export type DL2InRefKW = { @@ -188,7 +188,7 @@ export type DL2Nested = { type: "Nested"; text: string; span: Span; - ident: DL2Ident; + qualifier: DL2Qualifier; nestedAttr: DL2NestedAttr[]; commaSpace: DL2CommaSpace[]; }; @@ -209,7 +209,7 @@ export type DL2OutRef = { type: "OutRef"; text: string; span: Span; - table: DL2Ident; + table: DL2Qualifier; col: DL2Ident; }; export type DL2OutRefKW = { @@ -888,7 +888,7 @@ function extractInRef(input: string, node: RuleTree): DL2InRef { type: "InRef", text: textForSpan(input, node.span), span: node.span, - table: extractIdent(input, childByName(node, "ident", "table")), + table: extractQualifier(input, childByName(node, "qualifier", "table")), col: extractIdent(input, childByName(node, "ident", "col")), }; } @@ -931,7 +931,7 @@ function extractNested(input: string, node: RuleTree): DL2Nested { type: "Nested", text: textForSpan(input, node.span), span: node.span, - ident: extractIdent(input, childByName(node, "ident", null)), + qualifier: extractQualifier(input, childByName(node, "qualifier", null)), nestedAttr: childrenByName(node, "nestedAttr").map((child) => extractNestedAttr(input, child) ), @@ -972,7 +972,7 @@ function extractOutRef(input: string, node: RuleTree): DL2OutRef { type: "OutRef", text: textForSpan(input, node.span), span: node.span, - table: extractIdent(input, childByName(node, "ident", "table")), + table: extractQualifier(input, childByName(node, "qualifier", "table")), col: extractIdent(input, childByName(node, "ident", "col")), }; } @@ -1404,11 +1404,11 @@ const GRAMMAR: Grammar = { { type: "Ref", captureName: "table", - rule: "ident", + rule: "qualifier", }, { type: "Text", - value: ".", + value: ":", }, { type: "Ref", @@ -1435,11 +1435,11 @@ const GRAMMAR: Grammar = { { type: "Ref", captureName: "table", - rule: "ident", + rule: "qualifier", }, { type: "Text", - value: ".", + value: ":", }, { type: "Ref", @@ -1767,7 +1767,7 @@ const GRAMMAR: Grammar = { { type: "Ref", captureName: null, - rule: "ident", + rule: "qualifier", }, { type: "Ref", From 2fce1a64ebb45e432781c3a750beab2751f6973a Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 14:30:52 -0500 Subject: [PATCH 09/14] fixes! --- languageWorkbench/languages/dl2/dl2.dl2 | 21 ++++++++++++++++++--- languageWorkbench/languages/dl2/example.txt | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/languageWorkbench/languages/dl2/dl2.dl2 b/languageWorkbench/languages/dl2/dl2.dl2 index 8e1b9db2d..e7c091f9c 100644 --- a/languageWorkbench/languages/dl2/dl2.dl2 +++ b/languageWorkbench/languages/dl2/dl2.dl2 @@ -1,11 +1,26 @@ +table ast.rule { + id, + record: inRef(ast.record:parentID) +} +table ast.record { + parentID, + qualifier: inRef(ast.qualifier:parentID) +} + def scope.Defn{scopeID: I, span: S, name: N, kind: K, type: "any"} { scope.defnRule{scopeID: I, span: S, name: N, kind: K} } def scope.defnRule{scopeID: RuleID, span: S, name: N, kind: "relation"} { - ast.rule{id: RuleID} & - ast.record{id: RecordID, parentID: RuleID} & - ast.qualifier{id: QualifierID, parentID: RecordID, text: N, span: S} + ast.rule{ + id: RuleID, + record { + qualifier { + text: N, + span: S + } + } + } } table hl.mapping {} diff --git a/languageWorkbench/languages/dl2/example.txt b/languageWorkbench/languages/dl2/example.txt index ce72d86ec..485620389 100644 --- a/languageWorkbench/languages/dl2/example.txt +++ b/languageWorkbench/languages/dl2/example.txt @@ -2,7 +2,7 @@ import "ast" table constraint { id, - record: inRef(record.parentID) + record: inRef(record:parentID) } def varInComparison{scope: I, name: N, span: S} { From be7a6fda7d22537401318f68e02b1111a6f97e0f Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 14:34:52 -0500 Subject: [PATCH 10/14] add scope.defnTable --- languageWorkbench/languages/dl2/dl2.dl2 | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/languageWorkbench/languages/dl2/dl2.dl2 b/languageWorkbench/languages/dl2/dl2.dl2 index e7c091f9c..16d07bca2 100644 --- a/languageWorkbench/languages/dl2/dl2.dl2 +++ b/languageWorkbench/languages/dl2/dl2.dl2 @@ -1,19 +1,20 @@ table ast.rule { - id, record: inRef(ast.record:parentID) } table ast.record { - parentID, + qualifier: inRef(ast.qualifier:parentID) +} +table ast.tableDecl { qualifier: inRef(ast.qualifier:parentID) } def scope.Defn{scopeID: I, span: S, name: N, kind: K, type: "any"} { - scope.defnRule{scopeID: I, span: S, name: N, kind: K} + scope.defnRule{scopeID: I, span: S, name: N, kind: K} | + scope.defnTable{scopeID: I, span: S, name: N, kind: K} } -def scope.defnRule{scopeID: RuleID, span: S, name: N, kind: "relation"} { +def scope.defnRule{scopeID: global{}, span: S, name: N, kind: "relation"} { ast.rule{ - id: RuleID, record { qualifier { text: N, @@ -23,6 +24,15 @@ def scope.defnRule{scopeID: RuleID, span: S, name: N, kind: "relation"} { } } +def scope.defnTable{scopeID: global{}, span: S, name: N, kind: "relation"} { + ast.tableDecl{ + qualifier { + text: N, + span: S + } + } +} + table hl.mapping {} hl.mapping{rule: "ident", type: "ident"}. From dc5e6d17ec147102e17e2b6d58632f948de1c025 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 14:52:24 -0500 Subject: [PATCH 11/14] scope.defnAttr --- languageWorkbench/languages/dl2/dl2.dl2 | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/languageWorkbench/languages/dl2/dl2.dl2 b/languageWorkbench/languages/dl2/dl2.dl2 index 16d07bca2..69b8ca2c1 100644 --- a/languageWorkbench/languages/dl2/dl2.dl2 +++ b/languageWorkbench/languages/dl2/dl2.dl2 @@ -5,12 +5,17 @@ table ast.record { qualifier: inRef(ast.qualifier:parentID) } table ast.tableDecl { - qualifier: inRef(ast.qualifier:parentID) + qualifier: inRef(ast.qualifier:parentID), + attr: inRef(ast.tableAttr:parentID) +} +table ast.tableAttr { + ident: inRef(ast.ident:parentID) } def scope.Defn{scopeID: I, span: S, name: N, kind: K, type: "any"} { scope.defnRule{scopeID: I, span: S, name: N, kind: K} | - scope.defnTable{scopeID: I, span: S, name: N, kind: K} + scope.defnTable{scopeID: I, span: S, name: N, kind: K} | + scope.defnAttr{scopeID: I, span: S, name: N, kind: K} } def scope.defnRule{scopeID: global{}, span: S, name: N, kind: "relation"} { @@ -33,6 +38,20 @@ def scope.defnTable{scopeID: global{}, span: S, name: N, kind: "relation"} { } } +def scope.defnAttr{scopeID: I, span: S, name: N, kind: "attr"} { + ast.table { + qualifier { + text: I + }, + attr { + ident { + text: N, + span: S + } + } + } +} + table hl.mapping {} hl.mapping{rule: "ident", type: "ident"}. From b4b0c29427b2a62071921149357c317aff6340db Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 14:55:23 -0500 Subject: [PATCH 12/14] fix --- languageWorkbench/languages/dl2/dl2.dl2 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/languageWorkbench/languages/dl2/dl2.dl2 b/languageWorkbench/languages/dl2/dl2.dl2 index 69b8ca2c1..759e7e3c1 100644 --- a/languageWorkbench/languages/dl2/dl2.dl2 +++ b/languageWorkbench/languages/dl2/dl2.dl2 @@ -19,7 +19,7 @@ def scope.Defn{scopeID: I, span: S, name: N, kind: K, type: "any"} { } def scope.defnRule{scopeID: global{}, span: S, name: N, kind: "relation"} { - ast.rule{ + ast.rule { record { qualifier { text: N, @@ -30,7 +30,7 @@ def scope.defnRule{scopeID: global{}, span: S, name: N, kind: "relation"} { } def scope.defnTable{scopeID: global{}, span: S, name: N, kind: "relation"} { - ast.tableDecl{ + ast.tableDecl { qualifier { text: N, span: S @@ -39,7 +39,7 @@ def scope.defnTable{scopeID: global{}, span: S, name: N, kind: "relation"} { } def scope.defnAttr{scopeID: I, span: S, name: N, kind: "attr"} { - ast.table { + ast.tableDecl { qualifier { text: I }, From 7be6b61eadcd70fc28f9e57fcd78ea4c96e60567 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 20:06:35 -0500 Subject: [PATCH 13/14] fixes --- languageWorkbench/ddTests.ts | 18 +++++++----------- languageWorkbench/languages/dl2/compile.dd.txt | 4 ++-- languageWorkbench/languages/dl2/run.dd.txt | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/languageWorkbench/ddTests.ts b/languageWorkbench/ddTests.ts index dcd290695..fc0217670 100644 --- a/languageWorkbench/ddTests.ts +++ b/languageWorkbench/ddTests.ts @@ -9,7 +9,7 @@ import { import { datalogOut, plainTextOut } from "../util/ddTest/types"; import * as fs from "fs"; import { Suite } from "../util/testBench/testing"; -import { LanguageSpec, dl } from "./common/types"; +import { LanguageSpec, dl, dl2 } from "./common/types"; import { IncrementalInterpreter } from "../core/incremental/interpreter"; import { compile } from "./languages/dl2/compile"; import { extractModule } from "./languages/dl2/extract"; @@ -133,18 +133,14 @@ export function testLangQuery( const exampleWithCursor = lines.slice(1, lines.length - 1).join("\n"); const { input: example, cursorPos } = extractCursor(exampleWithCursor); const query = lines[lines.length - 1]; + + const basePath = `languageWorkbench/languages/${langName}/${langName}`; const langSpec: LanguageSpec = { name: langName, - logic: dl( - fs.readFileSync( - `languageWorkbench/languages/${langName}/${langName}.dl`, - "utf8" - ) - ), - grammar: fs.readFileSync( - `languageWorkbench/languages/${langName}/${langName}.grammar`, - "utf8" - ), + logic: fs.existsSync(`${basePath}.dl2`) + ? dl2(fs.readFileSync(`${basePath}.dl2`, "utf8")) + : dl(fs.readFileSync(`${basePath}.dl`, "utf8")), + grammar: fs.readFileSync(`${basePath}.grammar`, "utf8"), example: "", }; const { interp: withoutCursor } = cache.getInterpForDoc( diff --git a/languageWorkbench/languages/dl2/compile.dd.txt b/languageWorkbench/languages/dl2/compile.dd.txt index 4e4781c50..9b47c6f6a 100644 --- a/languageWorkbench/languages/dl2/compile.dd.txt +++ b/languageWorkbench/languages/dl2/compile.dd.txt @@ -1,6 +1,6 @@ table post { author_id, - comment: inRef(comment.post_id) + comment: inRef(comment:post_id) } table comment { author_id, @@ -20,7 +20,7 @@ postComment{commentID: C, postID: P} :- post{id: P} & comment{id: C, post_id: P} table post { author_id, - comment: inRef(comment.post_id) + comment: inRef(comment:post_id) } table comment { author_id, diff --git a/languageWorkbench/languages/dl2/run.dd.txt b/languageWorkbench/languages/dl2/run.dd.txt index 4e46dfdd5..b63375955 100644 --- a/languageWorkbench/languages/dl2/run.dd.txt +++ b/languageWorkbench/languages/dl2/run.dd.txt @@ -1,6 +1,6 @@ table post { author_id, - comment: inRef(comment.post_id) + comment: inRef(comment:post_id) } table comment { author_id, From a56037fedb2e60ebad97b96f7a625d0730e40ecd Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 8 Jan 2024 20:11:01 -0500 Subject: [PATCH 14/14] fix benchmarks --- languageWorkbench/benchmarks.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/languageWorkbench/benchmarks.ts b/languageWorkbench/benchmarks.ts index ddf4cc770..c89d8ae11 100644 --- a/languageWorkbench/benchmarks.ts +++ b/languageWorkbench/benchmarks.ts @@ -14,7 +14,7 @@ import { InterpCache, addCursor } from "./interpCache"; import { AbstractInterpreter } from "../core/abstractInterpreter"; import * as fs from "fs"; import { assertDeepEqual } from "../util/testBench/testing"; -import { LanguageSpec } from "./common/types"; +import { LanguageSpec, dl } from "./common/types"; import { SimpleInterpreter } from "../core/simple/interpreter"; import { fsLoader } from "../core/fsLoader"; import { IncrementalInterpreter } from "../core/incremental/interpreter"; @@ -229,7 +229,7 @@ const flattenedByRule = flattenByRule(ruleTree, input, LEAVES); const langSpec: LanguageSpec = { name: "datalog", - logic: fs.readFileSync(`languageWorkbench/languages/dl/dl.dl`, "utf8"), + logic: dl(fs.readFileSync(`languageWorkbench/languages/dl/dl.dl`, "utf8")), grammar: fs.readFileSync(`languageWorkbench/languages/dl/dl.grammar`, "utf8"), example: "", };