From fa4af8b27d316075df049cc5d8a33eb886eb4527 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Tue, 21 Jul 2020 23:33:37 -0500 Subject: [PATCH] JSON5 in dbStatic: Modify lexer's number support dbLex.l acceps a leading or trailing decimal point with float/double values and an explicit leading + on all numbers. Tested in dbStaticTest.db but only passing tests. --- modules/database/src/ioc/dbStatic/dbLex.l | 11 ++++-- modules/database/test/ioc/db/dbStaticTest.db | 40 ++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/modules/database/src/ioc/dbStatic/dbLex.l b/modules/database/src/ioc/dbStatic/dbLex.l index 1dbd23d99..5c28044f8 100644 --- a/modules/database/src/ioc/dbStatic/dbLex.l +++ b/modules/database/src/ioc/dbStatic/dbLex.l @@ -25,10 +25,15 @@ hexdigit [0-9a-fA-F] unicodechar ({backslash}"u"{hexdigit}{4}) jsonchar ({normalchar}|{escapedchar}|{unicodechar}) jsondqstr ({doublequote}{jsonchar}*{doublequote}) -int ("-"?([0-9]|[1-9][0-9]+)) + +sign ([+-]?) +int ({sign}([0-9]|[1-9][0-9]+)) frac ("."[0-9]+) -exp ([eE][+-]?[0-9]+) -number ({int}{frac}?{exp}?) +exp ([eE]{sign}[0-9]+) +jsonnum ({int}{frac}?{exp}?) +intexp ({int}"."{exp}?) +fracexp ({sign}{frac}{exp}?) +number ({jsonnum}|{intexp}|{fracexp}) %{ #undef YY_INPUT diff --git a/modules/database/test/ioc/db/dbStaticTest.db b/modules/database/test/ioc/db/dbStaticTest.db index 63036727f..03ffaf4b9 100644 --- a/modules/database/test/ioc/db/dbStaticTest.db +++ b/modules/database/test/ioc/db/dbStaticTest.db @@ -6,3 +6,43 @@ record(x, "testrec") { alias("testrec", "testalias2") alias("testalias2", "testalias3") + +# New number formats allowed in JSON5, show dbLex/dbYacc parsing +record(x, "t1") { + field( C8, +12) + field( U8, +123) + field(I16, +1234) + field(U16, +12345) + field(I32, +123456) + field(U32, +1234567) + field(I64, +12345678) + field(U64, +123456789) + field(F32, .123) + field(F64, .123) + field(F32, 123.) + field(F64, 123.) + field(F32, +.123) + field(F64, +.123) + field(F32, +123.) + field(F64, +123.) + field(F32, -.123) + field(F64, -.123) + field(F32, -123.) + field(F64, -123.) + field(F32, .123e4) + field(F64, .123e4) + field(F32, 123.e4) + field(F64, 123.e4) + field(F32, 123.e+4) + field(F64, 123.e+4) + field(F32, 123.e-4) + field(F64, 123.e-4) + field(F32, +.123e4) + field(F64, +.123e4) + field(F32, +123.e4) + field(F64, +123.e4) + field(F32, -.123e4) + field(F64, -.123e4) + field(F32, -123.e4) + field(F64, -123.e4) +}