@@ -691,6 +691,13 @@ defmodule NimbleParsec do
691691 bin_segment ( combinator , inclusive , exclusive , :integer )
692692 end
693693
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+
694701 @ doc ~S"""
695702 Defines a single UTF-8 codepoint in the given ranges.
696703
@@ -812,7 +819,7 @@ defmodule NimbleParsec do
812819
813820 min_max_compile_runtime_chars (
814821 combinator ,
815- ascii_char ( [ ?0 .. ?9 ] ) ,
822+ integer_nibble ( ) ,
816823 count ,
817824 :__compile_integer__ ,
818825 :__runtime_integer__ ,
@@ -828,7 +835,7 @@ defmodule NimbleParsec do
828835
829836 min_max_compile_runtime_chars (
830837 combinator ,
831- ascii_char ( [ ?0 .. ?9 ] ) ,
838+ integer_nibble ( ) ,
832839 opts ,
833840 :__compile_integer__ ,
834841 :__runtime_integer__ ,
@@ -2083,7 +2090,7 @@ defmodule NimbleParsec do
20832090 ast =
20842091 quote do
20852092 [ 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 ) ]
20872094 end
20882095
20892096 { :{} , [ ] , [ rest , ast , context ] }
@@ -2093,7 +2100,7 @@ defmodule NimbleParsec do
20932100 ast =
20942101 quote do
20952102 [ 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 ) ]
20972104 end
20982105
20992106 { :{} , [ ] , [ rest , ast , context ] }
@@ -2113,11 +2120,11 @@ defmodule NimbleParsec do
21132120 defp reverse_now_or_later ( expr ) , do: quote ( do: :lists . reverse ( unquote ( expr ) ) )
21142121
21152122 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 ) ]
21172124 end
21182125
21192126 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 ) ]
21212128 end
21222129
21232130 defp quoted_ascii_to_integer ( [ ] , _index ) do
0 commit comments