Skip to content

Commit 2719034

Browse files
authored
feat(compiler): Allow a newline character after 'as' when aliasing (#1641)
1 parent 752da69 commit 2719034

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

compiler/src/parsing/parser.messages

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,73 @@ program: MODULE UIDENT EOL FOREIGN WASM LIDENT COLON UIDENT AS YIELD
191191
## The known suffix of the stack is as follows:
192192
## AS
193193
##
194+
program: MODULE UIDENT EOL PROVIDE LBRACE UIDENT AS EOL YIELD
195+
##
196+
## Ends in an error in state: 51.
197+
##
198+
## as_prefix(uid) -> AS option(eols) . uid [ RBRACE EOL COMMA ]
199+
##
200+
## The known suffix of the stack is as follows:
201+
## AS option(eols)
202+
##
203+
## WARNING: This example involves spurious reductions.
204+
## This implies that, although the LR(1) items shown above provide an
205+
## accurate view of the past (what has been recognized so far), they
206+
## may provide an INCOMPLETE view of the future (what was expected next).
207+
## In state 3, spurious reduction of production nonempty_list(eol) -> EOL
208+
## In state 6, spurious reduction of production eols -> nonempty_list(eol)
209+
## In state 53, spurious reduction of production option(eols) -> eols
210+
##
211+
program: MODULE UIDENT EOL PROVIDE LBRACE LIDENT AS EOL YIELD
212+
##
213+
## Ends in an error in state: 98.
214+
##
215+
## as_prefix(lid) -> AS option(eols) . lid [ RBRACE EOL COMMA ]
216+
##
217+
## The known suffix of the stack is as follows:
218+
## AS option(eols)
219+
##
220+
## WARNING: This example involves spurious reductions.
221+
## This implies that, although the LR(1) items shown above provide an
222+
## accurate view of the past (what has been recognized so far), they
223+
## may provide an INCOMPLETE view of the future (what was expected next).
224+
## In state 3, spurious reduction of production nonempty_list(eol) -> EOL
225+
## In state 6, spurious reduction of production eols -> nonempty_list(eol)
226+
## In state 53, spurious reduction of production option(eols) -> eols
227+
##
228+
program: MODULE UIDENT EOL FOREIGN WASM LIDENT COLON UIDENT AS EOL YIELD
229+
##
230+
## Ends in an error in state: 755.
231+
##
232+
## as_prefix(id_str) -> AS option(eols) . id_str [ FROM ]
233+
##
234+
## The known suffix of the stack is as follows:
235+
## AS option(eols)
236+
##
237+
## WARNING: This example involves spurious reductions.
238+
## This implies that, although the LR(1) items shown above provide an
239+
## accurate view of the past (what has been recognized so far), they
240+
## may provide an INCOMPLETE view of the future (what was expected next).
241+
## In state 3, spurious reduction of production nonempty_list(eol) -> EOL
242+
## In state 6, spurious reduction of production eols -> nonempty_list(eol)
243+
## In state 53, spurious reduction of production option(eols) -> eols
244+
##
245+
program: MODULE UIDENT EOL INCLUDE STRING AS EOL YIELD
246+
##
247+
## Ends in an error in state: 823.
248+
##
249+
## include_alias -> AS eols . qualified_uid [ SEMI RBRACE EOL EOF ]
250+
##
251+
## The known suffix of the stack is as follows:
252+
## AS eols
253+
##
254+
## WARNING: This example involves spurious reductions.
255+
## This implies that, although the LR(1) items shown above provide an
256+
## accurate view of the past (what has been recognized so far), they
257+
## may provide an INCOMPLETE view of the future (what was expected next).
258+
## In state 3, spurious reduction of production nonempty_list(eol) -> EOL
259+
## In state 6, spurious reduction of production eols -> nonempty_list(eol)
260+
##
194261

195262
Expected an alias.
196263

compiler/src/parsing/parser.mly

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ value_binds:
310310
| lseparated_nonempty_list(comma, value_bind) { $1 }
311311

312312
as_prefix(X):
313-
| AS X {$2}
313+
| AS opt_eols X {$3}
314314

315315
aliasable(X):
316316
| X as_prefix(X)? {($1, $2)}
@@ -331,7 +331,7 @@ use_stmt:
331331
| FROM qualified_uid USE use_shape { Exp.use ~loc:(to_loc $loc) $2 $4 }
332332

333333
include_alias:
334-
| AS qualified_uid { make_module_alias $2 }
334+
| AS opt_eols qualified_uid { make_module_alias $3 }
335335

336336
include_stmt:
337337
| INCLUDE file_path include_alias? { Inc.mk ~loc:(to_loc $loc) $2 $3 }

compiler/test/formatter_inputs/includes.gr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ include "runtime/unsafe/memory"
44
include "runtime/unsafe/tags"
55
include "list"
66
include "option" as Opt
7+
include "option" as
8+
Opt
79
// TODO(#1627): This comment disappears
810
include /* special include */ "array"
911
include "array" as /* special include */ Foo

compiler/test/formatter_outputs/includes.gr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include "runtime/unsafe/memory"
44
include "runtime/unsafe/tags"
55
include "list"
66
include "option" as Opt
7+
include "option" as Opt
78
// TODO(#1627): This comment disappears
89
include "array"
910
include "array" as Foo

0 commit comments

Comments
 (0)