Skip to content

Commit

Permalink
Fix code inspections findings.
Browse files Browse the repository at this point in the history
  • Loading branch information
c4xuxo committed Dec 9, 2022
1 parent 071c262 commit 002051d
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 84 deletions.
21 changes: 21 additions & 0 deletions .dictionaries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Dictionaries

This folder contains dictionaries to be used by spell checkers programs to
validate the special words used in this project.

## Available dictionaries

### Words

Contains words used in this project.

File: [words.dic](words.dic)

## File format

Plain text files with the dic extension, containing words separated with a
newline.

## Adding words guidelines

Please only add words that make sense, and in the appropriate dictionary.
4 changes: 4 additions & 0 deletions .dictionaries/words.dic
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CLASSDEF
ENDDOC
PROPERTYDEF
REVHIST
2 changes: 1 addition & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
cache: 'npm'
- run: npm install
- run: npm run build
- run: npm run test
- run: npm test
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

# Add lib/
!lib/**
# Exclude .map in lib/
# Exclude exceptions from lib/
*.map
*.tsbuildinfo

# Add documentation
!LICENSE
Expand Down
9 changes: 4 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
"lib": false
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
"lib": true
},
"editor.rulers": [120] // Recommended typescript ruler
}
"editor.rulers": [120]
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
"url": "https://github.com/ing-bank/psl-parser.git"
},
"scripts": {
"clean": "rimraf lib",
"buildts": "tsc",
"build": "npm run clean && npm run buildts",
"prebuild": "rimraf lib",
"build": "tsc --build src",
"lint": "tslint -c tslint.json --project .",
"watch": "npm run build -- -watch",
"pretest": "tsc --build src",
"test": "jest"
},
"dependencies": {
Expand Down
13 changes: 8 additions & 5 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export interface ParsedDocument {
declarations: Declaration[];

/**
* An array of PROPERTYDEFs
* An array of PROPERTYDEF
*/
properties: Property[];

Expand Down Expand Up @@ -328,16 +328,17 @@ class Parser {
if (documentation) this.activeMethod.documentation = documentation;
}
}
else if (this.activeToken.isNewLine()) continue;
else this.throwAwayTokensTil(Type.NewLine);
else if (!this.activeToken.isNewLine()) {
this.throwAwayTokensTil(Type.NewLine);
}
}
return {
comments: this.comments,
declarations: this.declarations,
extending: this.extending,
pslPackage: this.pslPackage,
methods: this.methods,
properties: this.properties,
pslPackage: this.pslPackage,
tokens: this.tokens,
};
}
Expand Down Expand Up @@ -580,7 +581,9 @@ class Parser {
}

private throwAwayTokensTil(type: Type) {
while (this.next() && this.activeToken.type !== type);
while (this.next()) {
if (this.activeToken.type === type) break;
}
}

private loadTokenBuffer() {
Expand Down
8 changes: 4 additions & 4 deletions src/statementParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTokens, Token, Type } from './tokenizer';
import {getTokens, Token, Type} from './tokenizer';

