Skip to content

Commit

Permalink
Merge pull request #222 from MeasureAuthoringTool/MAT-7995_updateErro…
Browse files Browse the repository at this point in the history
…rMsgWhenDefineLacksName

Mat 7995 update error msg when define lacks name
  • Loading branch information
sb-cecilialiu authored Dec 17, 2024
2 parents f40b5c0 + 33cf094 commit c9ebb35
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 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.8",
"version": "1.0.9",
"description": "Antlr Parsing of CQL in typescript",
"publishConfig": {
"access": "public"
Expand Down
3 changes: 2 additions & 1 deletion src/CustomErrorListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Recognizer } from "antlr4ts/Recognizer";
import { Token } from "antlr4ts/Token";
import { ParserATNSimulator } from "antlr4ts/atn/ParserATNSimulator";
import CqlResult from "./dto/CqlResult";
import convertCustomError from "./util/CustomeErrorConverter";

/**
* Fires on grammar errors.
Expand Down Expand Up @@ -32,7 +33,7 @@ export default class CustomErrorListener implements ANTLRErrorListener<Token> {
1, // plus 1 to ensure full text is included in Ace Editor highlight
},
name: offendingSymbol.text,
message: msg,
message: convertCustomError(msg),
});
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/util/CustomeErrorConverter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const convertCustomError = (errorMessage: string): string => {
let convertedMsg: string = errorMessage;
switch (errorMessage) {
case "no viable alternative at input 'define :'": {
convertedMsg = "Definition is missing a name.";
break;
}
default: {
break;
}
}
return convertedMsg;
};

export default convertCustomError;
10 changes: 10 additions & 0 deletions test/CqlAntlr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
cqlFluentFunctions,
relatedContextRetrieve,
aggregateQuery,
cqlDefineWithNoName,
} from "./testCql";
import { CqlAntlr } from "../src";
import CqlResult from "../src/dto/CqlResult";
Expand Down Expand Up @@ -177,4 +178,13 @@ describe("test antlr", () => {
const cqlResult: CqlResult = cqlAntlr.parse();
expect(cqlResult.errors.length).toEqual(0);
});

it("test define with no name", (): void => {
const cqlAntlr = new CqlAntlr(cqlDefineWithNoName);
const cqlResult: CqlResult = cqlAntlr.parse();
expect(cqlResult.errors.length).toEqual(1);
expect(cqlResult.errors[0].message).toEqual(
"Definition is missing a name."
);
});
});
5 changes: 5 additions & 0 deletions test/testCql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ define FactorialOfFive:
aggregate Result starting 1: Result * Num
`;

const cqlDefineWithNoName = `
define :
true
`;
export {
simpleDefinitionCql,
fhirTestCql,
Expand All @@ -232,4 +236,5 @@ export {
cqlFluentFunctions,
relatedContextRetrieve,
aggregateQuery,
cqlDefineWithNoName,
};

0 comments on commit c9ebb35

Please sign in to comment.