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

WIP: Update initial ECLGrammar plumbing #359

Draft
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/.eclcc
/dist*
/ecl-sample/.vscode/settings.json
/grammar
/grammar/ecl/.*
/grammar/kel/.*
/grammar/kel/*.g4
/grammar/salt/.*
/grammar/salt/*.g4
/grammar/*.jar
/images
/lib*
/node_modules
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceRoot}",
"${workspaceRoot}\\ecl-sample"
"${workspaceRoot}/ecl-sample"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
Expand All @@ -47,7 +47,7 @@
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"${workspaceRoot}\\ecl-sample"
"${workspaceRoot}/ecl-sample"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
Expand Down
4 changes: 4 additions & 0 deletions grammar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ANTLR Notes

Latest Antlr 4.x: https://www.antlr.org/download.html
* antlr-4.9.3-complete.jar
46 changes: 46 additions & 0 deletions grammar/ecl/ECLLexer.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
lexer grammar ECLLexer;

channels {
WS_CHANNEL
}

WS: [ t]+ -> channel(WS_CHANNEL);
NL: ('rn' | 'r' | 'n') -> channel(WS_CHANNEL);

// Calc ---------------------------------------------

INPUT_KW: 'input';
OUTPUT_KW: 'output';

NUMBER_LIT: ('0' | [1-9][0-9]*) ('.' [0-9]+)?;

ID: [a-zA-Z][a-zA-Z0-9_]*;

LPAREN: '(';
RPAREN: ')';
EQUAL: '=';
MINUS: '-';
PLUS: '+';
MUL: '*';
DIV: '/';

UNRECOGNIZED: .;

// ECL ---------------------------------------------

LETTER: [a-zA-Z];
DIGIT: [0-9];
BINDIGIT: [0-1];
HEXDIGIT: [a-fA-F0-9];
ALPHANUM: [a-zA-Z$0-9];
ALPHANUMCOLON: [a-zA-Z$0-9:@];
BLANK: [ \t\r];
SLASH: [/];
STAR: [*];
PERCENT: [%];
LCURLY: [{];
RCURLY: [}];
DOT: [.];
HEXPAIRS: (HEXDIGIT HEXDIGIT)+;
ERR_HEXPAIRS: HEXDIGIT (HEXDIGIT HEXDIGIT)*;
XPATHSEQ: ([^}\r\n])+;
28 changes: 28 additions & 0 deletions grammar/ecl/ECLParser.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
parser grammar ECLParser;

options {
tokenVocab = ECLLexer;
}

// Calc ---------------------------------------------

compilationUnit:
(inputs += input)* (calcs += calc)* (outputs += output)* EOF;

input: INPUT_KW ID;

output: OUTPUT_KW ID;

calc: target = ID EQUAL value = expression;

expression:
NUMBER_LIT
| ID
| LPAREN expression RPAREN
| expression operator = (MUL | DIV) expression
| expression operator = (MINUS | PLUS) expression
| MINUS expression;

// ECL ---------------------------------------------

// TODO
5 changes: 5 additions & 0 deletions grammar/ecl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ECL Simple Grammar

See:
* [lexer](https://github.com/hpcc-systems/HPCC-Platform/blob/master/ecl/hql/hqllex.l)
* [grammar](https://github.com/hpcc-systems/HPCC-Platform/blob/master/ecl/hql/hqlgram.y)
3 changes: 3 additions & 0 deletions grammar/kel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Grammar file from: https://github.com/hpcc-systems/KEL/tree/master/kel/src/main/antlr4/org/hpccsystems/kel/parse
* KELLexer.g4
* KELParser.g4
2 changes: 2 additions & 0 deletions grammar/salt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Grammar file from: https://github.com/hpcc-systems/SALT/blob/master/SALT/src/main/java/com/relx/rba/tardis/salt/antlr
* Salt.g4
21 changes: 16 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"scripts": {
"clean": "rimraf --glob out lib* dist types hpcc-systems.ecl.vsix",
"copy-resources": "copyfiles -f ./node_modules/@hpcc-js/ddl-shim/schema/v2.json ./dist",
"gen-grammar": "wsl -e ./scripts/grammar-generate.sh",
"gen-grammar": "run-script-os",
"gen-grammar:win32": "wsl -e ./scripts/grammar-generate.sh",
"gen-grammar:linux": "./scripts/grammar-generate.sh",
"gen-nls": "node ./lib-util/index.js",
"compile": "tsc",
"compile-watch": "npm run compile -- -watch",
Expand Down Expand Up @@ -80,7 +82,7 @@
"@vscode/vsce": "2.21.0",
"acorn-walk": "8.2.0",
"adm-zip": "0.5.10",
"antlr4": "4.11.0",
"antlr4": "4.13.1",
"assert": "2.1.0",
"browserify-zlib": "0.2.0",
"buffer": "6.0.3",
Expand All @@ -100,6 +102,7 @@
"rollup": "3.29.1",
"rollup-plugin-postcss": "4.0.2",
"rollup-plugin-sourcemaps": "0.6.3",
"run-script-os": "^1.1.6",
"source-map-loader": "4.0.1",
"standard-version": "9.5.0",
"stream-browserify": "3.0.0",
Expand Down Expand Up @@ -1336,4 +1339,4 @@
}
]
}
}
}
19 changes: 15 additions & 4 deletions scripts/grammar-generate.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
#!/bin/bash

ANTLR_VER=4.13.1

cd ./grammar/ecl
java -jar ../antlr-${ANTLR_VER}-complete.jar -Dlanguage=TypeScript -o ../../src/grammar/ecl -visitor -Xexact-output-dir ./*.g4
cd ../..

cd ./grammar/kel
java -jar ../antlr-4.10.1-complete.jar -Dlanguage=JavaScript -o ../../src/grammar/kel -visitor -Xexact-output-dir ./*.g4
if ls *.g4 >/dev/null 2>&1; then
java -jar ../antlr-${ANTLR_VER}-complete.jar -Dlanguage=TypeScript -o ../../src/grammar/kel -visitor -Xexact-output-dir ./*.g4
fi
cd ../..

cd ./grammar/salt
java -jar ../antlr-4.10.1-complete.jar -Dlanguage=JavaScript -o ../../src/grammar/salt -visitor -Xexact-output-dir ./*.g4

if ls *.g4 >/dev/null 2>&1; then
java -jar ../antlr-${ANTLR_VER}-complete.jar -Dlanguage=TypeScript -o ../../src/grammar/salt -visitor -Xexact-output-dir ./*.g4
fi
cd ../..

# cd ./grammar/dude
# java -jar ../antlr-4.10.1-complete.jar -Dlanguage=JavaScript -o ../../src/grammar/dude -visitor -Xexact-output-dir ./*.g4
# java -jar ../antlr-${ANTLR_VER}-complete.jar -Dlanguage=TypeScript -o ../../src/grammar/dude -visitor -Xexact-output-dir ./*.g4
# cd ../..

# cd ./grammar/trixe
# java -jar ../antlr-4.10.1-complete.jar -Dlanguage=JavaScript -o ../../src/grammar/trixe -visitor -Xexact-output-dir ./*.g4
# java -jar ../antlr-${ANTLR_VER}-complete.jar -Dlanguage=TypeScript -o ../../src/grammar/trixe -visitor -Xexact-output-dir ./*.g4
# cd ../..
Loading
Loading