mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00

Implements the new `module` header syntax as described in "module and package changes" [1]: ``` module [Request, Response, req] ``` The old syntax should still work fine, and is automatically upgraded to the new one when running `roc format`. [1] https://docs.google.com/document/d/1E_77fO-44BtoBtXoVeWyGh1xN2KRTWTu8q6i25RNNx0/edit
34 lines
782 B
Text
34 lines
782 B
Text
module [Variable, fromUtf8, toIndex, totalCount, toStr]
|
|
|
|
# Variables in False can only be single letters. Thus, the valid variables are "a" to "z".
|
|
# This opaque type deals with ensure we always have valid variables.
|
|
Variable := U8
|
|
|
|
totalCount : U64
|
|
totalCount =
|
|
0x7A # "z"
|
|
- 0x61 # "a"
|
|
+ 1
|
|
|
|
toStr : Variable -> Str
|
|
toStr = \@Variable char ->
|
|
when Str.fromUtf8 [char] is
|
|
Ok str -> str
|
|
_ -> "_"
|
|
|
|
fromUtf8 : U8 -> Result Variable [InvalidVariableUtf8]
|
|
fromUtf8 = \char ->
|
|
if
|
|
char
|
|
>= 0x61 # "a"
|
|
&& char
|
|
<= 0x7A # "z"
|
|
then
|
|
Ok (@Variable char)
|
|
else
|
|
Err InvalidVariableUtf8
|
|
|
|
toIndex : Variable -> U64
|
|
toIndex = \@Variable char ->
|
|
Num.intCast (char - 0x61) # "a"
|
|
# List.first (Str.toUtf8 "a")
|