Skip to content

Commit

Permalink
[spec] Better align EBNF grammars in the lexical syntax chapter.
Browse files Browse the repository at this point in the history
[Cherry-picked 18c8f91]
  • Loading branch information
sjrd authored and WojciechMazur committed Jun 19, 2024
1 parent 1fa7c83 commit 6cda0e8
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions docs/_spec/01-lexical-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ colon ::= ':' -- with side conditions explained above
## Identifiers

```ebnf
op ::= opchar {opchar}
varid ::= lower idrest
boundvarid ::= varid
| ‘`’ varid ‘`’
alphaid ::= upper idrest
| varid
plainid ::= alphaid
| op
id ::= plainid
| ‘`’ { charNoBackQuoteOrNewline | escapeSeq } ‘`’
idrest ::= {letter | digit} [‘_’ op]
op ::= opchar {opchar}
varid ::= lower idrest
boundvarid ::= varid
| ‘`’ varid ‘`’
alphaid ::= upper idrest
| varid
plainid ::= alphaid
| op
id ::= plainid
| ‘`’ { charNoBackQuoteOrNewline | escapeSeq } ‘`’
idrest ::= {letter | digit} [‘_’ op]
escapeSeq ::= UnicodeEscape | charEscapeSeq
UnicodeEscape ::= ‘\’ ‘u’ {‘u’} hexDigit hexDigit hexDigit hexDigit
hexDigit ::= ‘0’ | ... | ‘9’ | ‘A’ | ... | ‘F’ | ‘a’ | ... | ‘f’
Expand Down Expand Up @@ -177,9 +177,8 @@ _ ) ] }
The tokens that can begin a statement are all Scala tokens _except_ the following delimiters and reserved words:

```
catch else extends finally forSome match
with yield , . ; : = => <- <: <%
>: # [ ) ] }
catch else extends finally forSome match with yield
, . ; : = => <- <: <% >: # [ ) ] }
```

A `case` token can begin a statement only if followed by a
Expand Down Expand Up @@ -334,8 +333,7 @@ Literal ::= [‘-’] integerLiteral
### Integer Literals

```ebnf
integerLiteral ::= (decimalNumeral | hexNumeral)
[‘L’ | ‘l’]
integerLiteral ::= (decimalNumeral | hexNumeral) [‘L’ | ‘l’]
decimalNumeral ::= ‘0’ | digit [{digit | ‘_’} digit]
hexNumeral ::= ‘0’ (‘x’ | ‘X’) hexDigit [{hexDigit | ‘_’} hexDigit]
```
Expand Down Expand Up @@ -366,11 +364,10 @@ The digits of a numeric literal may be separated by arbitrarily many underscores
### Floating Point Literals

```ebnf
floatingPointLiteral
::= [decimalNumeral] ‘.’ digit [{digit | ‘_’} digit] [exponentPart] [floatType]
| decimalNumeral exponentPart [floatType]
| decimalNumeral floatType
exponentPart ::= (‘E’ | ‘e’) [‘+’ | ‘-’] digit [{digit | ‘_’} digit]
floatingPointLiteral ::= [decimalNumeral] ‘.’ digit [{digit | ‘_’} digit] [exponentPart] [floatType]
| decimalNumeral exponentPart [floatType]
| decimalNumeral floatType
exponentPart ::= (‘E’ | ‘e’) [‘+’ | ‘-’] digit [{digit | ‘_’} digit]
```

Floating point literals are of type `Float` when followed by a floating point type suffix `F` or `f`, and are of type `Double` otherwise.
Expand Down

0 comments on commit 6cda0e8

Please sign in to comment.