2.1 Implicit Forms
Rhombus parsing is driven by bindings even for forms that have no apparent name, such as a literal expression like 7 or square brackets like [1, 2, 3]. In those cases without an apparent name an implicit form is used to give meaning to the term, whether in an expression position, binding position, or other kind of position. For positions that allow only prefix operators, such as definition positions, only prefix implicits are used. Here are all of the implicit forms:
#%literal —
used for anything other than an identifier, keyword, operator, or compound form #%parens —
used for (…) #%brackets —
used for […] #%braces —
used for {…} #%quotes —
used for '…' #%call —
used as an infix form when a parsed form is followed immediately by a (…) term #%index —
used as an infix form when a parsed form is followed immediately by a […] term #%comp —
used as an infix form when a parsed form is followed immediately by a {…} term; this implicit form is not bound by rhombus #%juxtapose —
used as an infix form when a parsed form is followed immediately by a non-compound term; this implicit form is not bound by rhombus #%block —
used for a block formed with : (by itself as a would-be parsed term); this implicit form is not bound by rhombus #%alts —
used for a block formed with | (by itself as a would-be parsed term); this implicit form is not bound by rhombus #%body —
used by forms that contain a body sequence, such as block, the body of fun, and the result part of a match clause; the lexical context of the : or | that forms a block determines the #%body binding that is used
expression | |
| |
| |
binding operator | |
| |
| |
annotation | |
| |
| |
repetition | |
|
A literal is any individual term other than an identifier, keyword, operator, parenthesized term, bracketed term, braced term, quoted term, block, or alternatives.
> 7
7
> #%literal 7
7
> fun only_sevens(7): "yes"
> only_sevens(7)
"yes"
> only_sevens(8)
only_sevens: argument does not satisfy annotation
argument: 8
annotation: matching(7)
expression | |
| |
binding operator | |
| |
annotation | |
| |
entry point | |
| |
immediate callee | |
| |
expression | |
| |
entry point | |
| |
immediate callee | |
| |
annotation | |
Produces the same value as expr, same binding as bind, and so on. Multiple expression, bindings, etc., are disallowed.
The expression case with an immediate _ in parentheses among other terms is a special case for a function shorthand, and it takes precedence over parsing the parenthesized sequence as an expr. See _ for more information.
The entry point and immediate callee bindings allow parentheses to be used around such forms, and they allow the function shorthand to cooperate in those positions.
The #%parens annotation form cooperates with -> to enable multiple argument annotations in parentheses. A -> annotation is assumed whenever the parenthesized term for #%parens is followed by ->.
> (1+2)
3
3
> x
3