Skip to content

Commit

Permalink
Merge pull request #827 from CakeML/hex
Browse files Browse the repository at this point in the history
Implement parsing of hex integer literals
  • Loading branch information
myreen committed May 6, 2021
2 parents c39f0f7 + 559b482 commit dcd58cd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
14 changes: 10 additions & 4 deletions compiler/parsing/lexer_implScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,16 @@ val next_sym_alt_def = tDefine "next_sym_alt" `
rest)
else SOME (ErrorS, Locs loc loc, TL str)
else
let (n,rest) = read_while isDigit str [] in
SOME (NumberS (&(num_from_dec_string_alt (c::n))),
Locs loc (loc with col := loc.col + LENGTH n),
rest)
if str ≠ "" ∧ c = #"0" ∧ HD str = #"x" then
let (n,rest) = read_while isHexDigit (TL str) [] in
SOME (NumberS (& num_from_hex_string_alt n),
Locs loc (loc with col := loc.col + LENGTH n + 2),
rest)
else
let (n,rest) = read_while isDigit str [] in
SOME (NumberS (&(num_from_dec_string_alt (c::n))),
Locs loc (loc with col := loc.col + LENGTH n),
rest)
else if c = #"~" /\ str <> "" /\ isDigit (HD str) then (* read negative number *)
let (n,rest) = read_while isDigit str [] in
SOME (NumberS (0- &(num_from_dec_string_alt n)),
Expand Down
16 changes: 10 additions & 6 deletions semantics/lexer_funScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,16 @@ val next_sym_def = tDefine "next_sym" `
rest)
else SOME (ErrorS, Locs loc loc, TL str)
else
let (n,rest) = read_while isDigit str [] in
SOME (NumberS (&(num_from_dec_string (c::n))),
Locs loc (loc with col := loc.col + LENGTH n),
rest)
if str ≠ "" ∧ c = #"0" ∧ HD str = #"x" then
let (n,rest) = read_while isHexDigit (TL str) [] in
SOME (NumberS (& (num_from_hex_string n)),
Locs loc (loc with col := loc.col + LENGTH n + 2),
rest)
else
let (n,rest) = read_while isDigit str [] in
SOME (NumberS (&(num_from_dec_string (c::n))),
Locs loc (loc with col := loc.col + LENGTH n),
rest)
else if c = #"~" /\ str <> "" /\ isDigit (HD str) then (* read negative number *)
let (n,rest) = read_while isDigit str [] in
SOME (NumberS (0- &(num_from_dec_string n)),
Expand All @@ -207,11 +213,9 @@ val next_sym_def = tDefine "next_sym" `
SOME (mkCharS t, Locs loc loc', rest)
else if isPREFIX "#(" (c::str) then
let (t, loc', rest) = read_FFIcall (TL str) "" (loc with col := loc.col + 2) in

SOME (t, Locs loc loc', rest)
else if isPREFIX "#{" (c::str) then
let (t, loc', rest) = read_REPLcommand (TL str) "" (loc with col := loc.col + 2) in

SOME (t, Locs loc loc', rest)
else if isPREFIX "(*" (c::str) then
case skip_comment (TL str) 0 (loc with col := loc.col + 2) of
Expand Down

0 comments on commit dcd58cd

Please sign in to comment.