mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-27 11:48:55 -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 {
|
function readExpr (str: string): Expr {
|
||||||
const txt = PgfText_FromString(str)
|
const txt = PgfText_FromString(str)
|
||||||
const expr = runtime.pgf_read_expr(txt, unmarshaller.ref())
|
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
|
return ref.readObject(expr) as Expr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -210,6 +210,13 @@ describe('abstract syntax', () => {
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
describe('expressions', () => {
|
describe('expressions', () => {
|
||||||
|
test('invalid', () => {
|
||||||
|
expect(() => {
|
||||||
|
PGF.readExpr('->')
|
||||||
|
}).toThrow(PGF.PGFError)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('literals', () => {
|
||||||
test('small integer', () => {
|
test('small integer', () => {
|
||||||
const e1 = PGF.readExpr('123')
|
const e1 = PGF.readExpr('123')
|
||||||
const e2 = new PGF.ExprLit(123)
|
const e2 = new PGF.ExprLit(123)
|
||||||
@@ -285,4 +292,5 @@ describe('expressions', () => {
|
|||||||
expect(e1).toEqual(e2)
|
expect(e1).toEqual(e2)
|
||||||
expect(e1).not.toEqual(e3)
|
expect(e1).not.toEqual(e3)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user