-
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.
- Loading branch information
Showing
18 changed files
with
716 additions
and
759 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,34 +1,27 @@ | ||
import gleam/dynamic | ||
import gleam/result | ||
import handles/engine | ||
import handles/lexer | ||
import handles/parser | ||
|
||
pub type HandlesError { | ||
LexError(error: lexer.LexError) | ||
ParseError(error: List(parser.ParseError)) | ||
RuntimeError(error: engine.RuntimeError) | ||
} | ||
import gleam/string_builder | ||
import handles/ctx | ||
import handles/error | ||
import handles/internal/engine | ||
import handles/internal/parser | ||
import handles/internal/tokenizer | ||
|
||
pub type Template { | ||
Template(ast: List(parser.AST)) | ||
} | ||
|
||
pub fn prepare(template: String) -> Result(Template, HandlesError) { | ||
use tokens <- result.try(result.map_error(lexer.run(template), LexError)) | ||
use ast <- result.try( | ||
result.map_error(parser.run(tokens, ["if", "unless", "each"]), fn(err) { | ||
ParseError(err) | ||
}), | ||
) | ||
Ok(Template(ast)) | ||
pub fn prepare(template: String) -> Result(Template, error.TokenizerError) { | ||
tokenizer.run(template, 0, []) | ||
|> result.map(fn(tokens) { | ||
let ast = parser.run(tokens, []) | ||
Template(ast) | ||
}) | ||
} | ||
|
||
pub fn run( | ||
template: Template, | ||
ctx: dynamic.Dynamic, | ||
) -> Result(String, HandlesError) { | ||
root_ctx: List(ctx.Prop), | ||
) -> Result(String, error.RuntimeError) { | ||
let Template(ast) = template | ||
engine.run(ast, ctx) | ||
|> result.map_error(RuntimeError) | ||
engine.run(ast, ctx.Dict(root_ctx), string_builder.new()) | ||
} |
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,12 @@ | ||
pub type Prop { | ||
Prop(key: String, value: Value) | ||
} | ||
|
||
pub type Value { | ||
Str(value: String) | ||
Int(value: Int) | ||
Float(value: Float) | ||
Bool(value: Bool) | ||
Dict(value: List(Prop)) | ||
List(value: List(Value)) | ||
} |
This file was deleted.
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
Oops, something went wrong.