Skip to content

Commit 0c75113

Browse files
committed
Fix float parsing
1 parent 7f591ca commit 0c75113

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333

3434
### Fixed
3535
- Views will now update properly when the server changes the value of a form field (#1483)
36+
- Fixed float parsing for stylesheet rules
3637

3738
## [0.3.1] 2024-10-02
3839

lib/live_view_native/swiftui/rules_parser/tokens.ex

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,30 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Tokens do
2121

2222
def nil_(), do: replace(string("nil"), nil)
2323

24-
def minus(), do: string("-")
25-
26-
def underscored_integer() do
27-
integer(min: 1)
24+
def digits() do
25+
ascii_char([?0..?9])
2826
|> repeat(
2927
choice([
3028
ascii_char([?0..?9]),
31-
ignore(string("_"))
32-
|> ascii_char([?0..?9])
29+
ignore(string("_")) |> ascii_char([?0..?9])
3330
])
34-
|> reduce({List, :to_string, []})
3531
)
36-
|> reduce({Enum, :join, [""]})
32+
|> reduce({List, :to_string, []})
33+
end
34+
35+
def minus(), do: string("-")
36+
37+
def frac() do
38+
concat(string("."), digits())
3739
end
3840

3941
def integer() do
4042
optional(minus())
41-
|> concat(underscored_integer())
43+
|> concat(digits())
4244
|> reduce({Enum, :join, [""]})
4345
|> map({String, :to_integer, []})
4446
end
4547

46-
def frac() do
47-
concat(string("."), underscored_integer())
48-
end
49-
5048
def float() do
5149
integer()
5250
|> concat(frac())

test/live_view_native/swiftui/rules_parser_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do
117117

118118
assert parse(input) == output
119119

120-
input = "background(Color.blue.opacity(0.2).blendMode(.multiply).mix(with: .orange).opacity(0.7))"
121-
output = {:background, [], [{:., [], [{:., [], [{:., [], [{:., [], [{:., [], [:Color, :blue]}, {:opacity, [], [0.2]}]}, {:blendMode, [], [{:., [], [nil, :multiply]}]}]}, {:mix, [], [{:with, {:., [], [nil, :orange]}}]}]}, {:opacity, [], [0.7]}]}]}
120+
input = "background(Color.blue.opacity(0.02).blendMode(.multiply).mix(with: .orange).opacity(0.7))"
121+
output = {:background, [], [{:., [], [{:., [], [{:., [], [{:., [], [{:., [], [:Color, :blue]}, {:opacity, [], [0.02]}]}, {:blendMode, [], [{:., [], [nil, :multiply]}]}]}, {:mix, [], [{:with, {:., [], [nil, :orange]}}]}]}, {:opacity, [], [0.7]}]}]}
122122

123123
assert parse(input) == output
124124
end

0 commit comments

Comments
 (0)