Skip to content

Parse prefix assignment with a discarded rest#45

Merged
lpil merged 1 commit into
lpil:mainfrom
alvivi:concatenate-pattern-discard-rest
Jun 16, 2026
Merged

Parse prefix assignment with a discarded rest#45
lpil merged 1 commit into
lpil:mainfrom
alvivi:concatenate-pattern-discard-rest

Conversation

@alvivi

@alvivi alvivi commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

A string-prefix concatenation pattern that binds the prefix with as and discards the rest — e.g. "a" as letter <> _ — fails to parse with UnexpectedToken(LessGreater, ...), even though the Gleam compiler accepts it.

pattern already handles "a" as x <> rest (named rest) and "a" <> _ (a discarded rest with no prefix assignment), but had no arm combining a prefix assignment with a discarded rest. This adds the missing as Name <> Discarded
arm.

Closes #44.

A string-prefix concatenation pattern that binds the prefix with
`as` and discards the rest, e.g. `"a" as letter <> _`, failed to
parse with `UnexpectedToken(LessGreater, ...)`, even though the
Gleam compiler accepts it.

The `pattern` parser had arms for `"a" as x <> rest` (named rest)
and `"a" <> _` (a discarded rest with no prefix assignment), but
none combining a prefix assignment with a discarded rest. Add the
missing `as Name <> Discarded` arm.

@lpil lpil left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

@lpil
lpil merged commit 140059c into lpil:main Jun 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when parsing a string-prefix pattern with "as" and a discarded rest

2 participants