23
23
//// - The `empty` built-in procedure that returns an empty list
24
24
25
25
// -- Imports --
26
+ import gleam/dict . { type Dict }
26
27
import gleam/int
27
28
import gleam/list
28
29
import gleam/pair
29
30
import gleam/result
30
31
import gleam/string
31
- import gleam/dict . { type Dict }
32
32
33
33
// -- Types --
34
34
@@ -61,7 +61,7 @@ pub type Scope =
61
61
62
62
/// State represents the state of the interpreter.
63
63
/// It contains the global scope and the local scope.
64
- /// The local scope is used for local variables and
64
+ /// The local scope is used for local variables and
65
65
/// the global scope is used for global variables.
66
66
pub type State {
67
67
State ( global_scope : Scope , local_scope : Scope )
@@ -79,7 +79,7 @@ type Parsed =
79
79
type Procedure =
80
80
fn ( List ( Expression ) , State ) -> Evaluated
81
81
82
- /// Eval function takes a string as an input and returns a result
82
+ /// Eval function takes a string as an input and returns a result
83
83
/// after evaluating the input.
84
84
pub fn eval ( source : String ) -> Result ( String , Error ) {
85
85
source
@@ -94,15 +94,15 @@ const empty = List([])
94
94
95
95
// -- Parsing --
96
96
97
- /// Parse function takes a string as an input and a list of expressions and
97
+ /// Parse function takes a string as an input and a list of expressions and
98
98
/// returns a result after parsing the input.
99
99
fn parse (
100
100
source : String ,
101
101
expressions : List ( Expression ) ,
102
102
) -> Result ( List ( Expression ) , Error ) {
103
103
use # ( expression , rest ) <- result . try ( parse_expression ( source ) )
104
104
let expressions = [ expression , .. expressions ]
105
- case string . trim_left ( rest ) {
105
+ case string . trim_start ( rest ) {
106
106
"" -> Ok ( list . reverse ( expressions ) )
107
107
_ -> parse ( rest , expressions )
108
108
}
@@ -112,7 +112,7 @@ fn parse(
112
112
/// after parsing the expressions included in the source.
113
113
/// Also checks for unexpected end of file and unexpected close parenthesis.
114
114
fn parse_expression ( source : String ) -> Parsed {
115
- let source = string . trim_left ( source )
115
+ let source = string . trim_start ( source )
116
116
case source {
117
117
"" -> Error ( UnexpectedEndOfFile )
118
118
")" <> _ -> Error ( UnexpectedCloseParen )
@@ -133,7 +133,7 @@ fn tail_recursive_parse_list(
133
133
source : String ,
134
134
elements : List ( Expression ) ,
135
135
) -> Parsed {
136
- let source = string . trim_left ( source )
136
+ let source = string . trim_start ( source )
137
137
case source {
138
138
"" -> Error ( UnexpectedEndOfFile )
139
139
")" <> rest -> Ok ( # ( List ( list . reverse ( elements ) ) , rest ) )
@@ -146,7 +146,7 @@ fn tail_recursive_parse_list(
146
146
147
147
/// Parse_atom function takes a string as a source and returns a result
148
148
/// Atoms can be integers, booleans or symbols.
149
- /// This function also checks for unexpected end of file and
149
+ /// This function also checks for unexpected end of file and
150
150
/// unexpected close parenthesis.
151
151
fn parse_atom ( source : String ) -> Parsed {
152
152
let # ( content , rest ) = parse_atom_content ( source , "" )
@@ -461,7 +461,7 @@ fn let_builtin(expressions: List(Expression), state: State) -> Evaluated {
461
461
Ok ( # ( value , set_locals ( state , original_locals ) ) )
462
462
}
463
463
464
- /// Evaluate_binding function takes a state and a binding and returns a result
464
+ /// Evaluate_binding function takes a state and a binding and returns a result
465
465
/// after evaluating the binding.
466
466
fn evaluate_binding ( state : State , binding : Expression ) -> Result ( State , Error ) {
467
467
use binding <- result . try ( expect_list ( binding ) )
@@ -575,7 +575,7 @@ fn type_error(expected: String, value: Expression) -> Result(anything, Error) {
575
575
/// arity_error function takes an expected arity and a list of expressions and
576
576
/// returns a result after creating an arity error.
577
577
/// It is used to create an arity error when the expected arity and the length
578
- ///
578
+ ///
579
579
fn arity_error ( expected : Int , got : List ( a) ) -> Result ( anything, Error ) {
580
580
Error ( IncorrectArity ( expected : expected , got : list . length ( got ) ) )
581
581
}
@@ -665,7 +665,7 @@ fn type_name(value: Expression) -> String {
665
665
}
666
666
}
667
667
668
- /// Print function takes an expression and prints a string representing the
668
+ /// Print function takes an expression and prints a string representing the
669
669
/// expression.
670
670
fn print ( value : Expression ) -> String {
671
671
case value {
0 commit comments