Skip to content

Commit

Permalink
Merge pull request #229 from MeasureAuthoringTool/MAT-7998_updatErrMs…
Browse files Browse the repository at this point in the history
…gWhenDefineNameIsKeyword

Release 1.0.10
  • Loading branch information
adongare authored Dec 27, 2024
2 parents ead748c + aa0cee9 commit 6e394b1
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 3 deletions.
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,
};

0 comments on commit 6e394b1

Please sign in to comment.