-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1de9c91
commit a0eb676
Showing
18 changed files
with
1,788 additions
and
1,595 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,9 +1,58 @@ | ||
//// The form formula language | ||
//// term t := | ||
//// Integer 69 | ||
//// Float 420.69 | ||
//// Conditional if t then t else t | ||
//// Bool TRUE | FALSE | ||
//// Date September 10 1997 | ||
//// Addition + | ||
import gleam/dict | ||
import gleam/result | ||
import squared_away/lang/error | ||
import squared_away/lang/interpreter | ||
import squared_away/lang/interpreter/value | ||
import squared_away/lang/parser | ||
import squared_away/lang/parser/expr | ||
import squared_away/lang/scanner | ||
import squared_away/lang/scanner/token | ||
import squared_away/lang/typechecker | ||
import squared_away/lang/typechecker/typed_expr | ||
|
||
pub fn interpret_grid( | ||
input: dict.Dict(String, Result(typed_expr.TypedExpr, error.CompileError)), | ||
) -> dict.Dict(String, Result(value.Value, error.CompileError)) { | ||
use acc, key, typed_expr <- dict.fold(input, dict.new()) | ||
case typed_expr { | ||
Error(e) -> dict.insert(acc, key, Error(e)) | ||
Ok(typed_expr) -> { | ||
let maybe_value = interpreter.interpret(input, typed_expr) | ||
dict.insert(acc, key, maybe_value) | ||
} | ||
} | ||
} | ||
|
||
pub fn typecheck_grid( | ||
input: dict.Dict(String, Result(expr.Expr, error.CompileError)), | ||
) -> dict.Dict(String, Result(typed_expr.TypedExpr, error.CompileError)) { | ||
use acc, key, expr <- dict.fold(input, dict.new()) | ||
case expr { | ||
Error(e) -> dict.insert(acc, key, Error(e)) | ||
Ok(expr) -> { | ||
let maybe_typed_expr = typechecker.typecheck(input, expr) | ||
dict.insert(acc, key, maybe_typed_expr) | ||
} | ||
} | ||
} | ||
|
||
pub fn parse_grid( | ||
input: dict.Dict(String, Result(List(token.Token), error.CompileError)), | ||
) -> dict.Dict(String, Result(expr.Expr, error.CompileError)) { | ||
use acc, key, toks <- dict.fold(input, dict.new()) | ||
case toks { | ||
Error(e) -> dict.insert(acc, key, Error(e)) | ||
Ok(toks) -> { | ||
let expr = parser.parse(toks) | ||
dict.insert(acc, key, expr |> result.map_error(error.ParseError)) | ||
} | ||
} | ||
} | ||
|
||
pub fn scan_grid( | ||
input: dict.Dict(String, String), | ||
) -> dict.Dict(String, Result(List(token.Token), error.CompileError)) { | ||
use acc, key, src <- dict.fold(input, dict.new()) | ||
let maybe_scanned = scanner.scan(src) |> result.map_error(error.ScanError) | ||
dict.insert(acc, key, maybe_scanned) | ||
} |
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,11 @@ | ||
import squared_away/lang/interpreter/runtime_error | ||
import squared_away/lang/parser/parse_error | ||
import squared_away/lang/scanner/scan_error | ||
import squared_away/lang/typechecker/type_error | ||
|
||
pub type CompileError { | ||
ScanError(scan_error.ScanError) | ||
ParseError(parse_error.ParseError) | ||
TypeError(type_error.TypeError) | ||
RuntimeError(runtime_error.RuntimeError) | ||
} |
Oops, something went wrong.