Skip to content

Commit

Permalink
Add OPTIONAL, OPT back to UPARSE
Browse files Browse the repository at this point in the history
This adds OPTIONAL and OPT, but temporarily bridges over still tolerating
TRY, which will be deprecated after a while.
  • Loading branch information
hostilefork committed Mar 9, 2024
1 parent 569b25e commit d8212c6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/mezz/uparse.r
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,17 @@ default-combinators: make map! reduce [

=== BASIC KEYWORDS ===

'opt combinator [
'try combinator [
{If applying parser fails, succeed and return NULL; don't advance input}
return: "PARSER's result if it succeeds, otherwise NULL"
[any-value? pack?]
parser [action?]
<local> result'
][
fail "OPT combinator replaced in UPARSE by TRY"
fail "TRY combinator changed back to OPTIONAL (or abbreviate as OPT)"
]

'try combinator [
'optional combinator [
{If applying parser fails, succeed and return NULL; don't advance input}
return: "PARSER's result if it succeeds, otherwise NULL"
[any-value? pack?]
Expand Down Expand Up @@ -2588,6 +2588,12 @@ default-combinators: make map! reduce [
default-combinators.(tuple!): default-combinators.(word!)


=== ABBREVIATIONS ===

default-combinators.opt: default-combinators.optional
default-combinators.try: default-combinators.optional ; deprecated


=== COMPATIBILITY FOR NON-TAG KEYWORD FORMS ===

; !!! This has been deprecated. But it's currently possible to get this
Expand Down

0 comments on commit d8212c6

Please sign in to comment.