export enum SyntaxKind {
ASSIGNMENT,
Expand Down Expand Up @@ -402,7 +402,7 @@ export class StatementParser {
const spaceOrExpression = this.activeToken;
if (spaceOrExpression.isSpace()) {
this.next();
return forStatement; // argumentless for
return forStatement; // argument less for
}
const expression = this.parseExpression();
if (expression) forStatement.expressions.push(expression);
Expand Down Expand Up @@ -484,13 +484,12 @@ export class StatementParser {
while (this.activeToken && this.activeToken.isColon()) {
const colonToken = this.activeToken;
this.next(true);
const colon: BinaryOperator = {
rootNode = {
kind: SyntaxKind.BINARY_OPERATOR,
left: rootNode,
operator: [colonToken],
right: this.parseValue(),
};
rootNode = colon;
}
return rootNode;
}
Expand Down Expand Up @@ -747,6 +746,7 @@ export function forEachChild(node: Node, f: (n: Node) => boolean) {
const declaration = node as DeclarationStatement;
if (declaration.args) declaration.args.forEach(arg => forEachChild(arg, f));
f(declaration.type);
break;
case SyntaxKind.NUMERIC_LITERAL:
case SyntaxKind.STRING_LITERAL:
f(node);
Expand Down
7 changes: 7 additions & 0 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"composite": true,
}
}

14 changes: 7 additions & 7 deletions test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('Argument Names', () => {
expect(argNameValues).toEqual(['x1', 'x2']);
});

test('1 argument multitype', () => {
test('1 argument multi type', () => {
const methodString = 'public static void main(void x1(Integer, Record))';
const result = getMethod(methodString);
if (!result) {
Expand All @@ -220,7 +220,7 @@ describe('Argument Names', () => {
expect(argNameValues).toEqual(['x1']);
});

test('2 argument multitype', () => {
test('2 argument multi type', () => {
const methodString = 'public static void main(void x1(Integer, Record), void x2(void, String))';
const result = getMethod(methodString);
if (!result) {
Expand All @@ -231,7 +231,7 @@ describe('Argument Names', () => {
expect(argNameValues).toEqual(['x1', 'x2']);
});

test('2 argument multitype', () => {
test('2 argument multiline and multi type', () => {
const methodString = 'public static void main(void x1(Integer, Record)\n\t, void x2(void, String))';
const result = getMethod(methodString);
if (!result) {
Expand Down Expand Up @@ -299,7 +299,7 @@ describe('Argument Types', () => {
expect(argValues).toEqual([['String']]);
});

test('1 argument multitype', () => {
test('1 argument multi type', () => {
const methodString = 'public static void main(String x1(Number))';
const result = getMethod(methodString);
if (!result) {
Expand Down Expand Up @@ -681,15 +681,15 @@ describe('type declarations', () => {
expect(doc.declarations[0].types[0].value).toEqual('String');
expect(doc.declarations[0].id.value).toEqual('x');
});
test('mutliple type declaration', () => {
test('multiple type declaration', () => {
const declarationString = '\ttype public literal String x,y';
const doc = getParsedDoc(declarationString);
expect(doc.declarations[0].types[0].value).toEqual('String');
expect(doc.declarations[0].id.value).toEqual('x');
expect(doc.declarations[1].types[0].value).toEqual('String');
expect(doc.declarations[1].id.value).toEqual('y');
});
test('mutliple multitype type declaration', () => {
test('multiple multi type type declaration', () => {
const declarationString = '\ttype public literal String x(Number,Boolean),y';
const doc = getParsedDoc(declarationString);
expect(doc.declarations[0].types[0].value).toEqual('String');
Expand All @@ -699,7 +699,7 @@ describe('type declarations', () => {
expect(doc.declarations[1].types[0].value).toEqual('String');
expect(doc.declarations[1].id.value).toEqual('y');
});
test('mutliple type declaration equal sign', () => {
test('multiple type declaration equal sign', () => {
const declarationString = '\ttype String x = "hi", y = "hi"';
const doc = getParsedDoc(declarationString);
expect(doc.declarations[0].types[0].value).toEqual('String');
Expand Down
12 changes: 6 additions & 6 deletions test/statementParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
BinaryOperator, DeclarationStatement, Expression, Identifier, MultiSet, NumericLiteral,
PostCondition, Statement, StatementParser, StringLiteral, SyntaxKind, TypeIdentifier, Value,
} from '../src/statementParser';
} from '../src';
import { getTokens, Token } from '../src/tokenizer';

function parse(text: string) {
Expand Down Expand Up @@ -126,18 +126,18 @@ describe('recursive tests', () => {
expect(start.id).toBe(parser.tokens[2]);
});
test('Runtime start', () => {
const parser = parse('Runtime.start("BA",varlist)');
const parser = parse('Runtime.start("BA",varList)');
const dotNode = parser.parseExpression() as BinaryOperator;
const runtime = dotNode.left as Identifier;
const start = dotNode.right as Identifier;
const args = start.args as Value[];
const ba = args[0];
const varlist = args[1];
const varList = args[1];
expect(dotNode.kind === SyntaxKind.BINARY_OPERATOR);
expect(runtime.id).toBe(parser.tokens[0]);
expect((start).id).toBe(parser.tokens[2]);
expect(ba.id).toBe(parser.tokens[5]);
expect(varlist.id).toBe(parser.tokens[8]);
expect(varList.id).toBe(parser.tokens[8]);
});
test('grandchild', () => {
const parser = parse('a.b.c');
Expand Down Expand Up @@ -545,7 +545,7 @@ describe('recursive tests', () => {
expect(i.id.value).toBe('i');
expect(initial.id.value).toBe('1');
});
test('argumentless for loop', () => {
test('argument less for loop', () => {
const parser = parse('for set x = 1');
const statements = parser.parseLine();
const forStatement = statements[0];
Expand All @@ -563,7 +563,7 @@ describe('recursive tests', () => {
expect(args.length).toBe(3);
});
test('for order', () => {
const parser = parse('for set seq=tras(seq).order() quit:seq.isNull() do set(tras(seq))');
const parser = parse('for set seq=array(seq).order() quit:seq.isNull() do set(array(seq))');
const statements = parser.parseLine();
const setStatement = statements[1];
const equal = setStatement.expressions[0] as BinaryOperator;
Expand Down
Loading

0 comments on commit 002051d

Please sign in to comment.