Skip to content

Commit d29f6a0

Browse files
authored
Merge pull request #1 from halcyon-tech/fix/improvedKeywordParser
Fix/improved keyword parser
2 parents 82af74a + 32213ce commit d29f6a0

File tree

8 files changed

+306
-66
lines changed

8 files changed

+306
-66
lines changed

.vscode/launch.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66
"version": "0.2.0",
77
"configurations": [
88
{
9-
"name": "Run Extension",
10-
"type": "extensionHost",
9+
"name": "Launch Tests",
10+
"program": "${workspaceFolder}/test/index.js",
1111
"request": "launch",
12-
"args": [
13-
"--extensionDevelopmentPath=${workspaceFolder}"
14-
]
12+
"skipFiles": [
13+
"<node_internals>/**"
14+
],
15+
"type": "node"
1516
},
1617
{
17-
"name": "Extension Tests",
18+
"name": "Run Extension",
1819
"type": "extensionHost",
1920
"request": "launch",
2021
"args": [
21-
"--extensionDevelopmentPath=${workspaceFolder}",
22-
"--extensionTestsPath=${workspaceFolder}/test/suite/index"
22+
"--extensionDevelopmentPath=${workspaceFolder}"
2323
]
24-
}
24+
},
25+
2526
]
2627
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
],
5757
"scripts": {
5858
"lint": "eslint .",
59-
"pretest": "npm run lint",
60-
"test": "node ./test/runTest.js",
59+
"test": "node ./test",
6160
"package": "vsce package"
6261
},
6362
"devDependencies": {

src/dspf.js

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DisplayFile {
3535
inout = line[37].toUpperCase();
3636
y = line.substring(38, 41).trim();
3737
x = line.substring(41, 44).trim();
38-
keywords = line.substring(44).trim();
38+
keywords = line.substring(44).trimEnd();
3939

4040
switch (line[16]) {
4141
case 'R':
@@ -256,41 +256,9 @@ class DisplayFile {
256256
conditions: []
257257
};
258258

259-
let inString = false;
260-
let value = ``;
261-
262-
keywordStrings.forEach(keywordString => {
263-
if (keywordString.startsWith(`'`)) {
264-
inString = true;
265-
keywordString = keywordString.substring(1);
266-
267-
if (keywordString.endsWith(`'`) || keywordString.endsWith(`-`)) {
268-
keywordString = keywordString.substring(0, keywordString.length - 1);
269-
}
270-
271-
result.value = keywordString;
272-
value += `!`;
273-
return;
274-
}
275-
276-
if (keywordString.endsWith('-')) {
277-
if (inString)
278-
result.value += keywordString.substring(0, keywordString.length - 1);
279-
else
280-
value += keywordString.substring(0, keywordString.length - 1);
281-
} else
282-
if (keywordString.endsWith(`'`)) {
283-
if (inString) {
284-
result.value += keywordString.substring(0, keywordString.length - 1);
285-
inString = false;
286-
}
287-
} else {
288-
value += keywordString + ` `;
289-
}
290-
291-
value += `!`;
292-
});
259+
const newLineMark = `~`;
293260

261+
let value = keywordStrings.join(newLineMark) + newLineMark;
294262
let conditionalLine = 1;
295263

296264
if (value.length > 0) {
@@ -299,25 +267,45 @@ class DisplayFile {
299267
let inBrakcets = 0;
300268
let word = ``;
301269
let innerValue = ``;
270+
let inString = false;
302271

303272
for (let i = 0; i < value.length; i++) {
304273
switch (value[i]) {
305-
case `!`:
274+
case `+`:
275+
case `-`:
276+
if (!inString) {
277+
innerValue += value[i];
278+
}
279+
break;
280+
281+
case `'`:
306282
if (inBrakcets > 0) {
307283
innerValue += value[i];
308284
} else {
309-
conditionalLine += 1;
285+
if (inString) {
286+
inString = false;
287+
288+
result.value = innerValue;
289+
innerValue = ``;
290+
} else {
291+
inString = true;
292+
}
310293
}
311294
break;
295+
312296
case `(`:
313297
inBrakcets++;
314298
break;
315299
case `)`:
316300
inBrakcets--;
317301
break;
302+
303+
case newLineMark:
318304
case ` `:
319-
if (inBrakcets > 0) {
320-
innerValue += value[i];
305+
if (inBrakcets > 0 || inString) {
306+
if (value[i] !== newLineMark) {
307+
innerValue += value[i];
308+
}
321309
} else {
322310
if (word.length > 0) {
323311
let conditionals = conditionalStrings ? conditionalStrings[conditionalLine] : undefined;
@@ -332,9 +320,11 @@ class DisplayFile {
332320
innerValue = ``;
333321
}
334322
}
323+
324+
if (value[i] === newLineMark) conditionalLine += 1;
335325
break;
336326
default:
337-
if (inBrakcets > 0)
327+
if (inBrakcets > 0 || inString)
338328
innerValue += value[i];
339329
else
340330
word += value[i];

src/lensProvider.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,20 @@ module.exports = class lensProvider {
2929
line = line.padEnd(30);
3030
// Not a comment
3131
if (line[6] !== `*`) {
32-
if (line[5].toUpperCase() === `A`) {
33-
// Is a record format definition
34-
if (line[16].toUpperCase() === `R`) {
35-
const name = line.substring(18, 28).trim();
32+
// Is a record format definition
33+
if (line[16].toUpperCase() === `R`) {
34+
const name = line.substring(18, 28).trim();
3635

37-
codeLens.push(new vscode.CodeLens(
38-
new vscode.Range(
39-
index, 0, index, 0
40-
),
41-
{
42-
command: `vscode-displayfile.render`,
43-
title: `Preview ${name}`,
44-
arguments: [lines, name, document.languageId]
45-
}
46-
));
47-
}
36+
codeLens.push(new vscode.CodeLens(
37+
new vscode.Range(
38+
index, 0, index, 0
39+
),
40+
{
41+
command: `vscode-displayfile.render`,
42+
title: `Preview ${name}`,
43+
arguments: [lines, name, document.languageId]
44+
}
45+
));
4846
}
4947
}
5048
});

test/file/depts.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
exports.lines = [
2+
` A INDARA`,
3+
` A CA03(03)`,
4+
` A R SFLDTA SFL`,
5+
` A RRN 4Y 0H`,
6+
` A* DISPLAY DTA`,
7+
` A XSEL 1A B 7 8`,
8+
` A XID 3A O 7 12`,
9+
` A XNAME 38A O 7 16`,
10+
` A* COLOR HELLO`,
11+
` A R SFLCTL SFLCTL(SFLDTA)`,
12+
` A SFLPAG(0014)`,
13+
` A SFLSIZ(9999)`,
14+
` A OVERLAY`,
15+
` A 85 SFLDSPCTL`,
16+
` A 95 SFLDSP`,
17+
` A N85 SFLCLR`,
18+
` A SFLRRN 4S 0H SFLRCDNBR(CURSOR)`,
19+
` A*`,
20+
` A 6 6'Opt'`,
21+
` A DSPATR(HI)`,
22+
` A DSPATR(UL)`,
23+
` A 6 12'ID'`,
24+
` A DSPATR(HI)`,
25+
` A DSPATR(UL)`,
26+
` A 6 16'Name'`,
27+
` A DSPATR(UL)`,
28+
` A COLOR(WHT)`,
29+
` A R FOOTER_FMT`,
30+
` A OVERLAY`,
31+
` A 3 6'F3=Exit'`,
32+
` A COLOR(BLU)`,
33+
` A 2 35'Departments'`,
34+
` A DSPATR(UL)`,
35+
` A COLOR(WHT)`,
36+
` A 4 6'5=View' COLOR(BLU)`,
37+
];

test/file/replloadfm.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// https://github.com/tom-writes-code/rpgle-repl
2+
3+
exports.lines = [
4+
` DSPSIZ(27 132 *DS4)`,
5+
` INDARA`,
6+
``,
7+
` R HEADER`,
8+
` 1 2'repl:load snippets'`,
9+
` COLOR(BLU)`,
10+
``,
11+
` 2 2'1=Load 4=Delete'`,
12+
` COLOR(WHT)`,
13+
``,
14+
` H_MODE 16A O 2 84`,
15+
` 50 COLOR(WHT)`,
16+
` N50 COLOR(RED)`,
17+
` 2102'filter by profile:'`,
18+
` COLOR(WHT)`,
19+
` H_FILTER 10A B 2122`,
20+
` COLOR(WHT)`,
21+
``,
22+
` R SNIPPET SFL`,
23+
` CHGINPDFT(LC)`,
24+
` S_SELECT 1A B 3 2COLOR(WHT)`,
25+
` DSPATR(UL)`,
26+
` 99 DSPATR(RI)`,
27+
` 99 DSPATR(PC)`,
28+
` S_ORIGIN 30A O 3 4COLOR(BLU)`,
29+
` S_LASTCHG 10A O 3 35COLOR(BLU)`,
30+
` S_PREVIEW 85A O 3 46COLOR(GRN)`,
31+
` S_OWNER 10A H`,
32+
` S_SAVENAME 20A H`,
33+
` S_SESSION 28A H`,
34+
``,
35+
` R SNIPPETS SFLCTL(SNIPPET)`,
36+
` SFLSIZ(23)`,
37+
` SFLPAG(22)`,
38+
` TEXT('Snippets Control Format')`,
39+
` CF03(03 'Exit')`,
40+
` CF11(11 'Saved/Unsaved')`,
41+
` OVERLAY`,
42+
` 40 SFLDSP`,
43+
` 41 SFLDSPCTL`,
44+
` 42 SFLCLR`,
45+
` 43 SFLEND(*MORE)`,
46+
``,
47+
` R NORECORDS`,
48+
` OVERLAY`,
49+
` 4 5'no snippets found for the current -`,
50+
` search criteria'`,
51+
``,
52+
` R FKEYS`,
53+
` FRCDTA`,
54+
` OVERLAY`,
55+
` MSGLIN 129A O 27 2DSPATR(HI)`,
56+
``,
57+
` 26 2'F3=Exit F11=Saved/Unsaved Snippet-`,
58+
` s'`,
59+
` COLOR(BLU)`,
60+
``,
61+
` R CONFIRM`,
62+
` OVERLAY`,
63+
` WINDOW(6 6 6 54)`,
64+
` CF10(10 'Confirm')`,
65+
` CF12(12 'Cancel')`,
66+
``,
67+
``,
68+
` CNFTXT1 50A O 2 3COLOR(WHT)`,
69+
` CNFTXT2 50A O 3 3COLOR(WHT)`,
70+
``,
71+
` 5 3'F10=Confirm -`,
72+
` F12=Cancel'`,
73+
` COLOR(BLU)`,
74+
]

test/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const cases = require("./tests");
2+
3+
Object.values(cases).forEach(testcase => testcase());

0 commit comments

Comments
 (0)