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

Release 1.0.10 #226

Open
wants to merge 3 commits into
base: develop
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: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@madie/cql-antlr-parser",
"version": "1.0.9",
"version": "1.0.10",
"description": "Antlr Parsing of CQL in typescript",
"publishConfig": {
"access": "public"
Expand Down
130 changes: 130 additions & 0 deletions src/util/CustomeErrorConverter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,127 @@
const keyWords: string[] = [
"after",
"aggregate",
"all",
"and",
"as",
"asc",
"ascending",
"before",
"between",
"by",
"called",
"case",
"cast",
"code",
"Code",
"codesystem",
"codesystems",
"collapse",
"concept",
"Concept",
"contains",
"context",
"convert",
"date",
"day",
"days",
"default",
"define",
"desc",
"descending",
"difference",
"display",
"distinct",
"div",
"duration",
"during",
"else",
"end",
"ends",
"except",
"exists",
"expand",
"false",
"flatten",
"fluent",
"from",
"function",
"hour",
"hours",
"if",
"implies",
"in",
"include",
"includes",
"included in",
"intersect",
"Interval",
"is",
"let",
"library",
"List",
"maximum",
"meets",
"millisecond",
"milliseconds",
"minimum",
"minute",
"minutes",
"mod",
"month",
"months",
"not",
"null",
"occurs",
"of",
"on or",
"or",
"or after",
"or before",
"or less",
"or more",
"or on",
"overlaps",
"parameter",
"per",
"point",
"predecessor",
"private",
"properly",
"public",
"return",
"same",
"second",
"seconds",
"singleton",
"start",
"starting",
"starts",
"sort",
"successor",
"such that",
"then",
"time",
"timezoneoffset",
"to",
"true",
"Tuple",
"union",
"using",
"valueset",
"version",
"week",
"weeks",
"where",
"when",
"width",
"with",
"within",
"without",
"xor",
"year",
"years",
];
const convertCustomError = (errorMessage: string): string => {
let convertedMsg: string = errorMessage;
switch (errorMessage) {
Expand All @@ -6,6 +130,12 @@ const convertCustomError = (errorMessage: string): string => {
break;
}
default: {
const findKeyword = errorMessage
.replace(/'/g, "")
.replace("no viable alternative at input define ", "");
if (findKeyword && keyWords.find((kword) => findKeyword === kword)) {
convertedMsg = "Definition names must not be a reserved word.";
}
break;
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/CqlAntlr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
relatedContextRetrieve,
aggregateQuery,
cqlDefineWithNoName,
cqlDefineWithKeyWord,
} from "./testCql";
import { CqlAntlr } from "../src";
import CqlResult from "../src/dto/CqlResult";
Expand Down Expand Up @@ -187,4 +188,13 @@ describe("test antlr", () => {
"Definition is missing a name."
);
});

it("test define with key words", (): void => {
const cqlAntlr = new CqlAntlr(cqlDefineWithKeyWord);
const cqlResult: CqlResult = cqlAntlr.parse();
expect(cqlResult.errors.length).toEqual(1);
expect(cqlResult.errors[0].message).toEqual(
"Definition names must not be a reserved word."
);
});
});
5 changes: 5 additions & 0 deletions test/testCql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ const cqlDefineWithNoName = `
define :
true
`;
const cqlDefineWithKeyWord = `
define on or:
true
`;
export {
simpleDefinitionCql,
fhirTestCql,
Expand All @@ -237,4 +241,5 @@ export {
relatedContextRetrieve,
aggregateQuery,
cqlDefineWithNoName,
cqlDefineWithKeyWord,
};
Loading