From: Steve Hancock Date: Thu, 16 Jan 2020 17:13:20 +0000 (-0800) Subject: added support for hex floating point X-Git-Tag: 20200619~142 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=772cd9e0acd8c1c181376cb3366c081a589d6eb3;p=perltidy.git added support for hex floating point --- diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 616253e6..2c445b79 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -6542,9 +6542,9 @@ sub numerator_expected { BEGIN { - # List of tokens which may follow a pattern. Note that we will not - # have formed digraphs at this point, so we will see '&' instead of - # '&&' and '|' instead of '||' + # List of tokens which may follow a pattern. Note that we will not + # have formed digraphs at this point, so we will see '&' instead of + # '&&' and '|' instead of '||' # /(\)|\}|\;|\&\&|\|\||and|or|while|if|unless)/ my @q = qw( & && | || ? : + - * and or while if unless); @@ -6792,8 +6792,45 @@ sub scan_number_do { # handle octal, hex, binary if ( !defined($number) ) { pos($input_line) = $pos_beg; - if ( $input_line =~ - /\G[+-]?0(([xX][0-9a-fA-F_]+)|([0-7_]+)|([bB][01_]+))/g ) + + # Perl 5.22 added floating point literals, like '0x0.b17217f7d1cf78p0' + # For reference, the format prior to hex floating point is: + # /\G[+-]?0(([xX][0-9a-fA-F_]+)|([0-7_]+)|([bB][01_]+))/g ) + # (hex) (octal) (binary) + if ( + $input_line =~ + + /\G[+-]?0( # leading [signed] 0 + + # a hex float, i.e. '0x0.b17217f7d1cf78p0' + ([xX][0-9a-fA-F_]* # X and optional leading digits + (\.([0-9a-fA-F][0-9a-fA-F_]*)?)? # optional decimal and fraction + [Pp][+-]?[0-9a-fA-F] # REQUIRED exponent with digit + [0-9a-fA-F_]*) # optional Additional exponent digits + + # or hex integer + |([xX][0-9a-fA-F_]+) + + # or octal fraction + |([0-7_]+ # string of octal digits + (\.([0-7][0-7_]*)?)? # optional decimal and fraction + [Pp][+-]?[0-7] # REQUIRED exponent, no underscore + [0-7_]*) # Additonal exponent digits, with underscores + + # or octal integer + |([0-7_]+) # string of octal digits + + # or a binary float + |([bB][01_]* # 'b' with string of binary digits + (\.([01][01_]*)?)? # optional decimal and fraction + [Pp][+-]?[01] # Required exponent indicator, no underscore + [01_]*) # additional exponent bits + + # or binary integer + |([bB][01_]+) # 'b' with string of binary digits + + )/gx + ) { $pos = pos($input_line); my $numc = $pos - $pos_beg;