Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for parsing negative numbers in sexps #1655

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ unreleased
fixes #1647)
- Prevent `short-path` from looping in some cases related to recursive type
definitions (#1645)
- Support parsing negative numbers in sexps (#1655)
+ editor modes
- emacs: call merlin-client-logger with "interrupted" if the
merlin binary itself is interrupted, not just the parsing of the
Expand Down
16 changes: 8 additions & 8 deletions src/utils/sexp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ let is_alpha c =
|| (c >= 'A' && c <= 'Z')

let is_num c =
(c >= '0' && c <= '9')
(c >= '0' && c <= '9' || c == '-')

let is_alphanum c = is_alpha c || is_num c

Expand Down Expand Up @@ -149,22 +149,22 @@ let read_sexp getch =
and read_num getch c =
Buffer.clear buf;
Buffer.add_char buf c;
let is_float = ref false in
let rec aux () =
let rec aux ~is_start ~is_float =
match getch () with
| '-' when is_start ->
Buffer.add_char buf c; aux ~is_start:false ~is_float
| c when c >= '0' && c <= '9' ->
Buffer.add_char buf c; aux ()
Buffer.add_char buf c; aux ~is_start:false ~is_float
| '.' | 'e' | 'E' as c ->
is_float := true;
Buffer.add_char buf c; aux ()
Buffer.add_char buf c; aux ~is_start:false ~is_float:true
| c ->
let s = Buffer.contents buf in
(if !is_float
(if is_float
then Float (float_of_string s)
else Int (int_of_string s)),
Some c
in
aux ()
aux ~is_start:true ~is_float:false

and read_string getch =
Buffer.clear buf;
Expand Down