Skip to content

Commit 890f02a

Browse files
committed
rm old keyword logic
1 parent 0375cac commit 890f02a

File tree

4 files changed

+0
-254
lines changed

4 files changed

+0
-254
lines changed

packages/transpiler/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as abaplint from "@abaplint/core";
22
import {Validation, config} from "./validation";
33
import {UnitTest} from "./unit_test";
4-
import {Keywords} from "./keywords";
54
import {IFile, IOutput, IProgress, ITranspilerOptions, IOutputFile, UnknownTypesEnum} from "./types";
65
import {DatabaseSetup} from "./db";
76
import {HandleTable} from "./handlers/handle_table";
@@ -42,7 +41,6 @@ export class Transpiler {
4241
public async run(reg: abaplint.IRegistry, progress?: IProgress): Promise<IOutput> {
4342

4443
reg.parse();
45-
new Keywords(this.options?.keywords).handle(reg);
4644
this.validate(reg);
4745

4846
const dbSetup = new DatabaseSetup(reg).run(this.options);

packages/transpiler/src/keywords.ts

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as abaplint from "@abaplint/core";
2-
31
// https://www.w3schools.com/js/js_reserved.asp
42
export const DEFAULT_KEYWORDS: string[] = [
53
"abstract", "arguments", "await",
@@ -21,99 +19,3 @@ export const DEFAULT_KEYWORDS: string[] = [
2119
"delete",
2220
"volatile", "while", "yield"];
2321
// "with"
24-
25-
/** Replaces javascript keywords in ABAP source code, in-memory only */
26-
export class Keywords {
27-
private readonly keywords: string[] = [];
28-
29-
public constructor(keywords?: string[]) {
30-
if (keywords !== undefined) {
31-
this.keywords = keywords;
32-
} else {
33-
this.keywords = DEFAULT_KEYWORDS;
34-
}
35-
}
36-
37-
public handle(reg: abaplint.IRegistry) {
38-
if (this.keywords.length === 0) {
39-
return;
40-
}
41-
reg.parse();
42-
43-
for (const o of reg.getObjects()) {
44-
if (!(o instanceof abaplint.ABAPObject)) {
45-
continue;
46-
}
47-
for (const f of o.getABAPFiles()) {
48-
const tokens: abaplint.Token[] = [];
49-
for (const s of f.getStatements()) {
50-
if (s.get() instanceof abaplint.MacroCall) {
51-
tokens.push(...this.handleMacro(s));
52-
} else {
53-
tokens.push(...this.traverse(s, f));
54-
}
55-
}
56-
if (tokens.length === 0) {
57-
continue;
58-
}
59-
const rows = f.getRawRows();
60-
for (const t of tokens.reverse()) {
61-
const original = rows[t.getRow() - 1];
62-
const index = t.getEnd().getCol() - 1;
63-
rows[t.getRow() - 1] = original.substring(0, index) + "_" + original.substring(index);
64-
}
65-
reg.updateFile(new abaplint.MemoryFile(f.getFilename(), rows.join("\n")));
66-
}
67-
}
68-
69-
reg.parse();
70-
}
71-
72-
private handleMacro(node: abaplint.Nodes.StatementNode): abaplint.Token[] {
73-
const tokens: abaplint.Token[] = [];
74-
75-
for (const token of node.getTokens()) {
76-
for (const k of this.keywords) {
77-
const lower = token.getStr().toLowerCase();
78-
if (k === lower
79-
|| "!" + k === lower
80-
|| lower.endsWith("~" + k)) {
81-
tokens.push(token);
82-
}
83-
}
84-
}
85-
86-
return tokens;
87-
}
88-
89-
private traverse(node: abaplint.INode, file: abaplint.ABAPFile): abaplint.Token[] {
90-
91-
const ret: abaplint.Token[] = [];
92-
for (const c of node.getChildren()) {
93-
if (c instanceof abaplint.Nodes.TokenNodeRegex) {
94-
const token = c.getFirstToken();
95-
96-
const start = token.getStart();
97-
if (start instanceof abaplint.VirtualPosition) {
98-
continue;
99-
}
100-
for (const k of this.keywords) {
101-
const lower = token.getStr().toLowerCase();
102-
if (k === lower
103-
|| "!" + k === lower
104-
|| lower.endsWith("~" + k)) {
105-
ret.push(token);
106-
break;
107-
}
108-
}
109-
} else if (c instanceof abaplint.Nodes.TokenNode) {
110-
continue;
111-
} else {
112-
ret.push(...this.traverse(c, file));
113-
}
114-
}
115-
116-
return ret;
117-
}
118-
119-
}

packages/transpiler/src/validation.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import {Issue, IRegistry, Config, IConfig, Version} from "@abaplint/core";
2-
import {DEFAULT_KEYWORDS} from "./keywords";
32
import {ITranspilerOptions, UnknownTypesEnum} from "./types";
43

54
export const config: IConfig = {
65
"global": {
76
"files": "/**/*.*",
8-
"skipGeneratedGatewayClasses": true,
9-
"skipGeneratedPersistentClasses": true,
10-
"skipGeneratedFunctionGroups": true,
117
},
128
"syntax": {
139
"version": Version.OpenABAP,
@@ -124,17 +120,6 @@ export class Validation {
124120
}
125121

126122
config.rules["forbidden_identifier"]["check"] = ["^unique\\d+$"];
127-
if (this.options?.keywords === undefined) {
128-
for (const d of DEFAULT_KEYWORDS) {
129-
const add = "^" + d + "$";
130-
config.rules["forbidden_identifier"]["check"].push(add);
131-
}
132-
} else {
133-
for (const d of this.options.keywords) {
134-
const add = "^" + d + "$";
135-
config.rules["forbidden_identifier"]["check"].push(add);
136-
}
137-
}
138123

139124
if (this.options?.unknownTypes === UnknownTypesEnum.runtimeError) {
140125
// this is not a constant, just a regex that happens to not match anything

test/keywords.ts

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)