@@ -31,7 +31,7 @@ Terminals
31
31
dot_call_op op_identifier
32
32
comp_op at_op unary_op and_op or_op arrow_op match_op in_op in_match_op
33
33
dual_op add_op mult_op exp_op two_op pipe_op stab_op when_op
34
- 'true' 'false' 'nil' 'do' eol ',' '.' '&'
34
+ 'true' 'false' 'nil' 'do' eol ',' '.'
35
35
'(' ')' '[' ']' '{' '}' '<<' '>>'
36
36
.
37
37
@@ -105,6 +105,7 @@ expr -> unmatched_expr : '$1'.
105
105
% % segments and act accordingly.
106
106
matched_expr -> matched_expr matched_op_expr : build_op (element (1 , '$2' ), '$1' , element (2 , '$2' )).
107
107
matched_expr -> matched_expr no_parens_op_expr : build_op (element (1 , '$2' ), '$1' , element (2 , '$2' )).
108
+ matched_expr -> unary_op_eol number : build_unary_op ('$1' , ? exprs ('$2' )).
108
109
matched_expr -> unary_op_eol matched_expr : build_unary_op ('$1' , '$2' ).
109
110
matched_expr -> unary_op_eol no_parens_expr : build_unary_op ('$1' , '$2' ).
110
111
matched_expr -> at_op_eol matched_expr : build_unary_op ('$1' , '$2' ).
@@ -210,7 +211,6 @@ base_expr -> list_string : build_list_string('$1').
210
211
base_expr -> atom_string : build_atom_string ('$1' ).
211
212
base_expr -> bit_string : '$1' .
212
213
base_expr -> sigil : build_sigil ('$1' ).
213
- base_expr -> '&' number : { '&' , meta ('$1' ), [? exprs ('$2' )] }.
214
214
215
215
% % Blocks
216
216
@@ -244,7 +244,7 @@ stab_expr -> call_args_no_parens_all stab_op_eol stab_maybe_expr :
244
244
stab_expr -> stab_parens_many stab_op_eol stab_maybe_expr :
245
245
build_op ('$2' , unwrap_splice ('$1' ), '$3' ).
246
246
stab_expr -> stab_parens_many when_op expr stab_op_eol stab_maybe_expr :
247
- build_op ('$4' , [{ 'when' , meta ('$2' ), unwrap_splice ('$1' ) ++ ['$3' ] }], '$5' ).
247
+ build_op ('$4' , [{ 'when' , meta ('$2' ), unwrap_splice ('$1' ) ++ ['$3' ] }], '$5' ).
248
248
249
249
stab_maybe_expr -> 'expr' : '$1' .
250
250
stab_maybe_expr -> '$empty' : nil .
@@ -459,9 +459,7 @@ Erlang code.
459
459
-define (line (Node ), element (2 , Node )).
460
460
-define (exprs (Node ), element (3 , Node )).
461
461
-define (lexical (Kind ), Kind == import ; Kind == alias ; Kind == '__aliases__' ).
462
-
463
462
-define (rearrange_uop (Op ), Op == 'not' orelse Op == '!' ).
464
- -define (rearrange_bop (Op ), Op == 'in' orelse Op == 'inlist' orelse Op == 'inbits' ).
465
463
466
464
% % The following directive is needed for (significantly) faster
467
465
% % compilation of the generated .erl file by the HiPE compiler
@@ -479,8 +477,8 @@ build_op({ _Kind, Line, '/' }, { '&', _, [{ Kind, _, Atom } = Left] }, Right) wh
479
477
build_op ({ _Kind , Line , '/' }, { '&' , _ , [{ { '.' , _ , [_ , _ ] }, _ , [] } = Left ] }, Right ) when is_number (Right ) ->
480
478
{ '&' , meta (Line ), [{ '/' , meta (Line ), [Left , Right ] }] };
481
479
482
- build_op ({ _Kind , Line , BOp }, { UOp , _ , [Left ] }, Right ) when ? rearrange_bop ( BOp ), ? rearrange_uop (UOp ) ->
483
- { UOp , meta (Line ), [{ BOp , meta (Line ), [Left , Right ] }] };
480
+ build_op ({ _Kind , Line , 'in' }, { UOp , _ , [Left ] }, Right ) when ? rearrange_uop (UOp ) ->
481
+ { UOp , meta (Line ), [{ 'in' , meta (Line ), [Left , Right ] }] };
484
482
485
483
build_op ({ _Kind , Line , Op }, Left , Right ) ->
486
484
{ Op , meta (Line ), [Left , Right ] }.
@@ -513,11 +511,17 @@ build_dot_alias(Dot, Other, { 'aliases', _, Right }) ->
513
511
build_dot (Dot , Left , Right ) ->
514
512
{ '.' , meta (Dot ), [Left , extract_identifier (Right )] }.
515
513
514
+ extract_identifier ({ Kind , _ , Identifier }) when
515
+ Kind == identifier ; Kind == bracket_identifier ; Kind == paren_identifier ;
516
+ Kind == do_identifier ; Kind == op_identifier ->
517
+ Identifier .
518
+
516
519
% % Identifiers
517
520
518
521
build_nested_parens (Dot , Args1 , Args2 ) ->
519
522
Identifier = build_identifier (Dot , Args1 ),
520
- { Identifier , ? line (Identifier ), Args2 }.
523
+ Meta = element (2 , Identifier ),
524
+ { Identifier , Meta , Args2 }.
521
525
522
526
build_identifier ({ '.' , Meta , _ } = Dot , Args ) ->
523
527
FArgs = case Args of
@@ -538,13 +542,6 @@ build_identifier({ _, Line, Identifier }, Args) when ?lexical(Identifier) ->
538
542
build_identifier ({ _ , Line , Identifier }, Args ) ->
539
543
{ Identifier , meta (Line ), Args }.
540
544
541
- extract_identifier ({ Kind , _ , Identifier }) when
542
- Kind == identifier ; Kind == bracket_identifier ; Kind == paren_identifier ;
543
- Kind == do_identifier ; Kind == op_identifier ->
544
- Identifier ;
545
-
546
- extract_identifier (Other ) -> Other .
547
-
548
545
% % Fn
549
546
550
547
build_fn (Op , Stab ) ->
0 commit comments