Skip to content

Commit

Permalink
Merge pull request #280 from codefori/fix/278_parser_fix
Browse files Browse the repository at this point in the history
Parser fixed for includes and undefined handling
  • Loading branch information
worksofliam authored Nov 18, 2023
2 parents 00a3713 + 0e1b7e1 commit c6e94fe
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 6 deletions.
27 changes: 21 additions & 6 deletions language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,26 @@ export default class Parser {
directiveLength = 9
};

/** @type {string|undefined} */
let directiveValue;

if (directivePosition >= 0) {
if (comment >= 0) {
return line.substring(directivePosition+directiveLength, comment).trim();
directiveValue = line.substring(directivePosition+directiveLength, comment).trim();
} else {
return line.substring(directivePosition+directiveLength).trim();
directiveValue = line.substring(directivePosition+directiveLength).trim();
}
}

if (directiveValue) {
const spaceIndex = directiveValue.indexOf(` `);
if (spaceIndex >= 0) {
directiveValue = directiveValue.substring(0, spaceIndex);
}

return directiveValue;
}

}

/**
Expand Down Expand Up @@ -1032,10 +1045,12 @@ export default class Parser {
scope.files.push(currentItem);
} else {
currentItem = scope.files[scope.files.length-1];
currentItem.keywords = [
...(currentItem.keywords ? currentItem.keywords : []),
...fSpec.keywords
]
if (currentItem) {
currentItem.keywords = [
...(currentItem.keywords ? currentItem.keywords : []),
...fSpec.keywords
]
}
}

resetDefinition = true;
Expand Down
82 changes: 82 additions & 0 deletions tests/suite/fixed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

const assert = require(`assert`);
const path = require(`path`);

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

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



exports.fixed9_3 = async () => {
const lines = [
``,
` Ctl-Opt DftActGrp(*No);`,
` /copy tests,eof4 Call plist update program ESF`,
` *COPY EQCPYLESRC,PLUPT_SB Call plist update program ESF`,
``,
` Dcl-s MyVariable2 Char(20);`,
``,
` Dcl-C theConstant 'Hello world';`,
``,
` dsply theConstant;`,
``,
` Return;`
].join(`\n`);

const cache = await parser.getDocs(uri, lines, {withIncludes: true, ignoreCache: true});

assert.strictEqual(cache.includes.length, 1);
assert.strictEqual(cache.variables.length, 1, `Expect length of 1`);
assert.strictEqual(cache.constants.length, 1, `Expect length of 1`);
assert.strictEqual(cache.procedures.length, 1, `Expect length of 1`);

const uppercase = cache.find(`UPPERCASE`);

const baseNameInclude = path.basename(uppercase.position.path);
assert.strictEqual(baseNameInclude, `eof4.rpgle`);
}

/**
* Issue with detecting correct type on subfield.
*/
Expand Down Expand Up @@ -1088,4 +1120,54 @@ exports.file_keywords = async () => {
assert.strictEqual(ord100d.keyword[`INDDS`], `indds`);
assert.strictEqual(ord100d.keyword[`SFILE`], `sfl01:rrn01`);
assert.strictEqual(ord100d.keyword[`INFDS`], `Info`);
}

exports.plist_test = async () => {
const lines = [
``,
` ?* PLPVD`,
` ?* PLPVD - Calling Plist for prompt/validate module driver PLPVD`,
` ?* PLPVD`,
` ?* Kaprog - E3A PLPVD`,
` ?* PLPVD`,
` ?* @PGMID - Program name PLPVD`,
` ?* @FLN - Field to prompt/validate on PLPVD`,
` ?* @SQN - Sequence number of type of validation/prompt PLPVD`,
` ?* @PRMPT - Prompt mode ('Y' or 'N') PLPVD`,
` ?* CCN - Communication array PLPVD`,
` ?* @ERMSG - Error message return field & parms PLPVD`,
` ?* @NUM - Numeric return field PLPVD`,
` ?* @CKEY - Command key used from prompt screen return field PLPVD`,
` ?* @PPF - Prompt performed flag ('Y' or 'N') returned PLPVD`,
` ?* @DSCNTRL - API Control Fields PLPVD`,
` ?* @DSSUPER - API Supervisor Data PLPVD`,
` ?* @DSINCRM - API Incremental Mode Control Fields PLPVD`,
` ?* @DSPV - PV Control Fields PLPVD`,
` ?* @DLFILTER - DL Filter Data PLDLD`,
` ?* @DLLIST - Array of DL row data PLDLD`,
` ?* @DLSELECTION - DL Selected Item PLDLD`,
` ?* PLDLD`,
` C PLPVD PLIST`,
` C PARM @PGMID 10`,
` C PARM @FLN 6`,
` C PARM @SQN 2 0`,
` C PARM @PRMPT 1`,
` C PARM CCN`,
` C DSEPMS PARM DSEPMS @ERMSG 37`,
` C PARM @NUM 15 0`,
` C PARM @CKEY 2`,
` C PARM @PPF 1`,
` C PARM @DSCNTRL`,
` C PARM @DSSUPER`,
` C PARM @DSINCRM`,
` C PARM @DSPV`,
` C PARM @PVFILTER 256`,
` C PARM @PVLIST 9999`,
` C PARM @PVSELECTION 256`,
``
].join(`\n`);

const cache = await parser.getDocs(uri, lines, {ignoreCache: true, withIncludes: true});

assert.strictEqual(cache.variables.length, 0);
}

0 comments on commit c6e94fe

Please sign in to comment.