Skip to content

Commit

Permalink
Handle sigil prefix/suffix in the scanner
Browse files Browse the repository at this point in the history
Summary: So that tokens are extracted correctly.

Reviewed By: alanz

Differential Revision: D59107939

fbshipit-source-id: 2c10769ec00b7df38a5122852f0987841a5a2a75
  • Loading branch information
robertoaloi authored and facebook-github-bot committed Jun 27, 2024
1 parent 50ba583 commit 0fe3033
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
module specified: otp27_sigils
Diagnostics reported in 1 modules:
otp27_sigils: 66
0:0-0:0::[Error] [E1500] 191: cannot parse file, giving up
3:9-3:12::[Error] [L1227] function f/0 undefined
3:14-3:17::[Error] [L1227] function g/0 undefined
8:0-8:15::[Error] [L1308] spec for undefined function f/0
otp27_sigils: 64
10:5-10:23::[Warning] [W0006] this statement has no effect
11:4-11:23::[Warning] [W0006] this statement has no effect
12:4-12:23::[Warning] [W0006] this statement has no effect
Expand Down Expand Up @@ -58,6 +54,7 @@ Diagnostics reported in 1 modules:
66:4-66:23::[Warning] [W0006] this statement has no effect
67:4-67:23::[Warning] [W0006] this statement has no effect
68:4-68:23::[Warning] [W0006] this statement has no effect
70:54-70:55::[Warning] [L1268] variable 'X' is unused
75:4-78:7::[Warning] [W0006] this statement has no effect
75:4-78:7::[Warning] [W0006] this statement has no effect
79:4-83:8::[Warning] [W0006] this statement has no effect
Expand All @@ -66,4 +63,5 @@ Diagnostics reported in 1 modules:
84:4-88:9::[Warning] [W0006] this statement has no effect
89:4-93:10::[Warning] [W0006] this statement has no effect
94:4-98:11::[Warning] [W0006] this statement has no effect
111:55-111:56::[Error] [P1711] syntax error before: X
127:8-127:23::[Warning] [W0002] Unused macro (THIS_IS_THE_END)
16 changes: 9 additions & 7 deletions erlang_service/src/elp_scan.erl
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ scan_sigil_prefix(Cs, St, Off, Toks, {Wcs, N0}) ->
SigilCs = lists:reverse(Nwcs),
try list_to_atom(tl(SigilCs)) of
SigilType when is_atom(SigilType) ->
scan_string(Ncs, St, Off + N, [Type | Toks], SigilType)
Tok = {Type, {Off, Off + N}, SigilType},
scan_string(Ncs, St, Off + N, [Tok | Toks], SigilType)
catch
_:_ ->
scan_error({illegal, Type}, Off, Off + N, Ncs)
Expand Down Expand Up @@ -1091,20 +1092,21 @@ scan_sigil_suffix(Cs, St, Off, Toks, SigilType) when
% Sigil string - scan suffix
is_atom(SigilType)
->
scan_sigil_suffix(Cs, St, Off, Toks, {"", 1});
scan_sigil_suffix(Cs, St, Off, Toks, {"", 0});
%%
scan_sigil_suffix(Cs, St, Off, Toks, {Wcs, N0}) when is_list(Wcs) ->
case scan_name(Cs, Wcs, N0) of
{more, Nwcs} ->
{more, {[], St, Off, Toks, Nwcs, fun scan_sigil_suffix/5}};
{Nwcs, Ncs} ->
{more, Nwcs, N} ->
{more, {[], St, Off, Toks, {Nwcs, N}, fun scan_sigil_suffix/5}};
{done, Nwcs, Ncs, N} ->
Type = sigil_suffix,
Noff = Off + length(Nwcs),
Noff = Off + N,
Suffix = lists:reverse(Nwcs),
try list_to_atom(Suffix) of
A when is_atom(A) ->
Tok = {Type, {Off, Noff}, Suffix},
scan_string_concat(
Ncs, St, Noff, [Type | Toks], {Suffix, 1}
Ncs, St, Noff, [Tok | Toks], {Suffix, 1}
)
catch
_:_ ->
Expand Down

0 comments on commit 0fe3033

Please sign in to comment.