Hi all -
I have a problem with this code (for a mini-Oberon compiler I'm doing).
I have to admit that the code is AI-generated - my apologies for that.
Anyway, here is the code -
# main.roc
# The entry-point of the mini-Oberon compiler
# This code is released to the public domain.
# "Share and enjoy....." :)
app "mini-oberon" provides [main] to "./platform"
import Lexer exposing [lex]
import Parser exposing [parse]
import Semantic exposing [semanticAnalyze]
import Ir exposing [generateIr]
import Optimiser exposing [optimizeIr]
import Codegen exposing [generateAssembly]
import Cli exposing [getArg]
main =
when getArg 1 is
Ok -> filePath =
readFile filePath
|> Result.andThen compile
|> case of
Ok assembly =>
Debug.log "Generated Assembly" assembly
Err msg =>
Debug.log "Compilation Error" msg
Err _ =>
Debug.log "Usage: mini-oberon <source-file>"
readFile : Str -> Result Str Str
readFile filePath =
File.read filePath
compile : Str -> Result Str Str
compile source =
lex source
|> Result.andThen parse
|> Result.andThen semanticAnalyze
|> Result.andThen generateIr
|> Result.map optimizeIr
|> Result.map generateAssembly
This gives me an error as follows -
andy@obsidian:~/mini-Oberon$ roc build
The current directory (/home/andy/mini-Oberon) does not contain a main.roc file to use as a default.
You can run `roc help` for more information on how to provide a .roc file.
andy@obsidian:~/mini-Oberon$ cd src
andy@obsidian:~/mini-Oberon/src$ ls
codegen ir lexer main.roc old_main.roc optimiser parser semantic
andy@obsidian:~/mini-Oberon/src$ roc build
── UNKNOWN OPERATOR in main.roc ────────────────────────────────────────────────
This looks like an operator, but it's not one I recognize!
21│ Ok -> filePath =
^
I have no specific suggestion for this operator, see
https://www.roc-lang.org/tutorial#operator-desugaring-table for the
full list of operators in Roc.andy@obsidian:~/mini-Oberon/src$
I'm still getting to grips with a few of the operators in Roc so I'm hoping someone may be able to help here.
Many thanks in advance -
@mooseman -- the formatting is a bit messy... would you mind editing your post using a Code Block? https://zulip.com/help/format-your-message-using-markdown#code-blocks
Also it'd be helpful if you posted a link to the code in a repository like GitHub, as that also usually includes syntax highlighting
Luke Boswell said:
Also it'd be helpful if you posted a link to the code in a repository like GitHub, as that also usually includes syntax highlighting
Hi Luke - thanks for your reply and sorry about that.
I've now edited my post and it seems to look better now - many thanks for that link!
I will indeed put the code on Github soon. I didn't want to put it there until it was finished but I'm close to finishing it now so it shouldn't be long before it's up there. Sometime in the next few days, I'm guessing.
Many thanks again - bye for now -
@mooseman the problem here is that you are trying to write a code block without adding a newline to start a block
So just add a newline after the -> on that line, and make sure you add 4 spaces of indent as well
Sam Mohr said:
So just add a newline after the -> on that line, and make sure you add 4 spaces of indent as well
Hi Sam - thanks for that!
Yep, that worked!
Ok, I'll see how I go now....... :)
Cheers - thanks again -
Last updated: Jul 06 2025 at 12:14 UTC