Skip to content

Commit

Permalink
Fix bugs and distinguish between Sigil Type and Sigil Prefix
Browse files Browse the repository at this point in the history
Summary: Backported from erlang/otp@b06923d

Reviewed By: alanz

Differential Revision: D57048097

fbshipit-source-id: 4fea3708d836272c6bf7194c0fd7e973f4466758
  • Loading branch information
robertoaloi authored and facebook-github-bot committed Jun 26, 2024
1 parent 04d346e commit e2bac67
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions erlang_service/src/elp_parse.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bin_base_type bin_unit_type
maybe_expr maybe_match_exprs maybe_match.

Terminals
char integer float atom sigil_type string sigil_suffix var
char integer float atom sigil_prefix string sigil_suffix var

'(' ')' ',' '->' '{' '}' '[' ']' '|' '||' '<-' ';' ':' '#' '.'
'after' 'begin' 'case' 'try' 'catch' 'end' 'fun' 'if' 'of' 'receive' 'when'
Expand Down Expand Up @@ -279,6 +279,7 @@ pat_expr_max -> var : '$1'.
pat_expr_max -> atomic : '$1'.
pat_expr_max -> list : '$1'.
pat_expr_max -> binary : '$1'.
pat_expr_max -> sigil : '$1'.
pat_expr_max -> tuple : '$1'.
pat_expr_max -> '(' pat_expr ')' : '$2'.

Expand Down Expand Up @@ -324,7 +325,7 @@ bit_type -> atom ':' integer : {{element(3,'$1'), element(3,'$3')}, ?anno('$1',

bit_size_expr -> expr_max : '$1'.

sigil -> sigil_type string sigil_suffix : build_sigil('$1', '$2', '$3').
sigil -> sigil_prefix string sigil_suffix : build_sigil('$1', '$2', '$3').

list_comprehension -> '[' expr '||' lc_exprs ']' :
{lc,?anno('$1','$5'),'$2','$4'}.
Expand Down Expand Up @@ -1411,8 +1412,8 @@ check_clauses(Cs, Name, Arity) ->
build_try(Try, Es, Scs, {Ccs, As, End}) ->
{'try', ?anno(Try, End), Es, Scs, Ccs, As}.

build_sigil(SigilType, String, SigilSuffix) ->
Type = element(3, SigilType),
build_sigil(SigilPrefix, String, SigilSuffix) ->
Type = element(3, SigilPrefix),
Suffix = element(3, SigilSuffix),
if
Type =:= 'S';
Expand All @@ -1433,7 +1434,7 @@ build_sigil(SigilType, String, SigilSuffix) ->
case Suffix of
"" ->
%% Convert to UTF-8 binary()
{bin,?anno(SigilType),
{bin,?anno(SigilPrefix),
[{bin_element,
?anno(String),String,default,[utf8]}]};
_ ->
Expand All @@ -1443,7 +1444,7 @@ build_sigil(SigilType, String, SigilSuffix) ->
end;
true ->
ret_err(
element(2, SigilType),
element(2, SigilPrefix),
"illegal sigil type.")
end.

Expand Down

0 comments on commit e2bac67

Please sign in to comment.