Skip to content

Commit

Permalink
Prototype implementation of PL/I
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Wilson <[email protected]>
Co-authored-by: Markus Rudolph <[email protected]>
Signed-off-by: Mark Sujew <[email protected]>
  • Loading branch information
3 people committed Nov 26, 2024
1 parent 769e52c commit 1f0d1c2
Show file tree
Hide file tree
Showing 66 changed files with 13,611 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: CI (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'pnpm'
- name: Build monorepo
shell: bash
run: |
pnpm install
pnpm build
- name: Test monorepo
if: success() || failure()
shell: bash
run: |
pnpm test
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vscode/*
!.vscode/extensions.json
!.vscode/launch.json
!.vscode/tasks.json
node_modules/
dist/
out/
**/src/generated
**/syntaxes/pli.merged.json
*.tsbuildinfo
*.vsix
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
auto-install-peers = true
lockfile = true
link-workspace-packages = true
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"langium.langium-vscode",
"vitest.explorer"
]
}
88 changes: 88 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// A launch configuration that launches the extension inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-extension",
"${workspaceFolder}/code_samples"
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/packages/language/out/**/*.js",
"${workspaceFolder}/packages/vscode-extension/out/**/*.js"
]
},
{
"name": "Run Web Extension",
"type": "extensionHost",
"debugWebWorkerHost": true,
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-extension",
"--extensionDevelopmentKind=web",
"${workspaceFolder}/code_samples"
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/packages/language/out/**/*.js",
"${workspaceFolder}/packages/vscode-extension/out/**/*.js"
]
},
{
"name": "Attach to Language Server",
"type": "node",
"port": 6009,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/packages/language/out/**/*.js",
"${workspaceFolder}/packages/vscode-extension/out/**/*.js",
"${workspaceFolder}/node_modules/langium"
]
},
{
"name": "Vitest: Run All",
"type": "node",
"request": "launch",
"skipFiles": [
"<node_internals>/**",
],
"cwd": "${workspaceFolder}",
"runtimeExecutable": "pnpm",
"args": [
"vitest",
"run",
"--no-watch"
],
"smartStep": true,
"console": "integratedTerminal"
},
{
"name": "Vitest: Run Selected File",
"type": "node",
"request": "launch",
"autoAttachChildProcesses": true,
"skipFiles": [
"<node_internals>/**"
],
"runtimeExecutable": "pnpm",
"args": [
"vitest",
"run",
"${relativeFile}"
],
"smartStep": true,
"console": "integratedTerminal"
}
]
}
2 changes: 1 addition & 1 deletion code_samples/CHART.pli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*PROCESS X(S),A(S),LINECOUNT(60);
/*PROCESS X(S),A(S),LINECOUNT(60); */
/* %M% %I% %D% %T%
PUNCH ' IDENTIFY **%M%1(''%M%/%I% %D% %T%'')'
PUNCH ' ENTRY PLISTART '
Expand Down
2 changes: 1 addition & 1 deletion code_samples/MACROS.pli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*PROCESS MI(':'),NEST,X,AG,A,MAR(2,72,1),GN,NUM,STG;
/*PROCESS MI(':'),NEST,X,AG,A,MAR(2,72,1),GN,NUM,STG; */

/*** (CHECK): ***/

Expand Down
2 changes: 1 addition & 1 deletion code_samples/PLI0002.pli
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

/* DECLARE HOST-VARIABLE */
DCL TIMESTAMP CHAR(26);
DCL BUF1_CLOB SQL TYPE IS CLOB_FILE;
DCL BUF1_CLOB; // SQL TYPE IS CLOB_FILE;
EXEC SQL DECLARE :BUF1_CLOB VARIABLE CCSID EBCDIC;

