Skip to content

Commit

Permalink
Merge pull request #1189 from mattheww/2022-04_bools
Browse files Browse the repository at this point in the history
Boolean literal expressions
  • Loading branch information
ehuss committed Apr 8, 2022
2 parents 60e99b1 + 9c5c3cb commit 6b6d2a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
13 changes: 8 additions & 5 deletions src/expressions/literal-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
>    | [RAW_BYTE_STRING_LITERAL]\
>    | [INTEGER_LITERAL][^out-of-range]\
>    | [FLOAT_LITERAL]\
>    | [BOOLEAN_LITERAL]
>    | `true` | `false`
>
> [^out-of-range]: A value ≥ 2<sup>128</sup> is not allowed.
A _literal expression_ is an expression consisting of a single token, rather than a sequence of tokens, that immediately and directly denotes the value it evaluates to, rather than referring to it by name or some other evaluation rule.

A literal is a form of [constant expression], so is evaluated (primarily) at compile time.

Each of the lexical [literal][literal tokens] forms described earlier can make up a literal expression.
Each of the lexical [literal][literal tokens] forms described earlier can make up a literal expression, as can the keywords `true` and `false`.

```rust
"hello"; // string type
Expand Down Expand Up @@ -148,10 +148,14 @@ The value of the expression is determined from the string representation of the
## Boolean literal expressions

A boolean literal expression consists of a single [BOOLEAN_LITERAL] token.
A boolean literal expression consists of one of the keywords `true` or `false`.

The expression's type is the primitive [boolean type], and its value is:
* true if the keyword is `true`
* false if the keyword is `false`

> **Note**: This section is incomplete.

[boolean type]: ../types/boolean.md
[constant expression]: ../const_eval.md#constant-expressions
[floating-point types]: ../types/numeric.md#floating-point-types
[lint check]: ../attributes/diagnostics.md#lint-check-attributes
Expand All @@ -176,4 +180,3 @@ A boolean literal expression consists of a single [BOOLEAN_LITERAL] token.
[RAW_BYTE_STRING_LITERAL]: ../tokens.md#raw-byte-string-literals
[INTEGER_LITERAL]: ../tokens.md#integer-literals
[FLOAT_LITERAL]: ../tokens.md#floating-point-literals
[BOOLEAN_LITERAL]: ../tokens.md#boolean-literals
3 changes: 1 addition & 2 deletions src/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ if let (a, 3) = (1, 2) { // "(a, 3)" is refutable, and will not match

> **<sup>Syntax</sup>**\
> _LiteralPattern_ :\
> &nbsp;&nbsp; &nbsp;&nbsp; [BOOLEAN_LITERAL]\
> &nbsp;&nbsp; &nbsp;&nbsp; `true` | `false`\
> &nbsp;&nbsp; | [CHAR_LITERAL]\
> &nbsp;&nbsp; | [BYTE_LITERAL]\
> &nbsp;&nbsp; | [STRING_LITERAL]\
Expand All @@ -132,7 +132,6 @@ if let (a, 3) = (1, 2) { // "(a, 3)" is refutable, and will not match
> &nbsp;&nbsp; | `-`<sup>?</sup> [INTEGER_LITERAL]\
> &nbsp;&nbsp; | `-`<sup>?</sup> [FLOAT_LITERAL]
[BOOLEAN_LITERAL]: tokens.md#boolean-literals
[CHAR_LITERAL]: tokens.md#character-literals
[BYTE_LITERAL]: tokens.md#byte-literals
[STRING_LITERAL]: tokens.md#string-literals
Expand Down
9 changes: 0 additions & 9 deletions src/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,6 @@ Examples of reserved forms:
2.0em; // this is not a pseudoliteral, or `2.0` followed by `em`
```

### Boolean literals

> **<sup>Lexer</sup>**\
> BOOLEAN_LITERAL :\
> &nbsp;&nbsp; &nbsp;&nbsp; `true`\
> &nbsp;&nbsp; | `false`
The two values of the boolean type are written `true` and `false`.

## Lifetimes and loop labels

> **<sup>Lexer</sup>**\
Expand Down

0 comments on commit 6b6d2a0

Please sign in to comment.