Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ParsedDocument to ParsedPsl #53

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions __tests__/parser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function getMethod(methodString: string): parser.Method | undefined {
const d = parser.parseText(methodString);
return d.methods[0];
}
function getParsedDoc(documentString: string): parser.ParsedDocument {
function getParsedPsl(documentString: string): parser.ParsedPsl {
return parser.parseText(documentString);
}

Expand Down Expand Up @@ -33,7 +33,7 @@ describe('Batch label', () => {
// ~p1 source not set up
if ER set RM = $$^MSG(1184,"BOFF-ACCUPD"), %BatchExit = 1 do EXC quit`;

const d = getParsedDoc(batchText);
const d = getParsedPsl(batchText);
expect(d.methods).toHaveLength(1);
});

Expand Down Expand Up @@ -93,7 +93,7 @@ describe('Method Identifiers', () => {

test('Label from document', () => {
const methodString = 'main\r\n';
const result = getParsedDoc(methodString);
const result = getParsedPsl(methodString);
if (!result) {
fail();
return;
Expand Down Expand Up @@ -347,13 +347,13 @@ describe('Argument Types', () => {
describe('Propertydefs', () => {
test('empty propertydef', () => {
const propertyString = '\t#PROPERTYDEF';
const doc = getParsedDoc(propertyString);
const doc = getParsedPsl(propertyString);
expect(doc.properties).toHaveLength(0);
});

test('one word propertydef', () => {
const propertyString = '\t#PROPERTYDEF test';
const doc = getParsedDoc(propertyString);
const doc = getParsedPsl(propertyString);
expect(doc.properties).toHaveLength(1);
});
});
Expand Down Expand Up @@ -394,7 +394,7 @@ public final String toString(String vMask)
quit
`;

const doc = getParsedDoc(documentString);
const doc = getParsedPsl(documentString);
expect(doc.methods).toHaveLength(3);
});

Expand All @@ -416,7 +416,7 @@ public final Integer toInteger()
quit
`;

const doc = getParsedDoc(documentString);
const doc = getParsedPsl(documentString);
expect(doc.extending.value).toBe('Primitive');
});

Expand All @@ -438,7 +438,7 @@ public final Integer 900()
quit
`;

const doc = getParsedDoc(documentString);
const doc = getParsedPsl(documentString);
expect(doc.methods[0].id.value).toBe('900');
});

Expand Down Expand Up @@ -478,7 +478,7 @@ public final String toString(String vMask)
quit
`;

const doc = getParsedDoc(documentString);
const doc = getParsedPsl(documentString);
expect(doc.methods.map(method => method.line)).toEqual([9, 18, 27]);
});

Expand Down Expand Up @@ -518,7 +518,7 @@ toString
quit
`;

const doc = getParsedDoc(documentString);
const doc = getParsedPsl(documentString);
expect(doc.methods.map(method => method.id.value)).toEqual(['toInteger', 'toNumber', 'toString']);
expect(doc.methods.map(method => method.line)).toEqual([9, 18, 27]);
});
Expand Down Expand Up @@ -561,7 +561,7 @@ public final String toString(String vMask)
quit
`;

const doc = getParsedDoc(documentString);
const doc = getParsedPsl(documentString);
expect(doc.methods).toHaveLength(3);
});

Expand Down Expand Up @@ -603,7 +603,7 @@ public final String toString(String vMask)
quit
`;

const doc = getParsedDoc(documentString);
const doc = getParsedPsl(documentString);
expect(doc.properties).toHaveLength(1);

});
Expand Down Expand Up @@ -646,7 +646,7 @@ public final String toString(String vMask)
quit
`;

const doc = getParsedDoc(documentString);
const doc = getParsedPsl(documentString);
expect(toValues(doc.properties[0].modifiers)).toEqual(['public']);
expect(doc.properties[0].id.value).toEqual('test');

Expand All @@ -655,21 +655,21 @@ public final String toString(String vMask)
describe('type declarations', () => {
test('basic type declaration', () => {
const declarationString = '\ttype public literal String x = "hi there"';
const doc = getParsedDoc(declarationString);
const doc = getParsedPsl(declarationString);
expect(doc.declarations[0].types[0].value).toEqual('String');
expect(doc.declarations[0].id.value).toEqual('x');
});
test('mutliple type declaration', () => {
const declarationString = '\ttype public literal String x,y';
const doc = getParsedDoc(declarationString);
const doc = getParsedPsl(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', () => {
const declarationString = '\ttype public literal String x(Number,Boolean),y';
const doc = getParsedDoc(declarationString);
const doc = getParsedPsl(declarationString);
expect(doc.declarations[0].types[0].value).toEqual('String');
expect(doc.declarations[0].types[1].value).toEqual('Number');
expect(doc.declarations[0].types[2].value).toEqual('Boolean');
Expand All @@ -679,21 +679,21 @@ describe('type declarations', () => {
});
test('mutliple type declaration equal sign', () => {
const declarationString = '\ttype String x = "hi", y = "hi"';
const doc = getParsedDoc(declarationString);
const doc = getParsedPsl(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('static type declaration', () => {
const declarationString = '\ttype static x';
const doc = getParsedDoc(declarationString);
const doc = getParsedPsl(declarationString);
expect(doc.declarations[0].types[0].value).toEqual('x');
expect(doc.declarations[0].id.value).toEqual('x');
});
test('type type declaration', () => {
const declarationString = '\ttype String type';
const doc = getParsedDoc(declarationString);
const doc = getParsedPsl(declarationString);
expect(doc.declarations[0].types[0].value).toEqual('String');
expect(doc.declarations[0].id.value).toEqual('type');
});
Expand All @@ -708,7 +708,7 @@ public static void main2()
type Number y
quit
`;
const doc = getParsedDoc(documentString);
const doc = getParsedPsl(documentString);
expect(doc.methods[0].declarations[0].id.value).toEqual('x');
expect(doc.methods[1].declarations[0].id.value).toEqual('y');
});
Expand Down
6 changes: 3 additions & 3 deletions __tests__/utilities-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import { MemberClass, ParsedDocument, parseFile } from '../src/parser/parser';
import { MemberClass, ParsedPsl, parseFile } from '../src/parser/parser';
import * as tokenizer from '../src/parser/tokenizer';
import * as utilities from '../src/parser/utilities';