DCL I FIXED BIN(31);
Expand Down
3 changes: 3 additions & 0 deletions code_samples/messages/IBM1295IE.pli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TEST: PROCEDURE OPTIONS(MAIN) REORDER;
dcl x(-2) fixed bin; //error: IBM1295IE Sole bound specified is less than 1. An upper bound of 1 is assumed.
END TEST;
2 changes: 2 additions & 0 deletions code_samples/messages/IBM1324IE.pli
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0PACK: PACKAGE EXPORTS(TEST, TEST, TEST); //error: TEST has 3 occurences, needed 1
0END;
3 changes: 3 additions & 0 deletions code_samples/messages/IBM1388IE.pli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0a: proc( x ) options(nodescriptor); //error: The NODESCRIPTOR attribute is invalid when any parameters have the NONCONNECTED attribute.
dcl x(20) fixed bin nonconnected;
0end a;
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "pl-one-workspace",
"description": "Base workspace package",
"version": "0.0.1",
"type": "module",
"private": true,
"scripts": {
"watch": "tsc -b tsconfig.build.json --watch",
"build": "pnpm langium:generate && tsc -b tsconfig.build.json && pnpm --dir packages/extension build && node ./scripts/merge-tmlanguage.mjs",
"build:clean": "pnpm clean && pnpm build",
"lint": "eslint src --ext ts",
"langium:generate": "pnpm --dir packages/language langium:generate",
"langium:watch": "pnpm --dir packages/language langium:watch",
"test": "vitest"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@typescript-eslint/parser": "~7.13.0",
"@typescript-eslint/eslint-plugin": "~7.13.0",
"eslint": "~8.57.0",
"deepmerge": "^1.5.0",
"langium": "~3.2.0",
"shx": "~0.3.4",
"typescript": "~5.4.5",
"vitest": "^1.6.0"
},
"volta": {
"node": "18.20.3",
"npm": "10.7.0"
}
}
1 change: 1 addition & 0 deletions packages/language/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# PL1 Language Package
10 changes: 10 additions & 0 deletions packages/language/langium-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"projectName": "Pl1",
"languages": [{
"id": "pli",
"grammar": "src/pli.langium",
"fileExtensions": [".pli"],
"caseInsensitive": true
}],
"out": "src/generated"
}
48 changes: 48 additions & 0 deletions packages/language/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "pl-one-language",
"description": "The language specific package",
"version": "0.0.1",
"type": "module",
"engines": {
"node": ">=18.0.0"
},
"files": [
"out",
"src"
],
"main": "./out/index.js",
"module": "./out/index.js",
"exports": {
".": {
"types": "./out/index.d.ts",
"default": "./out/index.js"
}
},
"typesVersions": {
"*": {
".": [
"out/index"
]
}
},
"scripts": {
"clean": "shx rm -fr *.tsbuildinfo out",
"build": "echo 'No build step'",
"build:clean": "npm run clean && npm run build",
"langium:generate": "langium generate",
"langium:watch": "langium generate --watch"
},
"dependencies": {
"chevrotain": "^11.0.3",
"langium": "~3.2.0",
"vscode-languageserver": "~9.0.1",
"vscode-languageserver-types": "^3.17.5"
},
"devDependencies": {
"langium-cli": "~3.2.0"
},
"volta": {
"node": "18.20.3",
"npm": "10.7.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

import { AstNode, JSDocDocumentationProvider } from 'langium';
import { isDeclaredVariable, isDoType3Variable, isLabelPrefix, isProcedureStatement, ProcedureStatement } from '../generated/ast';

export class PliDocumentationProvider extends JSDocDocumentationProvider {

override getDocumentation(node: AstNode): string | undefined {
if (isDeclaredVariable(node)) {
const declaredItem = node.$container;
let text = '```\n' + `DECLARE ${node.name} `;
for (const attribute of declaredItem.attributes) {
text += `${attribute.$cstNode?.text} `;
}
text += '\n```';
return text;
} else if (isLabelPrefix(node) && isProcedureStatement(node.$container)) {
return this.getProcedureHoverContent(node.$container);
} else if (isProcedureStatement(node)) {
return this.getProcedureHoverContent(node);
} else if (isDoType3Variable(node)) {
return '```\nDECLARE' + node.name + '\n```';
}
return '';
}

private getProcedureHoverContent(node: ProcedureStatement): string | undefined {
let text = '```\n';
for (const label of node.labels) {
text += `${label.name} `;
}
text += 'PROCEDURE ';
if (node.parameters.length > 0) {
text += '(' + node.parameters.map(e => e.id).join(', ') + ') ';
}
if (node.recursive.length > 0) {
text += 'RECURSIVE ';
}
if (node.order.includes('ORDER')) {
text += 'ORDER ';
} else if (node.order.includes('REORDER')) {
text += 'REORDER ';
}
if (node.options.length > 0) {
text += node.options.map(e => e.$cstNode?.text).join(' ');
}
if (node.returns.length > 0) {
text += node.returns.map(e => e.$cstNode?.text).join(' ');
}
text += '\n```';
return text;
}

}
17 changes: 17 additions & 0 deletions packages/language/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

export * from './pli-module.js';
export * from './validation/pli-validator.js';
export * from './generated/ast.js';
export * from './generated/grammar.js';
export * from './generated/module.js';
export * from './workspace/pli-builtin-functions.js';
Loading

0 comments on commit 1f0d1c2

Please sign in to comment.