aurora-langium 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +4 -0
- package/out/cli/cli-util.d.ts +9 -0
- package/out/cli/cli-util.js +39 -0
- package/out/cli/cli-util.js.map +1 -0
- package/out/cli/generator.d.ts +2 -0
- package/out/cli/generator.js +19 -0
- package/out/cli/generator.js.map +1 -0
- package/out/cli/main.d.ts +5 -0
- package/out/cli/main.js +32 -0
- package/out/cli/main.js.map +1 -0
- package/out/extension/main.cjs +18109 -0
- package/out/extension/main.cjs.map +7 -0
- package/out/extension/main.d.ts +3 -0
- package/out/extension/main.js +37 -0
- package/out/extension/main.js.map +1 -0
- package/out/language/aurora-module.d.ts +41 -0
- package/out/language/aurora-module.js +42 -0
- package/out/language/aurora-module.js.map +1 -0
- package/out/language/aurora-validator.d.ts +13 -0
- package/out/language/aurora-validator.js +25 -0
- package/out/language/aurora-validator.js.map +1 -0
- package/out/language/generated/ast.d.ts +249 -0
- package/out/language/generated/ast.js +375 -0
- package/out/language/generated/ast.js.map +1 -0
- package/out/language/generated/grammar.d.ts +6 -0
- package/out/language/generated/grammar.js +2436 -0
- package/out/language/generated/grammar.js.map +1 -0
- package/out/language/generated/module.d.ts +12 -0
- package/out/language/generated/module.js +20 -0
- package/out/language/generated/module.js.map +1 -0
- package/out/language/main.cjs +33292 -0
- package/out/language/main.cjs.map +7 -0
- package/out/language/main.d.ts +1 -0
- package/out/language/main.js +11 -0
- package/out/language/main.js.map +1 -0
- package/package.json +81 -0
- package/src/cli/cli-util.ts +51 -0
- package/src/cli/generator.ts +22 -0
- package/src/cli/main.ts +42 -0
- package/src/extension/main.ts +51 -0
- package/src/language/aurora-module.ts +68 -0
- package/src/language/aurora-validator.ts +31 -0
- package/src/language/aurora.langium +130 -0
- package/src/language/generated/ast.ts +668 -0
- package/src/language/generated/grammar.ts +2438 -0
- package/src/language/generated/module.ts +24 -0
- package/src/language/main.ts +13 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { startLanguageServer } from 'langium/lsp';
|
|
2
|
+
import { NodeFileSystem } from 'langium/node';
|
|
3
|
+
import { createConnection, ProposedFeatures } from 'vscode-languageserver/node.js';
|
|
4
|
+
import { createAuroraServices } from './aurora-module.js';
|
|
5
|
+
// Create a connection to the client
|
|
6
|
+
const connection = createConnection(ProposedFeatures.all);
|
|
7
|
+
// Inject the shared services and language-specific services
|
|
8
|
+
const { shared } = createAuroraServices(Object.assign({ connection }, NodeFileSystem));
|
|
9
|
+
// Start the language server with the shared services
|
|
10
|
+
startLanguageServer(shared);
|
|
11
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/language/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D,oCAAoC;AACpC,MAAM,UAAU,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;AAE1D,4DAA4D;AAC5D,MAAM,EAAE,MAAM,EAAE,GAAG,oBAAoB,iBAAG,UAAU,IAAK,cAAc,EAAG,CAAC;AAE3E,qDAAqD;AACrD,mBAAmB,CAAC,MAAM,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aurora-langium",
|
|
3
|
+
"description": "It containes the DSL named Aurora",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"files": [
|
|
6
|
+
"bin",
|
|
7
|
+
"out",
|
|
8
|
+
"src"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc -b tsconfig.src.json && node esbuild.mjs",
|
|
13
|
+
"watch": "concurrently -n tsc,esbuild -c blue,yellow \"tsc -b tsconfig.src.json --watch\" \"node esbuild.mjs --watch\"",
|
|
14
|
+
"lint": "eslint src --ext ts",
|
|
15
|
+
"langium:generate": "langium generate",
|
|
16
|
+
"langium:watch": "langium generate --watch",
|
|
17
|
+
"vscode:prepublish": "npm run build && npm run lint",
|
|
18
|
+
"test": "vitest run"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"langium": "~3.2.0",
|
|
22
|
+
"vscode-languageclient": "~9.0.1",
|
|
23
|
+
"vscode-languageserver": "~9.0.1",
|
|
24
|
+
"chalk": "~5.3.0",
|
|
25
|
+
"commander": "~11.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^18.0.0",
|
|
29
|
+
"@typescript-eslint/parser": "~7.3.1",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "~7.3.1",
|
|
31
|
+
"eslint": "~8.57.0",
|
|
32
|
+
"langium-cli": "~3.2.0",
|
|
33
|
+
"typescript": "~5.1.6",
|
|
34
|
+
"@types/vscode": "~1.67.0",
|
|
35
|
+
"concurrently": "~8.2.1",
|
|
36
|
+
"esbuild": "~0.20.2",
|
|
37
|
+
"vitest": "~1.4.0"
|
|
38
|
+
},
|
|
39
|
+
"volta": {
|
|
40
|
+
"node": "18.19.1",
|
|
41
|
+
"npm": "10.2.4"
|
|
42
|
+
},
|
|
43
|
+
"displayName": "aurora-langium",
|
|
44
|
+
"engines": {
|
|
45
|
+
"vscode": "^1.67.0",
|
|
46
|
+
"node": ">=18.0.0"
|
|
47
|
+
},
|
|
48
|
+
"categories": [
|
|
49
|
+
"Programming Languages"
|
|
50
|
+
],
|
|
51
|
+
"contributes": {
|
|
52
|
+
"languages": [
|
|
53
|
+
{
|
|
54
|
+
"id": "aurora",
|
|
55
|
+
"aliases": [
|
|
56
|
+
"Aurora",
|
|
57
|
+
"aurora"
|
|
58
|
+
],
|
|
59
|
+
"extensions": [".aurora"],
|
|
60
|
+
"configuration": "./language-configuration.json"
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"grammars": [
|
|
64
|
+
{
|
|
65
|
+
"language": "aurora",
|
|
66
|
+
"scopeName": "source.aurora",
|
|
67
|
+
"path": "syntaxes/aurora.tmLanguage.json"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
"activationEvents": [
|
|
72
|
+
"onLanguage:aurora"
|
|
73
|
+
],
|
|
74
|
+
"main": "./out/extension/main.cjs",
|
|
75
|
+
"bin": {
|
|
76
|
+
"aurora-cli": "./bin/cli.js"
|
|
77
|
+
},
|
|
78
|
+
"author": {
|
|
79
|
+
"name": "Aurora Constellations"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { AstNode, LangiumCoreServices, LangiumDocument } from 'langium';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import { URI } from 'langium';
|
|
6
|
+
|
|
7
|
+
export async function extractDocument(fileName: string, services: LangiumCoreServices): Promise<LangiumDocument> {
|
|
8
|
+
const extensions = services.LanguageMetaData.fileExtensions;
|
|
9
|
+
if (!extensions.includes(path.extname(fileName))) {
|
|
10
|
+
console.error(chalk.yellow(`Please choose a file with one of these extensions: ${extensions}.`));
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!fs.existsSync(fileName)) {
|
|
15
|
+
console.error(chalk.red(`File ${fileName} does not exist.`));
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const document = await services.shared.workspace.LangiumDocuments.getOrCreateDocument(URI.file(path.resolve(fileName)));
|
|
20
|
+
await services.shared.workspace.DocumentBuilder.build([document], { validation: true });
|
|
21
|
+
|
|
22
|
+
const validationErrors = (document.diagnostics ?? []).filter(e => e.severity === 1);
|
|
23
|
+
if (validationErrors.length > 0) {
|
|
24
|
+
console.error(chalk.red('There are validation errors:'));
|
|
25
|
+
for (const validationError of validationErrors) {
|
|
26
|
+
console.error(chalk.red(
|
|
27
|
+
`line ${validationError.range.start.line + 1}: ${validationError.message} [${document.textDocument.getText(validationError.range)}]`
|
|
28
|
+
));
|
|
29
|
+
}
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return document;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function extractAstNode<T extends AstNode>(fileName: string, services: LangiumCoreServices): Promise<T> {
|
|
37
|
+
return (await extractDocument(fileName, services)).parseResult?.value as T;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface FilePathData {
|
|
41
|
+
destination: string,
|
|
42
|
+
name: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function extractDestinationAndName(filePath: string, destination: string | undefined): FilePathData {
|
|
46
|
+
filePath = path.basename(filePath, path.extname(filePath)).replace(/[.-]/g, '');
|
|
47
|
+
return {
|
|
48
|
+
destination: destination ?? path.join(path.dirname(filePath), 'generated'),
|
|
49
|
+
name: path.basename(filePath)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PCM } from '../language/generated/ast.js';
|
|
2
|
+
import { expandToNode, joinToNode, toString } from 'langium/generate';
|
|
3
|
+
import * as fs from 'node:fs';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import { extractDestinationAndName } from './cli-util.js';
|
|
6
|
+
|
|
7
|
+
export function generateJavaScript(model: PCM, filePath: string, destination: string | undefined): string {
|
|
8
|
+
const data = extractDestinationAndName(filePath, destination);
|
|
9
|
+
const generatedFilePath = `${path.join(data.destination, data.name)}.js`;
|
|
10
|
+
|
|
11
|
+
const fileNode = expandToNode`
|
|
12
|
+
"use strict";
|
|
13
|
+
|
|
14
|
+
${joinToNode(model.imports, greeting => `console.log('Hello, ${greeting.importedNamespace}!');`, { appendNewLineIfNotEmpty: true })}
|
|
15
|
+
`.appendNewLineIfNotEmpty();
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(data.destination)) {
|
|
18
|
+
fs.mkdirSync(data.destination, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
fs.writeFileSync(generatedFilePath, toString(fileNode));
|
|
21
|
+
return generatedFilePath;
|
|
22
|
+
}
|
package/src/cli/main.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { PCM } from '../language/generated/ast.js';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import { AuroraLanguageMetaData } from '../language/generated/module.js';
|
|
5
|
+
import { createAuroraServices } from '../language/aurora-module.js';
|
|
6
|
+
import { extractAstNode } from './cli-util.js';
|
|
7
|
+
import { generateJavaScript } from './generator.js';
|
|
8
|
+
import { NodeFileSystem } from 'langium/node';
|
|
9
|
+
import * as url from 'node:url';
|
|
10
|
+
import * as fs from 'node:fs/promises';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
13
|
+
|
|
14
|
+
const packagePath = path.resolve(__dirname, '..', '..', 'package.json');
|
|
15
|
+
const packageContent = await fs.readFile(packagePath, 'utf-8');
|
|
16
|
+
|
|
17
|
+
export const generateAction = async (fileName: string, opts: GenerateOptions): Promise<void> => {
|
|
18
|
+
const services = createAuroraServices(NodeFileSystem).Aurora;
|
|
19
|
+
const PCM = await extractAstNode<PCM>(fileName, services);
|
|
20
|
+
const generatedFilePath = generateJavaScript(PCM, fileName, opts.destination);
|
|
21
|
+
console.log(chalk.green(`JavaScript code generated successfully: ${generatedFilePath}`));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type GenerateOptions = {
|
|
25
|
+
destination?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default function(): void {
|
|
29
|
+
const program = new Command();
|
|
30
|
+
|
|
31
|
+
program.version(JSON.parse(packageContent).version);
|
|
32
|
+
|
|
33
|
+
const fileExtensions = AuroraLanguageMetaData.fileExtensions.join(', ');
|
|
34
|
+
program
|
|
35
|
+
.command('generate')
|
|
36
|
+
.argument('<file>', `source file (possible file extensions: ${fileExtensions})`)
|
|
37
|
+
.option('-d, --destination <dir>', 'destination directory of generating')
|
|
38
|
+
.description('generates JavaScript code that prints "Hello, {name}!" for each greeting in a source file')
|
|
39
|
+
.action(generateAction);
|
|
40
|
+
|
|
41
|
+
program.parse(process.argv);
|
|
42
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { LanguageClientOptions, ServerOptions} from 'vscode-languageclient/node.js';
|
|
2
|
+
import type * as vscode from 'vscode';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { LanguageClient, TransportKind } from 'vscode-languageclient/node.js';
|
|
5
|
+
|
|
6
|
+
let client: LanguageClient;
|
|
7
|
+
|
|
8
|
+
// This function is called when the extension is activated.
|
|
9
|
+
export function activate(context: vscode.ExtensionContext): void {
|
|
10
|
+
client = startLanguageClient(context);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// This function is called when the extension is deactivated.
|
|
14
|
+
export function deactivate(): Thenable<void> | undefined {
|
|
15
|
+
if (client) {
|
|
16
|
+
return client.stop();
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function startLanguageClient(context: vscode.ExtensionContext): LanguageClient {
|
|
22
|
+
const serverModule = context.asAbsolutePath(path.join('out', 'language', 'main.cjs'));
|
|
23
|
+
// The debug options for the server
|
|
24
|
+
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging.
|
|
25
|
+
// By setting `process.env.DEBUG_BREAK` to a truthy value, the language server will wait until a debugger is attached.
|
|
26
|
+
const debugOptions = { execArgv: ['--nolazy', `--inspect${process.env.DEBUG_BREAK ? '-brk' : ''}=${process.env.DEBUG_SOCKET || '6009'}`] };
|
|
27
|
+
|
|
28
|
+
// If the extension is launched in debug mode then the debug server options are used
|
|
29
|
+
// Otherwise the run options are used
|
|
30
|
+
const serverOptions: ServerOptions = {
|
|
31
|
+
run: { module: serverModule, transport: TransportKind.ipc },
|
|
32
|
+
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Options to control the language client
|
|
36
|
+
const clientOptions: LanguageClientOptions = {
|
|
37
|
+
documentSelector: [{ scheme: '*', language: 'aurora' }]
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Create the language client and start the client.
|
|
41
|
+
const client = new LanguageClient(
|
|
42
|
+
'aurora',
|
|
43
|
+
'Aurora',
|
|
44
|
+
serverOptions,
|
|
45
|
+
clientOptions
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// Start the client. This will also launch the server
|
|
49
|
+
client.start();
|
|
50
|
+
return client;
|
|
51
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type Module, inject } from 'langium';
|
|
2
|
+
import { createDefaultModule, createDefaultSharedModule, type DefaultSharedModuleContext, type LangiumServices, type LangiumSharedServices, type PartialLangiumServices } from 'langium/lsp';
|
|
3
|
+
import { AuroraGeneratedModule, AuroraGeneratedSharedModule } from './generated/module.js';
|
|
4
|
+
import { AuroraValidator, registerValidationChecks } from './aurora-validator.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Declaration of custom services - add your own service classes here.
|
|
8
|
+
*/
|
|
9
|
+
export type AuroraAddedServices = {
|
|
10
|
+
validation: {
|
|
11
|
+
AuroraValidator: AuroraValidator
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Union of Langium default services and your custom services - use this as constructor parameter
|
|
17
|
+
* of custom service classes.
|
|
18
|
+
*/
|
|
19
|
+
export type AuroraServices = LangiumServices & AuroraAddedServices
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Dependency injection module that overrides Langium default services and contributes the
|
|
23
|
+
* declared custom services. The Langium defaults can be partially specified to override only
|
|
24
|
+
* selected services, while the custom services must be fully specified.
|
|
25
|
+
*/
|
|
26
|
+
export const AuroraModule: Module<AuroraServices, PartialLangiumServices & AuroraAddedServices> = {
|
|
27
|
+
validation: {
|
|
28
|
+
AuroraValidator: () => new AuroraValidator()
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create the full set of services required by Langium.
|
|
34
|
+
*
|
|
35
|
+
* First inject the shared services by merging two modules:
|
|
36
|
+
* - Langium default shared services
|
|
37
|
+
* - Services generated by langium-cli
|
|
38
|
+
*
|
|
39
|
+
* Then inject the language-specific services by merging three modules:
|
|
40
|
+
* - Langium default language-specific services
|
|
41
|
+
* - Services generated by langium-cli
|
|
42
|
+
* - Services specified in this file
|
|
43
|
+
*
|
|
44
|
+
* @param context Optional module context with the LSP connection
|
|
45
|
+
* @returns An object wrapping the shared services and the language-specific services
|
|
46
|
+
*/
|
|
47
|
+
export function createAuroraServices(context: DefaultSharedModuleContext): {
|
|
48
|
+
shared: LangiumSharedServices,
|
|
49
|
+
Aurora: AuroraServices
|
|
50
|
+
} {
|
|
51
|
+
const shared = inject(
|
|
52
|
+
createDefaultSharedModule(context),
|
|
53
|
+
AuroraGeneratedSharedModule
|
|
54
|
+
);
|
|
55
|
+
const Aurora = inject(
|
|
56
|
+
createDefaultModule({ shared }),
|
|
57
|
+
AuroraGeneratedModule,
|
|
58
|
+
AuroraModule
|
|
59
|
+
);
|
|
60
|
+
shared.ServiceRegistry.register(Aurora);
|
|
61
|
+
registerValidationChecks(Aurora);
|
|
62
|
+
if (!context.connection) {
|
|
63
|
+
// We don't run inside a language server
|
|
64
|
+
// Therefore, initialize the configuration provider instantly
|
|
65
|
+
shared.workspace.ConfigurationProvider.initialized({});
|
|
66
|
+
}
|
|
67
|
+
return { shared, Aurora };
|
|
68
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ValidationAcceptor, ValidationChecks } from 'langium';
|
|
2
|
+
import type { AuroraAstType, IssueCoordinate } from './generated/ast.js';
|
|
3
|
+
import type { AuroraServices } from './aurora-module.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Register custom validation checks.
|
|
7
|
+
*/
|
|
8
|
+
export function registerValidationChecks(services: AuroraServices) {
|
|
9
|
+
const registry = services.validation.ValidationRegistry;
|
|
10
|
+
const validator = services.validation.AuroraValidator;
|
|
11
|
+
const checks: ValidationChecks<AuroraAstType> = {
|
|
12
|
+
IssueCoordinate: validator.checkIssueCoordinateStartsWithCapital
|
|
13
|
+
};
|
|
14
|
+
registry.register(checks, validator);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Implementation of custom validations.
|
|
19
|
+
*/
|
|
20
|
+
export class AuroraValidator {
|
|
21
|
+
|
|
22
|
+
checkIssueCoordinateStartsWithCapital(issueCoordinate: IssueCoordinate, accept: ValidationAcceptor): void {
|
|
23
|
+
if (issueCoordinate.name) {
|
|
24
|
+
const firstChar = issueCoordinate.name.substring(0, 1);
|
|
25
|
+
if (firstChar.toUpperCase() !== firstChar) {
|
|
26
|
+
accept('warning', 'IssueCoordinate should start with a capital.', { node: issueCoordinate, property: 'name' });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
grammar Aurora
|
|
2
|
+
|
|
3
|
+
entry PCM:
|
|
4
|
+
package=PACKAGE ?
|
|
5
|
+
imports+=Import *
|
|
6
|
+
module=MODULE ?
|
|
7
|
+
template=TEMPLATE ?
|
|
8
|
+
elements+=(Issues | Orders | Clinical)*
|
|
9
|
+
;
|
|
10
|
+
|
|
11
|
+
/* Package and Import */
|
|
12
|
+
PACKAGE:'package' name=QualifiedName ';';
|
|
13
|
+
Import: 'import' importedNamespace=QualifiedNameWithWildcard ';';
|
|
14
|
+
QualifiedNameWithWildcard returns string: QualifiedName '.*'?;
|
|
15
|
+
QualifiedName returns string: ID ('.' ID )*;
|
|
16
|
+
NL_STATEMENT:
|
|
17
|
+
name=( NL_STATEMENTMULTI | SINGLENL );
|
|
18
|
+
Clinical:
|
|
19
|
+
'Clinical:'
|
|
20
|
+
narrative+=NL_STATEMENT*
|
|
21
|
+
namedGroups+=NamedGroupClinical*;
|
|
22
|
+
|
|
23
|
+
NamedGroupClinical:
|
|
24
|
+
name=ID_WITH_COLON
|
|
25
|
+
timestamp=TimeStamp ?
|
|
26
|
+
('('refs+=[ReferenceCoordinate:ID] (',' refs+=[ReferenceCoordinate:ID])* ')')?
|
|
27
|
+
narrative+=NL_STATEMENT *
|
|
28
|
+
coord+=(ClinicalCoordinate | ClinicalValue )*
|
|
29
|
+
;
|
|
30
|
+
|
|
31
|
+
ClinicalCoordinate:
|
|
32
|
+
qu+=QU *
|
|
33
|
+
timestamp=TimeStamp ?
|
|
34
|
+
name=ID
|
|
35
|
+
('('refs+=[ReferenceCoordinate:ID] (',' refs+=[ReferenceCoordinate:ID])* ')')?
|
|
36
|
+
narrative+=NL_STATEMENT *
|
|
37
|
+
;
|
|
38
|
+
|
|
39
|
+
ClinicalValue:
|
|
40
|
+
qu+=QU *
|
|
41
|
+
timestamp=TimeStamp ?
|
|
42
|
+
name=ID
|
|
43
|
+
'['
|
|
44
|
+
values+=SingleValueUnit
|
|
45
|
+
(',' values+=SingleValueUnit )*
|
|
46
|
+
']'
|
|
47
|
+
('('refs+=[ReferenceCoordinate:ID] (',' refs+=[ReferenceCoordinate:ID])* ')')?
|
|
48
|
+
narrative+=NL_STATEMENT *
|
|
49
|
+
;
|
|
50
|
+
|
|
51
|
+
/* Value Unit */
|
|
52
|
+
SingleValueUnit :
|
|
53
|
+
negative='(-)' ?
|
|
54
|
+
value=(ID | INT | Float | Fraction | Boolean )
|
|
55
|
+
unit=(ID | INT | Float | Fraction | Boolean | '_' )
|
|
56
|
+
;
|
|
57
|
+
|
|
58
|
+
Fraction returns string: INT '/' INT;
|
|
59
|
+
Boolean returns string: 'y' | 'n' ;
|
|
60
|
+
Float returns string: INT '.' INT ;
|
|
61
|
+
|
|
62
|
+
TimeStamp:
|
|
63
|
+
'@' ((empty="time" ) | (date=AuroraDate | time=Time )| (date=AuroraDate time=Time ) )
|
|
64
|
+
;
|
|
65
|
+
|
|
66
|
+
Issues:
|
|
67
|
+
'Issues:'
|
|
68
|
+
narrative+=NL_STATEMENT*
|
|
69
|
+
coord+=IssueCoordinate*;
|
|
70
|
+
|
|
71
|
+
IssueCoordinate:
|
|
72
|
+
comment+= ML_COMMENT*
|
|
73
|
+
qu += QU*
|
|
74
|
+
name=ID
|
|
75
|
+
('('refs+=[ReferenceCoordinate:ID] (',' refs+=[ReferenceCoordinate:ID])* ')')?
|
|
76
|
+
(':' snomed=Snomed)?
|
|
77
|
+
('from' mods+=[MODULE:ID] (',' mods+=[MODULE:ID])*
|
|
78
|
+
('with' temps+=[TEMPLATE: ID] (',' temps+=[TEMPLATE:ID])*)? )?
|
|
79
|
+
narrative+=NL_STATEMENT*
|
|
80
|
+
;
|
|
81
|
+
|
|
82
|
+
ReferenceCoordinate: (IssueCoordinate | OrderCoordinate | ClinicalCoordinate);
|
|
83
|
+
|
|
84
|
+
Orders:
|
|
85
|
+
'Orders:'
|
|
86
|
+
narrative+=NL_STATEMENT*
|
|
87
|
+
(namedGroups+=NamedGroupOrder)*;
|
|
88
|
+
|
|
89
|
+
NamedGroupOrder:
|
|
90
|
+
comment+= ML_COMMENT*
|
|
91
|
+
qu += QU*
|
|
92
|
+
name=ID_WITH_COLON
|
|
93
|
+
('('refs+=[ReferenceCoordinate:ID] (',' refs+=[ReferenceCoordinate:ID])* ')')?
|
|
94
|
+
narrative+=NL_STATEMENT *
|
|
95
|
+
(orders+=(OrderCoordinate | MutuallyExclusive))*;
|
|
96
|
+
|
|
97
|
+
OrderCoordinate:
|
|
98
|
+
comment+= ML_COMMENT*
|
|
99
|
+
qu += QU*
|
|
100
|
+
name=ID
|
|
101
|
+
('('refs+=[ReferenceCoordinate:ID] (',' refs+=[ReferenceCoordinate:ID])* ')')?
|
|
102
|
+
narrative+= NL_STATEMENT* ;
|
|
103
|
+
|
|
104
|
+
MutuallyExclusive:
|
|
105
|
+
comment+= ML_COMMENT*
|
|
106
|
+
order1=OrderCoordinate 'or' order2=OrderCoordinate;
|
|
107
|
+
|
|
108
|
+
/* Template and Module */
|
|
109
|
+
TEMPLATE: "template" name=ID elements+=(Clinical | Orders)*;
|
|
110
|
+
MODULE: "module:" name=ID elements+=(Issues | Orders)*;
|
|
111
|
+
|
|
112
|
+
AuroraDate returns string:INT '/' INT '/' INT | INT | INT '/' INT;
|
|
113
|
+
Time returns string: INT ':' INT ;
|
|
114
|
+
QU: query=QUTERMINAL;
|
|
115
|
+
|
|
116
|
+
Snomed:name=ID;
|
|
117
|
+
|
|
118
|
+
terminal PREFIXSINGLE : ('-') ('?' | '!' | '.' | 'x' )? ;
|
|
119
|
+
terminal PREFIXMULTI :('--' | '??' | '!!' | '..' | 'xx' );
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
terminal NL_STATEMENTMULTI returns string: PREFIXMULTI -> ';' ;
|
|
123
|
+
terminal ID_WITH_COLON: /[a-zA-Z0-9_]+:/;
|
|
124
|
+
terminal ID: /[a-zA-Z0-9_]+/;
|
|
125
|
+
terminal SINGLENL returns string: /-(\??|\.\?|!|x)?([^\n]*)/;
|
|
126
|
+
terminal INT: /[0-9]+/;
|
|
127
|
+
terminal ML_COMMENT returns string:'/*' -> '*/' ;
|
|
128
|
+
terminal SL_COMMENT returns string:'//' !('\n' | '\r' )('\r'? '\n' )? ;
|
|
129
|
+
hidden terminal WS: /\s+/;
|
|
130
|
+
terminal QUTERMINAL returns string:('?' | '!' | '*' | '~' );
|