mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-06-03 07:08:54 -06:00
Handle errors in readExpr
This commit is contained in:
@@ -201,6 +201,9 @@ function newNGF (abstract_name: string, path?: string): PGFGrammar {
|
||||
function readExpr (str: string): Expr {
|
||||
const txt = PgfText_FromString(str)
|
||||
const expr = runtime.pgf_read_expr(txt, unmarshaller.ref())
|
||||
if (ref.isNull(expr)) {
|
||||
throw new PGFError('unable to parse expression')
|
||||
}
|
||||
return ref.readObject(expr) as Expr
|
||||
}
|
||||
|
||||
|
||||
@@ -210,6 +210,13 @@ describe('abstract syntax', () => {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
describe('expressions', () => {
|
||||
test('invalid', () => {
|
||||
expect(() => {
|
||||
PGF.readExpr('->')
|
||||
}).toThrow(PGF.PGFError)
|
||||
})
|
||||
|
||||
describe('literals', () => {
|
||||
test('small integer', () => {
|
||||
const e1 = PGF.readExpr('123')
|
||||
const e2 = new PGF.ExprLit(123)
|
||||
@@ -285,4 +292,5 @@ describe('expressions', () => {
|
||||
expect(e1).toEqual(e2)
|
||||
expect(e1).not.toEqual(e3)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user