Skip to content

Commit c6e94fe

Browse files
authored
Merge pull request #280 from codefori/fix/278_parser_fix
Parser fixed for includes and undefined handling
2 parents 00a3713 + 0e1b7e1 commit c6e94fe

File tree

2 files changed

+103
-6
lines changed

2 files changed

+103
-6
lines changed

language/parser.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,26 @@ export default class Parser {
142142
directiveLength = 9
143143
};
144144

145+
/** @type {string|undefined} */
146+
let directiveValue;
147+
145148
if (directivePosition >= 0) {
146149
if (comment >= 0) {
147-
return line.substring(directivePosition+directiveLength, comment).trim();
150+
directiveValue = line.substring(directivePosition+directiveLength, comment).trim();
148151
} else {
149-
return line.substring(directivePosition+directiveLength).trim();
152+
directiveValue = line.substring(directivePosition+directiveLength).trim();
150153
}
151154
}
155+
156+
if (directiveValue) {
157+
const spaceIndex = directiveValue.indexOf(` `);
158+
if (spaceIndex >= 0) {
159+
directiveValue = directiveValue.substring(0, spaceIndex);
160+
}
161+
162+
return directiveValue;
163+
}
164+
152165
}
153166

154167
/**
@@ -1032,10 +1045,12 @@ export default class Parser {
10321045
scope.files.push(currentItem);
10331046
} else {
10341047
currentItem = scope.files[scope.files.length-1];
1035-
currentItem.keywords = [
1036-
...(currentItem.keywords ? currentItem.keywords : []),
1037-
...fSpec.keywords
1038-
]
1048+
if (currentItem) {
1049+
currentItem.keywords = [
1050+
...(currentItem.keywords ? currentItem.keywords : []),
1051+
...fSpec.keywords
1052+
]
1053+
}
10391054
}
10401055

10411056
resetDefinition = true;

tests/suite/fixed.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
const assert = require(`assert`);
3+
const path = require(`path`);
34

45
const {default: parserSetup} = require(`../parserSetup`);
56

@@ -416,6 +417,37 @@ exports.fixed9_2 = async () => {
416417
assert.strictEqual(theExtProcedure.subItems.length, 1);
417418
};
418419

420+
421+
422+
exports.fixed9_3 = async () => {
423+
const lines = [
424+
``,
425+
` Ctl-Opt DftActGrp(*No);`,
426+
` /copy tests,eof4 Call plist update program ESF`,
427+
` *COPY EQCPYLESRC,PLUPT_SB Call plist update program ESF`,
428+
``,
429+
` Dcl-s MyVariable2 Char(20);`,
430+
``,
431+
` Dcl-C theConstant 'Hello world';`,
432+
``,
433+
` dsply theConstant;`,
434+
``,
435+
` Return;`
436+
].join(`\n`);
437+
438+
const cache = await parser.getDocs(uri, lines, {withIncludes: true, ignoreCache: true});
439+
440+
assert.strictEqual(cache.includes.length, 1);
441+
assert.strictEqual(cache.variables.length, 1, `Expect length of 1`);
442+
assert.strictEqual(cache.constants.length, 1, `Expect length of 1`);
443+
assert.strictEqual(cache.procedures.length, 1, `Expect length of 1`);
444+
445+
const uppercase = cache.find(`UPPERCASE`);
446+
447+
const baseNameInclude = path.basename(uppercase.position.path);
448+
assert.strictEqual(baseNameInclude, `eof4.rpgle`);
449+
}
450+
419451
/**
420452
* Issue with detecting correct type on subfield.
421453
*/
@@ -1088,4 +1120,54 @@ exports.file_keywords = async () => {
10881120
assert.strictEqual(ord100d.keyword[`INDDS`], `indds`);
10891121
assert.strictEqual(ord100d.keyword[`SFILE`], `sfl01:rrn01`);
10901122
assert.strictEqual(ord100d.keyword[`INFDS`], `Info`);
1123+
}
1124+
1125+
exports.plist_test = async () => {
1126+
const lines = [
1127+
``,
1128+
` ?* PLPVD`,
1129+
` ?* PLPVD - Calling Plist for prompt/validate module driver PLPVD`,
1130+
` ?* PLPVD`,
1131+
` ?* Kaprog - E3A PLPVD`,
1132+
` ?* PLPVD`,
1133+
` ?* @PGMID - Program name PLPVD`,
1134+
` ?* @FLN - Field to prompt/validate on PLPVD`,
1135+
` ?* @SQN - Sequence number of type of validation/prompt PLPVD`,
1136+
` ?* @PRMPT - Prompt mode ('Y' or 'N') PLPVD`,
1137+
` ?* CCN - Communication array PLPVD`,
1138+
` ?* @ERMSG - Error message return field & parms PLPVD`,
1139+
` ?* @NUM - Numeric return field PLPVD`,
1140+
` ?* @CKEY - Command key used from prompt screen return field PLPVD`,
1141+
` ?* @PPF - Prompt performed flag ('Y' or 'N') returned PLPVD`,
1142+
` ?* @DSCNTRL - API Control Fields PLPVD`,
1143+
` ?* @DSSUPER - API Supervisor Data PLPVD`,
1144+
` ?* @DSINCRM - API Incremental Mode Control Fields PLPVD`,
1145+
` ?* @DSPV - PV Control Fields PLPVD`,
1146+
` ?* @DLFILTER - DL Filter Data PLDLD`,
1147+
` ?* @DLLIST - Array of DL row data PLDLD`,
1148+
` ?* @DLSELECTION - DL Selected Item PLDLD`,
1149+
` ?* PLDLD`,
1150+
` C PLPVD PLIST`,
1151+
` C PARM @PGMID 10`,
1152+
` C PARM @FLN 6`,
1153+
` C PARM @SQN 2 0`,
1154+
` C PARM @PRMPT 1`,
1155+
` C PARM CCN`,
1156+
` C DSEPMS PARM DSEPMS @ERMSG 37`,
1157+
` C PARM @NUM 15 0`,
1158+
` C PARM @CKEY 2`,
1159+
` C PARM @PPF 1`,
1160+
` C PARM @DSCNTRL`,
1161+
` C PARM @DSSUPER`,
1162+
` C PARM @DSINCRM`,
1163+
` C PARM @DSPV`,
1164+
` C PARM @PVFILTER 256`,
1165+
` C PARM @PVLIST 9999`,
1166+
` C PARM @PVSELECTION 256`,
1167+
``
1168+
].join(`\n`);
1169+
1170+
const cache = await parser.getDocs(uri, lines, {ignoreCache: true, withIncludes: true});
1171+
1172+
assert.strictEqual(cache.variables.length, 0);
10911173
}

0 commit comments

Comments
 (0)