@@ -7,6 +7,35 @@ module Mint
77 syntax_error FunctionExpectedExpression
88 syntax_error FunctionExpectedName
99
10+ def code_block : Ast ::Block ?
11+ start do |start_position |
12+ char '{' , SyntaxError
13+ whitespace
14+
15+ statements =
16+ many { comment || statement(:none , require_name: true ) }
17+
18+ whitespace
19+
20+ expression =
21+ expression! SyntaxError
22+
23+ whitespace
24+ tail_comments = many { comment }
25+
26+ whitespace
27+ char '}' , SyntaxError
28+
29+ self << Ast ::Block .new(
30+ tail_comments: tail_comments,
31+ statements: statements,
32+ expression: expression,
33+ from: start_position,
34+ to: position,
35+ input: data)
36+ end
37+ end
38+
1039 def function : Ast ::Function ?
1140 start do |start_position |
1241 comment = self .comment
@@ -41,21 +70,24 @@ module Mint
4170 item
4271 end
4372
44- head_comments, body, tail_comments = block_with_comments(
45- opening_bracket: FunctionExpectedOpeningBracket ,
46- closing_bracket: FunctionExpectedClosingBracket
47- ) do
48- expression! FunctionExpectedExpression
49- end
73+ body =
74+ code_block
75+
76+ # head_comments, body, tail_comments = block_with_comments(
77+ # opening_bracket: FunctionExpectedOpeningBracket,
78+ # closing_bracket: FunctionExpectedClosingBracket
79+ # ) do
80+ # expression! FunctionExpectedExpression
81+ # end
5082
5183 end_position = position
5284
5385 whitespace
5486
5587 self << Ast ::Function .new(
88+ head_comments: [] of Ast ::Comment ,
89+ tail_comments: [] of Ast ::Comment ,
5690 body: body.as(Ast ::Expression ),
57- head_comments: head_comments,
58- tail_comments: tail_comments,
5991 arguments: arguments,
6092 from: start_position,
6193 comment: comment,
0 commit comments