-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plumb errors and stuff through for multi-file programs
- Loading branch information
1 parent
f6d6bab
commit 38a9a4e
Showing
7 changed files
with
106 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
import compiler/generator | ||
import compiler/program | ||
import compiler/transformer | ||
import glance | ||
import gleam/dict | ||
import gleam/result | ||
|
||
// called only by unit tests | ||
// todo: remove | ||
pub fn compile(module_contents: String) -> Result(String, glance.Error) { | ||
module_contents | ||
|> glance.module | ||
|> result.map(transformer.transform) | ||
|> result.map(generator.generate) | ||
} | ||
|
||
pub fn compile_module(glance_module: glance.Module) -> String { | ||
glance_module | ||
|> transformer.transform | ||
|> generator.generate | ||
} | ||
|
||
pub fn compile_program(program: program.GleamProgram) -> program.CompiledProgram { | ||
program.CompiledProgram( | ||
modules: program.modules | ||
|> dict.map_values(fn(_key, value) { compile_module(value) }), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import glance | ||
import internal/errors as internal | ||
import simplifile | ||
|
||
pub type Error { | ||
FileReadError(module: String, error: simplifile.FileError) | ||
FileWriteError(module: String, error: simplifile.FileError) | ||
GlanceParseError(error: glance.Error, module: String, contents: String) | ||
} | ||
|
||
pub fn format_error(error: Error) -> String { | ||
case error { | ||
FileReadError(filename, simplifile.Enoent) -> "File not found " <> filename | ||
FileReadError(filename, _) -> "Unable to read " <> filename | ||
FileWriteError(filename, _) -> "Unable to write " <> filename | ||
GlanceParseError(error, filename, contents) -> | ||
internal.format_glance_error(error, filename, contents) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters