Skip to content

Commit 4e07d32

Browse files
msujewmontymxbLotes
committed
Prototype implementation of PL/I
Co-authored-by: Benjamin Wilson <[email protected]> Co-authored-by: Markus Rudolph <[email protected]> Signed-off-by: Mark Sujew <[email protected]>
1 parent 769e52c commit 4e07d32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+13716
-3
lines changed

.eslintrc.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaVersion": 6,
6+
"sourceType": "module"
7+
},
8+
"plugins": [
9+
"@typescript-eslint"
10+
],
11+
"rules": {
12+
}
13+
}

.github/workflows/ci.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
name: CI (${{ matrix.os }})
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [windows-latest, ubuntu-latest]
18+
runs-on: ${{ matrix.os }}
19+
timeout-minutes: 20
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
- name: Install pnpm
24+
uses: pnpm/action-setup@v4
25+
with:
26+
version: 9
27+
- name: Use Node.js
28+
uses: actions/setup-node@v3
29+
with:
30+
node-version: '18'
31+
cache: 'pnpm'
32+
- name: Build monorepo
33+
shell: bash
34+
run: |
35+
pnpm install
36+
pnpm build
37+
- name: Test monorepo
38+
if: success() || failure()
39+
shell: bash
40+
run: |
41+
pnpm test

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.vscode/*
2+
!.vscode/extensions.json
3+
!.vscode/launch.json
4+
!.vscode/tasks.json
5+
node_modules/
6+
dist/
7+
out/
8+
**/src/generated
9+
**/syntaxes/pli.merged.json
10+
*.tsbuildinfo
11+
*.vsix

.npmrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
auto-install-peers = true
2+
lockfile = true
3+
link-workspace-packages = true

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20.18.1

.vscode/extensions.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"langium.langium-vscode",
4+
"vitest.explorer"
5+
]
6+
}

.vscode/launch.json

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// A launch configuration that launches the extension inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Run Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-extension",
14+
"${workspaceFolder}/code_samples"
15+
],
16+
"sourceMaps": true,
17+
"outFiles": [
18+
"${workspaceFolder}/packages/language/out/**/*.js",
19+
"${workspaceFolder}/packages/vscode-extension/out/**/*.js"
20+
]
21+
},
22+
{
23+
"name": "Run Web Extension",
24+
"type": "extensionHost",
25+
"debugWebWorkerHost": true,
26+
"request": "launch",
27+
"args": [
28+
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-extension",
29+
"--extensionDevelopmentKind=web",
30+
"${workspaceFolder}/code_samples"
31+
],
32+
"sourceMaps": true,
33+
"outFiles": [
34+
"${workspaceFolder}/packages/language/out/**/*.js",
35+
"${workspaceFolder}/packages/vscode-extension/out/**/*.js"
36+
]
37+
},
38+
{
39+
"name": "Attach to Language Server",
40+
"type": "node",
41+
"port": 6009,
42+
"request": "attach",
43+
"skipFiles": [
44+
"<node_internals>/**"
45+
],
46+
"sourceMaps": true,
47+
"outFiles": [
48+
"${workspaceFolder}/packages/language/out/**/*.js",
49+
"${workspaceFolder}/packages/vscode-extension/out/**/*.js",
50+
"${workspaceFolder}/node_modules/langium"
51+
]
52+
},
53+
{
54+
"name": "Vitest: Run All",
55+
"type": "node",
56+
"request": "launch",
57+
"skipFiles": [
58+
"<node_internals>/**",
59+
],
60+
"cwd": "${workspaceFolder}",
61+
"runtimeExecutable": "pnpm",
62+
"args": [
63+
"vitest",
64+
"run",
65+
"--no-watch"
66+
],
67+
"smartStep": true,
68+
"console": "integratedTerminal"
69+
},
70+
{
71+
"name": "Vitest: Run Selected File",
72+
"type": "node",
73+
"request": "launch",
74+
"autoAttachChildProcesses": true,
75+
"skipFiles": [
76+
"<node_internals>/**"
77+
],
78+
"runtimeExecutable": "pnpm",
79+
"args": [
80+
"vitest",
81+
"run",
82+
"${relativeFile}"
83+
],
84+
"smartStep": true,
85+
"console": "integratedTerminal"
86+
}
87+
]
88+
}

code_samples/CHART.pli

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*PROCESS X(S),A(S),LINECOUNT(60);
1+
/*PROCESS X(S),A(S),LINECOUNT(60); */
22
/* %M% %I% %D% %T%
33
PUNCH ' IDENTIFY **%M%1(''%M%/%I% %D% %T%'')'
44
PUNCH ' ENTRY PLISTART '

code_samples/MACROS.pli

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*PROCESS MI(':'),NEST,X,AG,A,MAR(2,72,1),GN,NUM,STG;
1+
/*PROCESS MI(':'),NEST,X,AG,A,MAR(2,72,1),GN,NUM,STG; */
22

33
/*** (CHECK): ***/
44

code_samples/PLI0002.pli

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
/* DECLARE HOST-VARIABLE */
3939
DCL TIMESTAMP CHAR(26);
40-
DCL BUF1_CLOB SQL TYPE IS CLOB_FILE;
40+
DCL BUF1_CLOB; // SQL TYPE IS CLOB_FILE;
4141
EXEC SQL DECLARE :BUF1_CLOB VARIABLE CCSID EBCDIC;
4242

4343
DCL I FIXED BIN(31);

code_samples/messages/IBM1295IE.pli

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TEST: PROCEDURE OPTIONS(MAIN) REORDER;
2+
dcl x(-2) fixed bin; //error: IBM1295IE Sole bound specified is less than 1. An upper bound of 1 is assumed.
3+
END TEST;