Expand Down Expand Up @@ -121,8 +121,8 @@ describe('ParsedDocFinder', () => {
let parentFilePath: string;
let childFilePath: string;

let parsedParent: ParsedDocument;
let parsedChild: ParsedDocument;
let parsedParent: ParsedPsl;
let parsedChild: ParsedPsl;

beforeAll(async () => {
filesDir = path.resolve('__tests__', 'files');
Expand Down
4 changes: 2 additions & 2 deletions src/language/codeQuality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ function lint(
lintDiagnostics: vscode.DiagnosticCollection,
) {
const profileComponent: api.ProfileComponent = prepareDocument(textDocument);
const parsedDocument = api.ProfileComponent.isPsl(profileComponent.fsPath) ?
const parsedPsl = api.ProfileComponent.isPsl(profileComponent.fsPath) ?
parser.parseText(textDocument.getText()) : undefined;
const diagnostics = getDiagnostics(profileComponent, parsedDocument, useConfig);
const diagnostics = getDiagnostics(profileComponent, parsedPsl, useConfig);
const memberDiagnostics = transform(diagnostics, textDocument.uri);
process.nextTick(() => {
if (!cancellationToken.isCancellationRequested) {
Expand Down
12 changes: 6 additions & 6 deletions src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export interface Declaration extends Member {
/**
* An abstract syntax tree of a PSL document
*/
export interface ParsedDocument {
export interface ParsedPsl {

/**
* An array of Declarations that are not contained within a method.
Expand Down Expand Up @@ -239,20 +239,20 @@ export const NON_TYPE_MODIFIERS = [
'public', 'static', 'private',
];

export function parseText(sourceText: string): ParsedDocument {
export function parseText(sourceText: string): ParsedPsl {
const parser = new Parser();
return parser.parseDocument(sourceText);
return parser.parsePsl(sourceText);
}

export function parseFile(sourcePath: string): Promise<ParsedDocument> {
export function parseFile(sourcePath: string): Promise<ParsedPsl> {
return new Promise((resolve, reject) => {
fs.readFile(sourcePath, (err, data) => {
if (err) {
reject(err);
}
else {
const parser = new Parser();
resolve(parser.parseDocument(data.toString()));
resolve(parser.parsePsl(data.toString()));
}
});
});
Expand Down Expand Up @@ -280,7 +280,7 @@ class Parser {
if (tokenizer) this.tokenizer = tokenizer;
}

parseDocument(documentText: string): ParsedDocument {
parsePsl(documentText: string): ParsedPsl {
this.tokenizer = getTokens(documentText);
while (this.next()) {
if (this.activeToken.isAlphanumeric() || this.activeToken.isMinusSign()) {
Expand Down
40 changes: 20 additions & 20 deletions src/parser/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import { Member, MemberClass, Method, ParsedDocument, parseText, Property } from './parser';
import { Member, MemberClass, Method, ParsedPsl, parseText, Property } from './parser';
import { Position, Token, Type } from './tokenizer';

export interface FinderResult {
Expand All @@ -18,18 +18,18 @@ export const dummyPosition = new Position(0, 0);

export class ParsedDocFinder {

parsedDocument: ParsedDocument;
parsedPsl: ParsedPsl;
paths: FinderPaths;
procName: string;

private hierarchy: string[] = [];

constructor(
parsedDocument: ParsedDocument,
parsedPsl: ParsedPsl,
paths: FinderPaths,
getWorkspaceDocumentText?: (fsPath: string) => Promise<string>,
) {
this.parsedDocument = parsedDocument;
this.parsedPsl = parsedPsl;
this.paths = paths;
if (getWorkspaceDocumentText) this.getWorkspaceDocumentText = getWorkspaceDocumentText;
this.procName = path.basename(this.paths.routine).split('.')[0];
Expand Down Expand Up @@ -58,7 +58,7 @@ export class ParsedDocFinder {
fsPath: tableLocation,
};
}
else if (callTokens[0] === this.parsedDocument.extending) {
else if (callTokens[0] === this.parsedPsl.extending) {
finder = await finder.newFinder(callTokens[0].value);
return {
fsPath: finder.paths.routine,
Expand Down Expand Up @@ -135,7 +135,7 @@ export class ParsedDocFinder {
};
return ret;
});
const parsedDocument: ParsedDocument = {
const parsedPsl: ParsedPsl = {
comments: [],
declarations: [],
extending: new Token(Type.Alphanumeric, 'Record', dummyPosition),
Expand All @@ -145,7 +145,7 @@ export class ParsedDocFinder {
};
const newPaths: FinderPaths = Object.create(this.paths);
newPaths.routine = tableDirectory;
return new ParsedDocFinder(parsedDocument, newPaths, this.getWorkspaceDocumentText);
return new ParsedDocFinder(parsedPsl, newPaths, this.getWorkspaceDocumentText);
}
const pathsWithoutExtensions: string[] = this.paths.projectPsl.map(pslPath => path.join(pslPath, routineName));

Expand Down Expand Up @@ -176,7 +176,7 @@ export class ParsedDocFinder {
async searchInDocument(queriedId: string): Promise<FinderResult | undefined> {
let foundProperty;
if (path.relative(this.paths.routine, this.paths.table) === '..') {
foundProperty = this.parsedDocument.properties.find(p => p.id.value.toLowerCase() === queriedId.toLowerCase());
foundProperty = this.parsedPsl.properties.find(p => p.id.value.toLowerCase() === queriedId.toLowerCase());
if (foundProperty) {
const tableName = path.basename(this.paths.routine).toUpperCase();
return {
Expand All @@ -185,14 +185,14 @@ export class ParsedDocFinder {
};
}
}
foundProperty = this.parsedDocument.properties.find(p => p.id.value === queriedId);
foundProperty = this.parsedPsl.properties.find(p => p.id.value === queriedId);
if (foundProperty) return { member: foundProperty, fsPath: this.paths.routine };

const foundMethod = this.parsedDocument.methods.find(p => p.id.value === queriedId);
const foundMethod = this.parsedPsl.methods.find(p => p.id.value === queriedId);
if (foundMethod) return { member: foundMethod, fsPath: this.paths.routine };

if (this.parsedDocument.extending) {
const parentRoutineName = this.parsedDocument.extending.value;
if (this.parsedPsl.extending) {
const parentRoutineName = this.parsedPsl.extending.value;
if (this.hierarchy.indexOf(parentRoutineName) > -1) return;
const parentFinder: ParsedDocFinder | undefined = await this.searchForParent(parentRoutineName);
if (!parentFinder) return;
Expand All @@ -210,21 +210,21 @@ export class ParsedDocFinder {
};

if (path.relative(this.paths.routine, this.paths.table) === '..') {
this.parsedDocument.properties.forEach(property => {
this.parsedPsl.properties.forEach(property => {
const tableName = path.basename(this.paths.routine).toUpperCase();
addToResults({ member: property, fsPath: path.join(this.paths.routine, `${tableName}-${property.id.value}.COL`) });
});
}
this.parsedDocument.properties.forEach(property => {
this.parsedPsl.properties.forEach(property => {
addToResults({ member: property, fsPath: this.paths.routine });
});

this.parsedDocument.methods.forEach(method => {
this.parsedPsl.methods.forEach(method => {
addToResults({ member: method, fsPath: this.paths.routine });
});

if (this.parsedDocument.extending) {
const parentRoutineName = this.parsedDocument.extending.value;
if (this.parsedPsl.extending) {
const parentRoutineName = this.parsedPsl.extending.value;
if (this.hierarchy.indexOf(parentRoutineName) > -1) return results;
const parentFinder: ParsedDocFinder | undefined = await this.searchForParent(parentRoutineName);
if (!parentFinder) return results;
Expand All @@ -251,7 +251,7 @@ export class ParsedDocFinder {
}

private findActiveMethod(queriedToken: Token): Method | undefined {
const methods = this.parsedDocument.methods.filter(method => queriedToken.position.line >= method.id.position.line);
const methods = this.parsedPsl.methods.filter(method => queriedToken.position.line >= method.id.position.line);
if (methods) return methods[methods.length - 1];
}

Expand Down Expand Up @@ -401,8 +401,8 @@ export function getLineAfter(method: Method): number {
return method.closeParen ? method.closeParen.position.line + 1 : method.id.position.line + 1;
}

export function getCommentsOnLine(parsedDocument: ParsedDocument, lineNumber: number): Token[] {
return parsedDocument.comments.filter(t => {
export function getCommentsOnLine(parsedPsl: ParsedPsl, lineNumber: number): Token[] {
return parsedPsl.comments.filter(t => {
return t.position.line === lineNumber;
});
}
Loading