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

Add JQL Parser/AST #621

Open
wants to merge 2 commits into
base: master
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ The AST explorer provides following code parsers:
- YAML:
- [yaml][]
- [yaml-ast-parser][]
- JQL:
- [jql-parser][]
- [jql-ast][]

### Experimental / custom syntax

Expand Down Expand Up @@ -198,6 +201,7 @@ are included so you can prototype your own plugins:
[svelte]: https://github.com/sveltejs/svelte
[hyntax]: https://github.com/nik-garmash/hyntax
[java-parser]: https://github.com/jhipster/prettier-java/tree/master/packages/java-parser
[jql-parser]: https://www.npmjs.com/package/@atlassianlabs/jql-parser

### Contributions

Expand Down
2 changes: 1 addition & 1 deletion website/CACHE_BREAKER
Original file line number Diff line number Diff line change
@@ -1 +1 @@
27
28
2 changes: 2 additions & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
},
"dependencies": {
"@angular-eslint/template-parser": "^12.3.0",
"@atlassianlabs/jql-ast": "0.0.1",
"@atlassianlabs/jql-parser": "0.0.1",
"@angular/compiler": "^13.0.1",
"@babel/eslint-parser": "~7.13.0",
"@babel/runtime": "^7.16.3",
Expand Down
2 changes: 2 additions & 0 deletions website/src/components/buttons/CategoryButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const categoryIcon = {
sql: 'fa-database',
webidl: 'fa-th-list',
yaml: 'fa-yc',
'jql-ast': 'fa-database',
'jql-parser': 'fa-database',
};

export default class CategoryButton extends React.Component {
Expand Down
3 changes: 3 additions & 0 deletions website/src/parsers/jql-ast/codeExample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project = JQL and
developer in ("Soney Mathew", "Kyle Painter", "Cristian Casais")
ORDER BY created ASC, duedate DESC
6 changes: 6 additions & 0 deletions website/src/parsers/jql-ast/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'codemirror/mode/sql/sql';

export const id = 'jql-ast';
export const displayName = 'JQL AST';
export const mimeTypes = ['application/json'];
export const fileExtension = 'jql';
9 changes: 9 additions & 0 deletions website/src/parsers/jql-ast/jql-ast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import defaultParserInterface from './utils/defaultJqlAstParserInterface';
import pkg from '@atlassianlabs/jql-ast/package.json';

export default {
...defaultParserInterface(pkg),
loadParser(callback) {
require(['@atlassianlabs/jql-ast'], callback);
},
}
29 changes: 29 additions & 0 deletions website/src/parsers/jql-ast/utils/defaultJqlAstParserInterface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import defaultParserInterface from '../../utils/defaultParserInterface';

export default (pkg) => ({
...defaultParserInterface,
id: pkg.name+pkg.version,
displayName: pkg.name+'@'+pkg.version,
version: '',
locationProps: new Set(['positions','position']),
homepage: "https://www.npmjs.com/package/@atlassianlabs/jql-ast",

parse(jqlParser, code) {
return new jqlParser.JastBuilder().build(code);
},

opensByDefault(node, key) {
return key === 'query';
},

getNodeName(node) {
return node.type;
},

nodeToRange({ position }) {
if (!position) {
return;
}
return [position[0], position[1]];
},
});
3 changes: 3 additions & 0 deletions website/src/parsers/jql-parser/codeExample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project = JQL and
developer in ("Soney Mathew", "Kyle Painter", "Cristian Casais")
ORDER BY created ASC, duedate DESC
6 changes: 6 additions & 0 deletions website/src/parsers/jql-parser/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'codemirror/mode/sql/sql';

export const id = 'jql-parser';
export const displayName = 'JQL Parser';
export const mimeTypes = ['application/json'];
export const fileExtension = 'jql';
62 changes: 62 additions & 0 deletions website/src/parsers/jql-parser/jql-parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import defaultParserInterface from '../utils/defaultParserInterface';
import pkg from '@atlassianlabs/jql-parser/package.json';
import { CharStreams, CommonTokenStream } from 'antlr4ts';

const ID = 'jql-parser';
function traverse(tree, map, lexer) {
const name = tree.constructor.name;
if (name === "TerminalNode") {
const token = tree.symbol;
map["type"] = lexer.vocabulary.getSymbolicName(token.type);
map["text"] = token.text;
map["position"] = { startIndex: token.startIndex, stopIndex: token.stopIndex };
}
else {
const children = [];
map[name] = children;

if (tree.children) {
for (var i = 0; i < tree.children.length; i++) {
const nested = {};
children.push(nested);
traverse(tree.children[i], nested, lexer);
}
}
}
}

export default {
...defaultParserInterface,

id: ID,
displayName: pkg.name,
version: pkg.version,
homepage: 'https://www.npmjs.com/package/@atlassianlabs/jql-parser',
locationProps: new Set(['position']),
typeProps: new Set(['type']),

loadParser(callback) {
require(['@atlassianlabs/jql-parser'], callback);
},

parse(jqlParser, code) {
const chars = CharStreams.fromString(code);
const lexer = new jqlParser.JQLLexer(chars);
const tokenStream = new CommonTokenStream(lexer);
const parser = new jqlParser.JQLParser(tokenStream);
const map = {};
traverse(parser.jqlQuery(), map, lexer)
return map;
},

getNodeName(node) {
return node.type;
},

nodeToRange({ position }) {
if (!position) {
return;
}
return [position.startIndex, position.stopIndex];
},
};
35 changes: 35 additions & 0 deletions website/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
dependencies:
tslib "^2.3.0"

"@atlassianlabs/[email protected]":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@atlassianlabs/jql-ast/-/jql-ast-0.0.1.tgz#22116f4b58a69117a74c5e382bb97305bd9b3afb"
integrity sha512-MTU/ibDIqdKNQKN1QeEXI26RIaPydlCeb4RBLRehaFiqny8ToPwIFIcmn60asUS/dRdPzum07oPIufjEFh/40g==
dependencies:
"@atlassianlabs/jql-parser" "^0.0.1"
"@babel/runtime" "^7.15.4"
antlr4ts "^0.5.0-alpha.3"
memoize-one "^5.1.1"

"@atlassianlabs/[email protected]", "@atlassianlabs/jql-parser@^0.0.1":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@atlassianlabs/jql-parser/-/jql-parser-0.0.1.tgz#529bb5b05062f8e1953885e97b5b2de7a0804098"
integrity sha512-ukuR58r6jNUSUiQ3F0rypVHPeYSwuLaLtjOcopWP8tRIPg65vLbTPbg3v1YSsKarx56m175UKJoN6y3QcZA+9A==
dependencies:
"@babel/runtime" "^7.15.4"
antlr4ts "^0.5.0-alpha.3"

"@babel/[email protected]":
version "7.0.0-beta.44"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.44.tgz#2a02643368de80916162be70865c97774f3adbd9"
Expand Down Expand Up @@ -1285,6 +1303,13 @@
dependencies:
regenerator-runtime "^0.13.4"

"@babel/runtime@^7.15.4":
version "7.16.3"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.16.3.tgz#b86f0db02a04187a3c17caa77de69840165d42d5"
integrity sha512-WBwekcqacdY2e9AF/Q7WLFUWmdJGJTkbjqTjoMDgXkVZ3ZRUvOPsLb5KdwISoQVsbP+DQzVZW4Zhci0DvpbNTQ==
dependencies:
regenerator-runtime "^0.13.4"

"@babel/runtime@^7.5.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7":
version "7.14.0"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.14.0.tgz#46794bc20b612c5f75e62dd071e24dfd95f1cbe6"
Expand Down Expand Up @@ -2178,6 +2203,11 @@ ansi-styles@^4.1.0:
"@types/color-name" "^1.1.1"
color-convert "^2.0.1"

antlr4ts@^0.5.0-alpha.3:
version "0.5.0-alpha.4"
resolved "https://registry.yarnpkg.com/antlr4ts/-/antlr4ts-0.5.0-alpha.4.tgz#71702865a87478ed0b40c0709f422cf14d51652a"
integrity sha512-WPQDt1B74OfPv/IMS2ekXAKkTZIHl88uMetg6q3OTqgFxZ/dxDXI0EWLyZid/1Pe6hTftyg5N7gel5wNAGxXyQ==

anymatch@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-2.0.0.tgz#bcb24b4f37934d9aa7ac17b4adaf89e7c76ef2eb"
Expand Down Expand Up @@ -8077,6 +8107,11 @@ mem@^4.0.0:
mimic-fn "^2.0.0"
p-is-promise "^2.0.0"

memoize-one@^5.1.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.2.1.tgz#8337aa3c4335581839ec01c3d594090cebe8f00e"
integrity sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==

memory-fs@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.2.0.tgz#f2bb25368bc121e391c2520de92969caee0a0290"
Expand Down