Skip to content

Commit

Permalink
Merge pull request #44 from richardreeve/rr/float
Browse files Browse the repository at this point in the history
Fix mistake in float parsing and add PFloat16
  • Loading branch information
oxinabox committed Oct 26, 2023
2 parents a34ebac + ee23e29 commit 2ff6b8f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ParserCombinator"
uuid = "fae87a5f-d1ad-5cf0-8f61-c941e1580b46"
version = "2.2.0"
version = "2.2.1"

[deps]
AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
Expand Down
2 changes: 1 addition & 1 deletion src/ParserCombinator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ParserError, Error,
Transform, App, Appl, ITransform, IApp, IAppl,
@p_str, @P_str, @e_str, @E_str, Opt, Opt!,
Parse, PUInt, PUInt8, PUInt16, PUInt32, PUInt64,
PInt, PInt8, PInt16, PInt32, PInt64, PFloat32, PFloat64,
PInt, PInt8, PInt16, PInt32, PInt64, PFloat16, PFloat32, PFloat64,
Word, Space,
Star, Plus, Star!, Plus!, StarList, StarList!, PlusList, PlusList!,
@with_names, set_name,
Expand Down
5 changes: 3 additions & 2 deletions src/core/extras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ PInt8() = Parse(p"-?\d+", Int8)
PInt16() = Parse(p"-?\d+", Int16)
PInt32() = Parse(p"-?\d+", Int32)
PInt64() = Parse(p"-?\d+", Int64)
PFloat32() = Parse(p"-?(\d*\.?\d+|\d+\.\d*)([eE]\d+)?", Float32)
PFloat64() = Parse(p"-?(\d*\.?\d+|\d+\.\d*)([eE]\d+)?", Float64)
PFloat16() = Parse(p"-?(\d*\.?\d+|\d+\.\d*)([eE]-?\d+)?", Float16)
PFloat32() = Parse(p"-?(\d*\.?\d+|\d+\.\d*)([eE]-?\d+)?", Float32)
PFloat64() = Parse(p"-?(\d*\.?\d+|\d+\.\d*)([eE]-?\d+)?", Float64)

Word() = p"\w+"
Space() = p"\s+"
Expand Down
2 changes: 1 addition & 1 deletion test/core/calc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ end
# some regression tests
@test calc(parse_one("-5.0/7.0+5.0-5.0", all)[1]) -0.7142857142857144
@test eval(Meta.parse("-5.0/7.0+5.0-5.0")) -0.7142857142857144
@test calc(parse_one("(0.0-9.0)", all)[1]) -9.0
@test calc(parse_one("(0.0-9.0e-1)", all)[1]) -0.9
@test calc(parse_one("((0.0-9.0))", all)[1]) -9.0
@test calc(parse_one("-((0.0-9.0))", all)[1]) 9.0
@test calc(parse_one("(-6.0/5.0)", all)[1]) -1.2
Expand Down
3 changes: 3 additions & 0 deletions test/core/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
@test_throws ParserException parse_one("abc", And(Equal("a"), Lookahead(Equal("c")), Equal("b")))
@test parse_one("abc", And(Equal("a"), Not(Lookahead(Equal("c"))), Equal("b"))) == Any[["a"], [], ["b"]]
@test parse_one("1.2", PFloat64()) == [1.2]
@test parse_one("-9.0E01", PFloat64())[1] -90.0
@test parse_one("-9.0E-01", PFloat32())[1] -0.9
@test parse_one("-9.0e0", PFloat16())[1] -9.0
m1 = Delayed()
m1.matcher = Seq(Dot(), Opt(m1))
@test parse_one("abc", m1) == ['a', 'b', 'c']
Expand Down

0 comments on commit 2ff6b8f

Please sign in to comment.