@@ -691,6 +691,13 @@ defmodule NimbleParsec do
691
691
bin_segment ( combinator , inclusive , exclusive , :integer )
692
692
end
693
693
694
+ @ spec integer_nibble ( ) :: t
695
+ @ spec integer_nibble ( t ) :: t
696
+ def integer_nibble ( combinator \\ empty ( ) )
697
+ when is_combinator ( combinator ) do
698
+ [ { :integer_nibble } | combinator ]
699
+ end
700
+
694
701
@ doc ~S"""
695
702
Defines a single UTF-8 codepoint in the given ranges.
696
703
@@ -812,7 +819,7 @@ defmodule NimbleParsec do
812
819
813
820
min_max_compile_runtime_chars (
814
821
combinator ,
815
- ascii_char ( [ ?0 .. ?9 ] ) ,
822
+ integer_nibble ( ) ,
816
823
count ,
817
824
:__compile_integer__ ,
818
825
:__runtime_integer__ ,
@@ -828,7 +835,7 @@ defmodule NimbleParsec do
828
835
829
836
min_max_compile_runtime_chars (
830
837
combinator ,
831
- ascii_char ( [ ?0 .. ?9 ] ) ,
838
+ integer_nibble ( ) ,
832
839
opts ,
833
840
:__compile_integer__ ,
834
841
:__runtime_integer__ ,
@@ -2083,7 +2090,7 @@ defmodule NimbleParsec do
2083
2090
ast =
2084
2091
quote do
2085
2092
[ head | tail ] = unquote ( reverse_now_or_later ( acc ) )
2086
- [ :lists . foldl ( fn x , acc -> x - ?0 + acc * 10 end , head , tail ) ]
2093
+ [ :lists . foldl ( fn x , acc -> x + acc * 10 end , head , tail ) ]
2087
2094
end
2088
2095
2089
2096
{ :{} , [ ] , [ rest , ast , context ] }
@@ -2093,7 +2100,7 @@ defmodule NimbleParsec do
2093
2100
ast =
2094
2101
quote do
2095
2102
[ head | tail ] = unquote ( reverse_now_or_later ( acc ) )
2096
- [ :lists . foldl ( fn x , acc -> x - ?0 + acc * 10 end , head - ?0 , tail ) ]
2103
+ [ :lists . foldl ( fn x , acc -> x + acc * 10 end , head , tail ) ]
2097
2104
end
2098
2105
2099
2106
{ :{} , [ ] , [ rest , ast , context ] }
@@ -2113,11 +2120,11 @@ defmodule NimbleParsec do
2113
2120
defp reverse_now_or_later ( expr ) , do: quote ( do: :lists . reverse ( unquote ( expr ) ) )
2114
2121
2115
2122
defp quoted_ascii_to_integer ( [ var | vars ] , 1 ) do
2116
- [ quote ( do: unquote ( var ) - ?0 ) | quoted_ascii_to_integer ( vars , 10 ) ]
2123
+ [ quote ( do: unquote ( var ) ) | quoted_ascii_to_integer ( vars , 10 ) ]
2117
2124
end
2118
2125
2119
2126
defp quoted_ascii_to_integer ( [ var | vars ] , index ) do
2120
- [ quote ( do: ( unquote ( var ) - ?0 ) * unquote ( index ) ) | quoted_ascii_to_integer ( vars , index * 10 ) ]
2127
+ [ quote ( do: unquote ( var ) * unquote ( index ) ) | quoted_ascii_to_integer ( vars , index * 10 ) ]
2121
2128
end
2122
2129
2123
2130
defp quoted_ascii_to_integer ( [ ] , _index ) do
0 commit comments