Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:19
erlang
2662-Only-allow-single-separator-between-digits...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2662-Only-allow-single-separator-between-digits.patch of Package erlang
From 3fd74ac49fad11ed9e4f78932b36aec44d2d6514 Mon Sep 17 00:00:00 2001 From: Sergey Prokhorov <seriy.pr@gmail.com> Date: Fri, 19 Jul 2019 01:52:15 +0200 Subject: [PATCH 2/8] Only allow (single) separator between digits --- lib/stdlib/src/erl_scan.erl | 48 +++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/stdlib/src/erl_scan.erl b/lib/stdlib/src/erl_scan.erl index 4e5a51ae07..35ac83eb13 100644 --- a/lib/stdlib/src/erl_scan.erl +++ b/lib/stdlib/src/erl_scan.erl @@ -249,7 +249,7 @@ string_thing(_) -> "string". -define(WHITE_SPACE(C), is_integer(C) andalso (C >= $\000 andalso C =< $\s orelse C >= $\200 andalso C =< $\240)). --define(DIGIT(C), C >= $0, C =< $9). +-define(DIGIT(C), C >= $0 andalso C =< $9). -define(CHAR(C), is_integer(C), C >= 0). -define(UNICODE(C), is_integer(C) andalso @@ -940,15 +940,16 @@ escape_char(C) -> C. scan_number([C|Cs], St, Line, Col, Toks, Ncs) when ?DIGIT(C) -> scan_number(Cs, St, Line, Col, Toks, [C|Ncs]); -scan_number([$_|Cs], St, Line, Col, Toks, Ncs) -> - scan_number(Cs, St, Line, Col, Toks, Ncs); +scan_number([$_,Next|Cs], St, Line, Col, Toks, [Prev|_]=Ncs) when + ?DIGIT(Next) andalso ?DIGIT(Prev) -> + scan_number(Cs, St, Line, Col, Toks, [Next,$_|Ncs]); scan_number([$.,C|Cs], St, Line, Col, Toks, Ncs) when ?DIGIT(C) -> scan_fraction(Cs, St, Line, Col, Toks, [C,$.|Ncs]); scan_number([$.]=Cs, _St, Line, Col, Toks, Ncs) -> {more,{Cs,Col,Toks,Line,Ncs,fun scan_number/6}}; scan_number([$#|Cs]=Cs0, St, Line, Col, Toks, Ncs0) -> Ncs = lists:reverse(Ncs0), - case catch list_to_integer(Ncs) of + case catch list_to_integer(remove_digit_separators(Ncs)) of B when B >= 2, B =< 1+$Z-$A+10 -> Bcs = Ncs++[$#], scan_based_int(Cs, St, Line, Col, Toks, {B,[],Bcs}); @@ -960,7 +961,7 @@ scan_number([]=Cs, _St, Line, Col, Toks, Ncs) -> {more,{Cs,Col,Toks,Line,Ncs,fun scan_number/6}}; scan_number(Cs, St, Line, Col, Toks, Ncs0) -> Ncs = lists:reverse(Ncs0), - case catch list_to_integer(Ncs) of + case catch list_to_integer(remove_digit_separators(Ncs)) of N when is_integer(N) -> tok3(Cs, St, Line, Col, Toks, integer, Ncs, N); _ -> @@ -968,22 +969,25 @@ scan_number(Cs, St, Line, Col, Toks, Ncs0) -> scan_error({illegal,integer}, Line, Col, Line, Ncol, Cs) end. -scan_based_int([C|Cs], St, Line, Col, Toks, {B,Ncs,Bcs}) - when ?DIGIT(C), C < $0+B -> - scan_based_int(Cs, St, Line, Col, Toks, {B,[C|Ncs],Bcs}); -scan_based_int([C|Cs], St, Line, Col, Toks, {B,Ncs,Bcs}) - when C >= $A, B > 10, C < $A+B-10 -> - scan_based_int(Cs, St, Line, Col, Toks, {B,[C|Ncs],Bcs}); -scan_based_int([C|Cs], St, Line, Col, Toks, {B,Ncs,Bcs}) - when C >= $a, B > 10, C < $a+B-10 -> +remove_digit_separators(Number) -> + [C || C <- Number, C =/= $_]. + +-define(BASED_DIGIT(C, B), + ((?DIGIT(C) andalso C < $0 + B) + orelse (C >= $A andalso B > 10 andalso C < $A + B - 10) + orelse (C >= $a andalso B > 10 andalso C < $a + B - 10))). + +scan_based_int([C|Cs], St, Line, Col, Toks, {B,Ncs,Bcs}) when + ?BASED_DIGIT(C, B) -> scan_based_int(Cs, St, Line, Col, Toks, {B,[C|Ncs],Bcs}); -scan_based_int([$_|Cs], St, Line, Col, Toks, {B,Ncs,Bcs}) -> - scan_based_int(Cs, St, Line, Col, Toks, {B,Ncs,Bcs}); +scan_based_int([$_,Next|Cs], St, Line, Col, Toks, {B,[Prev|_]=Ncs,Bcs}) when + ?BASED_DIGIT(Next, B) andalso ?BASED_DIGIT(Prev, B) -> + scan_based_int(Cs, St, Line, Col, Toks, {B,[Next,$_|Ncs],Bcs}); scan_based_int([]=Cs, _St, Line, Col, Toks, State) -> {more,{Cs,Col,Toks,Line,State,fun scan_based_int/6}}; scan_based_int(Cs, St, Line, Col, Toks, {B,Ncs0,Bcs}) -> Ncs = lists:reverse(Ncs0), - case catch erlang:list_to_integer(Ncs, B) of + case catch erlang:list_to_integer(remove_digit_separators(Ncs), B) of N when is_integer(N) -> tok3(Cs, St, Line, Col, Toks, integer, Bcs++Ncs, N); _ -> @@ -994,8 +998,9 @@ scan_based_int(Cs, St, Line, Col, Toks, {B,Ncs0,Bcs}) -> scan_fraction([C|Cs], St, Line, Col, Toks, Ncs) when ?DIGIT(C) -> scan_fraction(Cs, St, Line, Col, Toks, [C|Ncs]); -scan_fraction([$_|Cs], St, Line, Col, Toks, Ncs) -> - scan_fraction(Cs, St, Line, Col, Toks, Ncs); +scan_fraction([$_,Next|Cs], St, Line, Col, Toks, [Prev|_]=Ncs) when + ?DIGIT(Next) andalso ?DIGIT(Prev) -> + scan_fraction(Cs, St, Line, Col, Toks, [Next,$_|Ncs]); scan_fraction([E|Cs], St, Line, Col, Toks, Ncs) when E =:= $e; E =:= $E -> scan_exponent_sign(Cs, St, Line, Col, Toks, [E|Ncs]); scan_fraction([]=Cs, _St, Line, Col, Toks, Ncs) -> @@ -1012,8 +1017,9 @@ scan_exponent_sign(Cs, St, Line, Col, Toks, Ncs) -> scan_exponent([C|Cs], St, Line, Col, Toks, Ncs) when ?DIGIT(C) -> scan_exponent(Cs, St, Line, Col, Toks, [C|Ncs]); -scan_exponent([$_|Cs], St, Line, Col, Toks, Ncs) -> - scan_exponent(Cs, St, Line, Col, Toks, Ncs); +scan_exponent([$_,Next|Cs], St, Line, Col, Toks, [Prev|_]=Ncs) when + ?DIGIT(Next) andalso ?DIGIT(Prev) -> + scan_exponent(Cs, St, Line, Col, Toks, [Next,$_|Ncs]); scan_exponent([]=Cs, _St, Line, Col, Toks, Ncs) -> {more,{Cs,Col,Toks,Line,Ncs,fun scan_exponent/6}}; scan_exponent(Cs, St, Line, Col, Toks, Ncs) -> @@ -1021,7 +1027,7 @@ scan_exponent(Cs, St, Line, Col, Toks, Ncs) -> float_end(Cs, St, Line, Col, Toks, Ncs0) -> Ncs = lists:reverse(Ncs0), - case catch list_to_float(Ncs) of + case catch list_to_float(remove_digit_separators(Ncs)) of F when is_float(F) -> tok3(Cs, St, Line, Col, Toks, float, Ncs, F); _ -> -- 2.16.4
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor