Skip to content

Commit

Permalink
2.10.15: rm old keyword logic (#1463)
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp authored Sep 6, 2024
1 parent 0375cac commit bfbc3eb
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 213 deletions.
18 changes: 9 additions & 9 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abaplint/transpiler-cli",
"version": "2.10.14",
"version": "2.10.15",
"description": "Transpiler - Command Line Interface",
"funding": "https://github.com/sponsors/larshp",
"bin": {
Expand All @@ -26,7 +26,7 @@
"author": "abaplint",
"license": "MIT",
"devDependencies": {
"@abaplint/transpiler": "^2.10.14",
"@abaplint/transpiler": "^2.10.15",
"@types/glob": "^8.1.0",
"glob": "=7.2.0",
"@types/progress": "^2.0.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abaplint/runtime",
"version": "2.10.14",
"version": "2.10.15",
"description": "Transpiler - Runtime",
"main": "build/src/index.js",
"typings": "build/src/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/transpiler/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/transpiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@abaplint/transpiler",
"version": "2.10.14",
"version": "2.10.15",
"description": "Transpiler",
"main": "build/src/index.js",
"typings": "build/src/index.d.ts",
Expand Down
2 changes: 0 additions & 2 deletions packages/transpiler/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as abaplint from "@abaplint/core";
import {Validation, config} from "./validation";
import {UnitTest} from "./unit_test";
import {Keywords} from "./keywords";
import {IFile, IOutput, IProgress, ITranspilerOptions, IOutputFile, UnknownTypesEnum} from "./types";
import {DatabaseSetup} from "./db";
import {HandleTable} from "./handlers/handle_table";
Expand Down Expand Up @@ -42,7 +41,6 @@ export class Transpiler {
public async run(reg: abaplint.IRegistry, progress?: IProgress): Promise<IOutput> {

reg.parse();
new Keywords(this.options?.keywords).handle(reg);
this.validate(reg);

const dbSetup = new DatabaseSetup(reg).run(this.options);
Expand Down
98 changes: 0 additions & 98 deletions packages/transpiler/src/keywords.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as abaplint from "@abaplint/core";

// https://www.w3schools.com/js/js_reserved.asp
export const DEFAULT_KEYWORDS: string[] = [
"abstract", "arguments", "await",
Expand All @@ -21,99 +19,3 @@ export const DEFAULT_KEYWORDS: string[] = [
"delete",
"volatile", "while", "yield"];
// "with"

/** Replaces javascript keywords in ABAP source code, in-memory only */
export class Keywords {
private readonly keywords: string[] = [];

public constructor(keywords?: string[]) {
if (keywords !== undefined) {
this.keywords = keywords;
} else {
this.keywords = DEFAULT_KEYWORDS;
}
}

public handle(reg: abaplint.IRegistry) {
if (this.keywords.length === 0) {
return;
}
reg.parse();

for (const o of reg.getObjects()) {
if (!(o instanceof abaplint.ABAPObject)) {
continue;
}
for (const f of o.getABAPFiles()) {
const tokens: abaplint.Token[] = [];
for (const s of f.getStatements()) {
if (s.get() instanceof abaplint.MacroCall) {
tokens.push(...this.handleMacro(s));
} else {
tokens.push(...this.traverse(s, f));
}
}
if (tokens.length === 0) {
continue;
}
const rows = f.getRawRows();
for (const t of tokens.reverse()) {
const original = rows[t.getRow() - 1];
const index = t.getEnd().getCol() - 1;
rows[t.getRow() - 1] = original.substring(0, index) + "_" + original.substring(index);
}
reg.updateFile(new abaplint.MemoryFile(f.getFilename(), rows.join("\n")));
}
}

reg.parse();
}

private handleMacro(node: abaplint.Nodes.StatementNode): abaplint.Token[] {
const tokens: abaplint.Token[] = [];

for (const token of node.getTokens()) {
for (const k of this.keywords) {
const lower = token.getStr().toLowerCase();
if (k === lower
|| "!" + k === lower
|| lower.endsWith("~" + k)) {
tokens.push(token);
}
}
}

return tokens;
}

private traverse(node: abaplint.INode, file: abaplint.ABAPFile): abaplint.Token[] {

const ret: abaplint.Token[] = [];
for (const c of node.getChildren()) {
if (c instanceof abaplint.Nodes.TokenNodeRegex) {
const token = c.getFirstToken();

const start = token.getStart();
if (start instanceof abaplint.VirtualPosition) {
continue;
}
for (const k of this.keywords) {
const lower = token.getStr().toLowerCase();
if (k === lower
|| "!" + k === lower
|| lower.endsWith("~" + k)) {
ret.push(token);
break;
}
}
} else if (c instanceof abaplint.Nodes.TokenNode) {
continue;
} else {
ret.push(...this.traverse(c, file));
}
}

return ret;
}

}
2 changes: 1 addition & 1 deletion packages/transpiler/src/statements/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class DataTranspiler implements IStatementTranspiler {
if (found.getValue() !== undefined && node.concatTokens().includes(" & ")) {
value = "\n" + traversal.setValues(found, found.getName());
} else {
value = DataTranspiler.buildValue(node, found.getName().toLowerCase(), traversal);
value = DataTranspiler.buildValue(node, Traversal.prefixVariable(found.getName().toLowerCase()), traversal);
}

const ret = new Chunk()
Expand Down
2 changes: 1 addition & 1 deletion packages/transpiler/src/traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ export class Traversal {
}
};

handle(val, name);
handle(val, Traversal.prefixVariable(name));

return ret;
}
Expand Down
15 changes: 0 additions & 15 deletions packages/transpiler/src/validation.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import {Issue, IRegistry, Config, IConfig, Version} from "@abaplint/core";
import {DEFAULT_KEYWORDS} from "./keywords";
import {ITranspilerOptions, UnknownTypesEnum} from "./types";

export const config: IConfig = {
"global": {
"files": "/**/*.*",
"skipGeneratedGatewayClasses": true,
"skipGeneratedPersistentClasses": true,
"skipGeneratedFunctionGroups": true,
},
"syntax": {
"version": Version.OpenABAP,
Expand Down Expand Up @@ -124,17 +120,6 @@ export class Validation {
}

config.rules["forbidden_identifier"]["check"] = ["^unique\\d+$"];
if (this.options?.keywords === undefined) {
for (const d of DEFAULT_KEYWORDS) {
const add = "^" + d + "$";
config.rules["forbidden_identifier"]["check"].push(add);
}
} else {
for (const d of this.options.keywords) {
const add = "^" + d + "$";
config.rules["forbidden_identifier"]["check"].push(add);
}
}

if (this.options?.unknownTypes === UnknownTypesEnum.runtimeError) {
// this is not a constant, just a regex that happens to not match anything
Expand Down
79 changes: 0 additions & 79 deletions packages/transpiler/test/keywords.ts

This file was deleted.

0 comments on commit bfbc3eb

Please sign in to comment.