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

Mat 7995 update error msg when define lacks name #222

Merged
merged 2 commits into from
Dec 17, 2024
Merged
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.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,
};
Loading