77Definitions .
88WHITESPACE = [\s \t \f \n \r ]
99DIGIT = [0 - 9 ]
10+ HEXDIGIT = [0 - 9 A - F ]
1011INT = {DIGIT }+
1112% Approximate numeric literal with a decimal
1213FLOAT = ({DIGIT }+ \.{DIGIT }* |\.{DIGIT }+ )(E [\+ \- ]?{INT })?
@@ -17,6 +18,7 @@ EXPONENT = {DIGIT}+E[\+\-]?{DIGIT}+
1718% to allow identifiers such as properties.group-id
1819IDENTIFIER = [a - zA - Z_ $] [a - zA - Z0 - 9 _ $. \- ]*
1920STRING = '([^' ]|'' )* '
21+ BINARY = 0x({HEXDIGIT}{HEXDIGIT})+
2022
2123Rules.
2224{WHITESPACE}+ : skip_token.
@@ -65,6 +67,7 @@ FALSE : {token, {boolean, TokenLine, false}}.
6567{EXPONENT } : {token , {float , TokenLine , parse_scientific_notation (TokenChars )}}.
6668{STRING } : {token , {string , TokenLine , process_string (TokenChars )}}.
6769{IDENTIFIER } : {token , {identifier , TokenLine , unicode :characters_to_binary (TokenChars )}}.
70+ {BINARY } : {token , {binary , TokenLine , parse_binary (TokenChars )}}.
6871
6972% Catch any other characters as errors
7073. : {error , {illegal_character , TokenChars }}.
@@ -100,3 +103,12 @@ process_string(Chars) ->
100103
101104process_escaped_quotes (Binary ) ->
102105 binary :replace (Binary , <<" ''" >>, <<" '" >>, [global ]).
106+
107+ parse_binary ([$0 , $x | HexChars ]) ->
108+ parse_hex_pairs (HexChars , <<>>).
109+
110+ parse_hex_pairs ([], Acc ) ->
111+ Acc ;
112+ parse_hex_pairs ([H1 , H2 | Rest ], Acc ) ->
113+ Byte = list_to_integer ([H1 , H2 ], 16 ),
114+ parse_hex_pairs (Rest , <<Acc /binary , Byte >>).
0 commit comments