-
-
Notifications
You must be signed in to change notification settings - Fork 370
Description
This bug isn't affecting me right now.
If I have a file called test.roc:
app [main!] {
pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.6/2BfGn4M9uWJNhDVeMghGeXNVDFijMfPsmmVeo6M4QjKX.tar.zst"
}
import pf.Stdout
main! : List(Str) => Try({}, [Exit(I32)])
main! = |_args| {
utf8 = Str.to_utf8("15%15==0")
result = parse_value!(utf8, get_next_token!(utf8, 0))
Stdout.line!("result: ${Str.inspect(result)}")
Ok({})
}
NumericRangeType : [
ExcludesEndValue, # ..<
IncludesEndValue, # ..=
]
TokenContents : [
EqualToken, # ==
ModuloToken, # %
UIntDigitsToken(U64),
Err(Str),
EndOfFileToken,
]
tokenize_digits : List(U8), U64, List(U8) -> (List(U8), U64)
tokenize_digits = |file, index, digits| {
match List.get(file, index) {
Ok(c) => {
if '0' <= c and c <= '9' {
return tokenize_digits(file, index + 1, List.append(digits, c))
} else if c == '_' {
return tokenize_digits(file, index + 1, digits)
}
}
_ => {}
}
(digits, index)
}
TokenizerResult : (
TokenContents,
U64, # Index of start of token/error
U64, # New index in file
)
get_next_token! : List(U8), U64 => TokenizerResult
get_next_token! = |file, index| {
Stdout.line!(index.to_str())
match List.get(file, index) {
Ok('%') => (ModuloToken, index, index + 1)
Ok('=') => {
match List.get(file, index+1) {
Ok('=') => (EqualToken, index, index + 2)
_ => (Err("todo"), index, index + 1)
}
}
Ok(c) => {
if ('0' <= c and c <= '9') {
# TODO: Add support for negatives and decimals
(digits, index2) = tokenize_digits(file, index + 1, [c])
str = Str.from_utf8_lossy(digits)
token : TokenContents
token = match U64.from_str(str) {
Ok(num) => UIntDigitsToken(num)
Err(_) => Err("todo")
}
(token, index, index2)
} else {
(Err("todo"), index, index + 1)
}
}
Err(_) => {
(EndOfFileToken, index, index)
}
}
}
ValueCombinationMethod := [
BooleanAnd, BooleanOr, BooleanNot,
IsEqual, IsNotEqual, IsGreaterThan, IsLessThan, IsGreaterThanOrEqual, IsLessThanOrEqual,
Multiply, Divide, Modulo,
Add, Subtract,
]
Value := [
VariableReference(Str),
UInt(U64),
Int(I64),
Float(F64),
CombinedValue({
combination_method: ValueCombinationMethod,
value1: Value,
value2: Value,
}),
]
parse_first_value! : TokenContents, U64 => Try((Value, U64), Str)
parse_first_value! = |token, index| {
match token {
UIntDigitsToken(x) => Ok((UInt(x), index))
_ => {
Err("todo")
}
}
}
parse_value! : List(U8), TokenizerResult => Try(Value, Str)
parse_value! = |file, (_token, _token_pos, var $index)| {
value1 : Value
value1 = UInt(3)
(token2, _token2_pos, $index) = get_next_token!(file, $index)
combination_method1 : ValueCombinationMethod
combination_method1 = match token2 {
ModuloToken => Modulo
# TODO
_ => {
Stdout.line!("Returning early from parse_value!")
return Ok(value1)
}
}
Stdout.line!("finished creating combination method 1 in parse_value!")
value2 = parse_value!(file, get_next_token!(file, $index))?
value = CombinedValue({combination_method: combination_method1, value1, value2})
Ok(value)
}
Then, when I try to run the file with roc test.roc, I get the error:
Error evaluating: TypeContainedMismatch
The version of the roc compiler that I am using is compiled from ad88807.
Reactions are currently unavailable