code_samples/messages/IBM1324IE.pli

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
0PACK: PACKAGE EXPORTS(TEST, TEST, TEST); //error: TEST has 3 occurences, needed 1
2+
0END;

code_samples/messages/IBM1388IE.pli

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
0a: proc( x ) options(nodescriptor); //error: The NODESCRIPTOR attribute is invalid when any parameters have the NONCONNECTED attribute.
2+
dcl x(20) fixed bin nonconnected;
3+
0end a;

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "pli-workspace",
3+
"description": "Base workspace package",
4+
"version": "0.0.1",
5+
"type": "module",
6+
"private": true,
7+
"scripts": {
8+
"watch": "tsc -b tsconfig.build.json --watch",
9+
"build": "pnpm langium:generate && tsc -b tsconfig.build.json && pnpm --dir packages/vscode-extension build && node ./scripts/merge-tmlanguage.mjs",
10+
"build:clean": "pnpm clean && pnpm build",
11+
"lint": "eslint src --ext ts",
12+
"langium:generate": "pnpm --dir packages/language langium:generate",
13+
"langium:watch": "pnpm --dir packages/language langium:watch",
14+
"test": "vitest"
15+
},
16+
"devDependencies": {
17+
"@types/node": "^18.19.70",
18+
"@typescript-eslint/eslint-plugin": "~7.13.1",
19+
"@typescript-eslint/parser": "~7.13.1",
20+
"deepmerge": "^1.5.2",
21+
"eslint": "~8.57.1",
22+
"langium": "~3.2.1",
23+
"shx": "~0.3.4",
24+
"typescript": "~5.4.5",
25+
"vitest": "^1.6.0"
26+
}
27+
}

packages/language/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# PL1 Language Package

packages/language/langium-config.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"projectName": "Pl1",
3+
"languages": [{
4+
"id": "pli",
5+
"grammar": "src/pli.langium",
6+
"fileExtensions": [".pli"],
7+
"caseInsensitive": true
8+
}],
9+
"out": "src/generated"
10+
}

packages/language/package.json

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "pli-language",
3+
"description": "The language specific package",
4+
"version": "0.0.1",
5+
"type": "module",
6+
"engines": {
7+
"node": ">=18.0.0"
8+
},
9+
"files": [
10+
"out",
11+
"src"
12+
],
13+
"main": "./out/index.js",
14+
"module": "./out/index.js",
15+
"exports": {
16+
".": {
17+
"types": "./out/index.d.ts",
18+
"default": "./out/index.js"
19+
}
20+
},
21+
"typesVersions": {
22+
"*": {
23+
".": [
24+
"out/index"
25+
]
26+
}
27+
},
28+
"scripts": {
29+
"clean": "shx rm -fr *.tsbuildinfo out",
30+
"build": "echo 'No build step'",
31+
"build:clean": "npm run clean && npm run build",
32+
"langium:generate": "langium generate",
33+
"langium:watch": "langium generate --watch"
34+
},
35+
"dependencies": {
36+
"chevrotain": "^11.0.3",
37+
"langium": "~3.2.0",
38+
"vscode-languageserver": "~9.0.1",
39+
"vscode-languageserver-types": "^3.17.5"
40+
},
41+
"devDependencies": {
42+
"langium-cli": "~3.2.0"
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*
10+
*/
11+
12+
import { AstNode, JSDocDocumentationProvider } from 'langium';
13+
import { isDeclaredVariable, isDoType3Variable, isLabelPrefix, isProcedureStatement, ProcedureStatement } from '../generated/ast';
14+
15+
export class PliDocumentationProvider extends JSDocDocumentationProvider {
16+
17+
override getDocumentation(node: AstNode): string | undefined {
18+
if (isDeclaredVariable(node)) {
19+
const declaredItem = node.$container;
20+
let text = '```\n' + `DECLARE ${node.name} `;
21+
for (const attribute of declaredItem.attributes) {
22+
text += `${attribute.$cstNode?.text} `;
23+
}
24+
text += '\n```';
25+
return text;
26+
} else if (isLabelPrefix(node) && isProcedureStatement(node.$container)) {
27+
return this.getProcedureHoverContent(node.$container);
28+
} else if (isProcedureStatement(node)) {
29+
return this.getProcedureHoverContent(node);
30+
} else if (isDoType3Variable(node)) {
31+
return '```\nDECLARE' + node.name + '\n```';
32+
}
33+
return '';
34+
}
35+
36+
private getProcedureHoverContent(node: ProcedureStatement): string | undefined {
37+
let text = '```\n';
38+
for (const label of node.labels) {
39+
text += `${label.name} `;
40+
}
41+
text += 'PROCEDURE ';
42+
if (node.parameters.length > 0) {
43+
text += '(' + node.parameters.map(e => e.id).join(', ') + ') ';
44+
}
45+
if (node.recursive.length > 0) {
46+
text += 'RECURSIVE ';
47+
}
48+
if (node.order.includes('ORDER')) {
49+
text += 'ORDER ';
50+
} else if (node.order.includes('REORDER')) {
51+
text += 'REORDER ';
52+
}
53+
if (node.options.length > 0) {
54+
text += node.options.map(e => e.$cstNode?.text).join(' ');
55+
}
56+
if (node.returns.length > 0) {
57+
text += node.returns.map(e => e.$cstNode?.text).join(' ');
58+
}
59+
text += '\n```';
60+
return text;
61+
}
62+
63+
}

packages/language/src/index.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*
10+
*/
11+
12+
export * from './pli-module.js';
13+
export * from './validation/pli-validator.js';
14+
export * from './generated/ast.js';
15+
export * from './generated/grammar.js';
16+
export * from './generated/module.js';
17+
export * from './workspace/pli-builtin-functions.js';

0 commit comments

Comments
 (0)