javascript - Slimit python minifier strange behaviour -
i trying minify javascript python 'slimit' package.
import slimit slimit.minify('[1,2,3,4,5,6,7,8]')
runs fine , returns '[1,2,3,4,5,6,7,8]'
import slimit slimit.minify('[01,02,03,04,05,06,07,08]')
gives error:
syntaxerror: unexpected token (number, '8') @ 1:23 between lextoken(number,'0',1,22) , lextoken(rbracket,']',1,24)
the strange thing minifying string [01,02,03,04,05,06,07] works ok.
slimit returns error when minifying 8 or more 0 padded integers in array.
this down lexer used slimit. numbers starting "0" (but not "0x") treated octal integers. sequence "08" therefore ends 2 separate tokens ("0", "8") hence "unexpected token" error.
note following:
>>> slimit import lexer >>> l = lexer() >>> l.input("02") >>> l.token() lextoken(number,'02',1,0) >>> l.input("08") >>> l.token() lextoken(number,'0',1,0) >>> l.token() lextoken(number,'8',1,1)
looking the source lexer, see regex used identify numbers:
t_number = r""" (?: 0[xx][0-9a-fa-f]+ # hex_integer_literal | 0[0-7]+ # or octal_integer_literal (spec b.1.1) | (?: # or decimal_literal (?:0|[1-9][0-9]*) # decimal_integer_literal \. # dot [0-9]* # decimal_digits_opt (?:[ee][+-]?[0-9]+)? # exponent_part_opt | \. # dot [0-9]+ # decimal_digits (?:[ee][+-]?[0-9]+)? # exponent_part_opt | (?:0|[1-9][0-9]*) # decimal_integer_literal (?:[ee][+-]?[0-9]+)? # exponent_part_opt ) ) """
the question of whether slimit should support octal representations or treat them plain base-10 integers open debate.
the json spec explicitly forbids octal forms of numbers , tools flag invalid json (try jsonlint). rfc 4627 (2.4. numbers):
octal , hex forms not allowed. leading zeros not allowed.
Comments
Post a Comment