Fixed node comparison bug

This commit is contained in:
Rolf Martin Glomsrud 2024-06-02 00:19:44 +02:00
parent ecf79c4462
commit 68b95e1cfd
8 changed files with 32 additions and 27 deletions

3
.gitignore vendored
View file

@ -1,5 +1,4 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore # Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
# Logs # Logs
logs logs
@ -167,3 +166,5 @@ dist
.yarn/build-state.yml .yarn/build-state.yml
.yarn/install-state.gz .yarn/install-state.gz
.pnp.\* .pnp.\*
output_testing/

View file

@ -18,26 +18,26 @@ export function registerValidationChecks(services: JstqlServices) {
* Implementation of custom validations. * Implementation of custom validations.
*/ */
export class JstqlValidator { export class JstqlValidator {
validateWildcards(pair: Case, accept: ValidationAcceptor): void { validateWildcards(case_: Case, accept: ValidationAcceptor): void {
try { try {
let validationResultAplTo = validateWildcardAplTo( let validationResultAplTo = validateWildcardAplTo(
collectWildcard(pair.aplTo.apl_to_code.split("")) collectWildcard(case_.aplTo.apl_to_code.split(""))
); );
if (validationResultAplTo.errors.length != 0) { if (validationResultAplTo.errors.length != 0) {
accept("error", validationResultAplTo.errors.join("\n"), { accept("error", validationResultAplTo.errors.join("\n"), {
node: pair.aplTo, node: case_.aplTo,
property: "apl_to_code", property: "apl_to_code",
}); });
} }
let validationResultTraTo = validateWildcardTraTo( let validationResultTraTo = validateWildcardTraTo(
collectWildcard(pair.traTo.transform_to_code.split("")), collectWildcard(case_.traTo.transform_to_code.split("")),
validationResultAplTo.env validationResultAplTo.env
); );
if (validationResultTraTo.length != 0) { if (validationResultTraTo.length != 0) {
accept("error", validationResultTraTo.join("\n"), { accept("error", validationResultTraTo.join("\n"), {
node: pair.traTo, node: case_.traTo,
property: "transform_to_code", property: "transform_to_code",
}); });
} }

View file

@ -1,11 +1,10 @@
proposal DoExpression{ proposal DoExpression{
case arrowFunction{ case arrowFunction{
applicable to { applicable to {
"() => { "(() => {
<<statements: (Statement && !ReturnStatement)+>> <<statements: (Statement && !ReturnStatement)+>>
return <<returnVal : Expression>>; return <<returnVal : Expression>>;
} })();"
"
} }
transform to { transform to {
"(do { "(do {

View file

@ -3,7 +3,7 @@ import { readdir } from "node:fs/promises";
import { parseJSTQL } from "./langium/langiumRunner"; import { parseJSTQL } from "./langium/langiumRunner";
const main = async () => { const main = async () => {
let basepathExamplesJSFiles = "../atom"; let basepathExamplesJSFiles = "../next.js";
let examples = (await readdir(basepathExamplesJSFiles, { recursive: true })) let examples = (await readdir(basepathExamplesJSFiles, { recursive: true }))
.filter((x) => x.endsWith(".js")) .filter((x) => x.endsWith(".js"))
.map((x) => basepathExamplesJSFiles + "/" + x); .map((x) => basepathExamplesJSFiles + "/" + x);

View file

@ -201,9 +201,18 @@ export class Matcher {
} }
} }
return codeNode.type === aplToNode.type for (let [key, val] of Object.entries(aplToNode)) {
? MatchResult.Matched if (keys_to_ignore.includes(key)) {
: MatchResult.NoMatch; continue;
}
if (typeof val !== "object") {
if (codeNode[key] !== val) {
return MatchResult.NoMatch;
}
}
}
return MatchResult.Matched;
} }
multiStatementMatcher(code: TreeNode<t.Node>, aplTo: TreeNode<t.Node>) { multiStatementMatcher(code: TreeNode<t.Node>, aplTo: TreeNode<t.Node>) {

View file

@ -19,13 +19,13 @@ function extractValues(types: t.Statement[]): Wildcard[] {
if (init) { if (init) {
if (init.type == "StringLiteral") { if (init.type == "StringLiteral") {
init = <t.StringLiteral>init; init = <t.StringLiteral>init;
prelude.push( let wildcard = new WildcardParser(
new WildcardParser( new WildcardTokenizer(
new WildcardTokenizer( innerDSLVariableName + ":" + init
innerDSLVariableName + ":" + init ).tokenize()
).tokenize() ).parse();
).parse()
); prelude.push(wildcard);
} else { } else {
throw new Error( throw new Error(
"Invalid usage of right side declaration in prelude" "Invalid usage of right side declaration in prelude"

View file

@ -54,10 +54,8 @@ export function transform(
let { cleanedJS: applicableTo, prelude } = parseInternalAplTo( let { cleanedJS: applicableTo, prelude } = parseInternalAplTo(
recipe.applicableTo recipe.applicableTo
); );
console.log(applicableTo);
let transformTo = parseInternalTraTo(recipe.transformTo); let transformTo = parseInternalTraTo(recipe.transformTo);
console.log(transformTo);
console.log(prelude);
let temp = transformSelfHosted( let temp = transformSelfHosted(
{ applicableTo, transformTo }, { applicableTo, transformTo },
prelude, prelude,
@ -93,10 +91,8 @@ function transformSelfHosted(
throw new Error("This no worky LOL"); throw new Error("This no worky LOL");
} }
let matches = runMatch(codeTree, applicableToTree, internals); let matches = runMatch(codeTree, applicableToTree, internals);
//showTreePaired(matches[0].statements[0]);
let outputAST = transformer(matches, transformToTree, codeAST, transformTo); let outputAST = transformer(matches, transformToTree, codeAST, transformTo);
//console.log("Finished transforming");
return [outputAST, matches.length]; return [outputAST, matches.length];
} }

View file

@ -1,9 +1,9 @@
let aaaa = () => { let aaaa = (() => {
let g = 100; let g = 100;
let ff = 10; let ff = 10;
let ggg = a(b); let ggg = a(b);
return 100; return 100;
}; })();
var bbaaa = (function () { var bbaaa = (function () {
let lllll = 1 + 1; let lllll = 1 + 1;