Skip to content

Update to work with new std library string.trim_start #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: "26.0.2"
gleam-version: "1.0.0"
otp-version: "27.1.2"
gleam-version: "1.9.1"
rebar3-version: "3"
- run: gleam deps download
- run: gleam test --target erlang
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

- Updated for Gleam v1.9.1
- Update code actions
- Update dependencies
- Replace removed `string.trim_left` with `string.trim_start`

## v1.2.0 - 2022-05-29

- Make the library compatible with the JavaScript target
Expand Down
8 changes: 4 additions & 4 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ description = "A Gleam Lisp interpreter"

repository = { type = "github", user = "gleam-lang", repo = "example_lisp_interpreter" }
links = [
{ title = "Website", href = "https://gleam.run" },
{ title = "Sponsor", href = "https://github.com/sponsors/lpil" },
{ title = "Website", href = "https://gleam.run" },
{ title = "Sponsor", href = "https://github.com/sponsors/lpil" },
]

[dependencies]
gleam_stdlib = "~> 0.34 or ~> 1.0"
gleam_stdlib = ">= 0.44.0 and < 2.0.0"

[dev-dependencies]
gleeunit = "~> 1.0"
gleeunit = ">= 1.0.0 and < 2.0.0"
8 changes: 4 additions & 4 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
{ name = "gleam_stdlib", version = "0.58.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "091F2D2C4A3A4E2047986C47E2C2C9D728A4E068ABB31FDA17B0D347E6248467" },
{ name = "gleeunit", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "0E6C83834BA65EDCAAF4FE4FB94AC697D9262D83E6F58A750D63C9F6C8A9D9FF" },
]

[requirements]
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
gleeunit = { version = "~> 1.0" }
gleam_stdlib = { version = ">= 0.44.0 and < 2.0.0" }
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
22 changes: 11 additions & 11 deletions src/glisp.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
//// - The `empty` built-in procedure that returns an empty list

// -- Imports --
import gleam/dict.{type Dict}
import gleam/int
import gleam/list
import gleam/pair
import gleam/result
import gleam/string
import gleam/dict.{type Dict}

// -- Types --

Expand Down Expand Up @@ -61,7 +61,7 @@ pub type Scope =

/// State represents the state of the interpreter.
/// It contains the global scope and the local scope.
/// The local scope is used for local variables and
/// The local scope is used for local variables and
/// the global scope is used for global variables.
pub type State {
State(global_scope: Scope, local_scope: Scope)
Expand All @@ -79,7 +79,7 @@ type Parsed =
type Procedure =
fn(List(Expression), State) -> Evaluated

/// Eval function takes a string as an input and returns a result
/// Eval function takes a string as an input and returns a result
/// after evaluating the input.
pub fn eval(source: String) -> Result(String, Error) {
source
Expand All @@ -94,15 +94,15 @@ const empty = List([])

// -- Parsing --

/// Parse function takes a string as an input and a list of expressions and
/// Parse function takes a string as an input and a list of expressions and
/// returns a result after parsing the input.
fn parse(
source: String,
expressions: List(Expression),
) -> Result(List(Expression), Error) {
use #(expression, rest) <- result.try(parse_expression(source))
let expressions = [expression, ..expressions]
case string.trim_left(rest) {
case string.trim_start(rest) {
"" -> Ok(list.reverse(expressions))
_ -> parse(rest, expressions)
}
Expand All @@ -112,7 +112,7 @@ fn parse(
/// after parsing the expressions included in the source.
/// Also checks for unexpected end of file and unexpected close parenthesis.
fn parse_expression(source: String) -> Parsed {
let source = string.trim_left(source)
let source = string.trim_start(source)
case source {
"" -> Error(UnexpectedEndOfFile)
")" <> _ -> Error(UnexpectedCloseParen)
Expand All @@ -133,7 +133,7 @@ fn tail_recursive_parse_list(
source: String,
elements: List(Expression),
) -> Parsed {
let source = string.trim_left(source)
let source = string.trim_start(source)
case source {
"" -> Error(UnexpectedEndOfFile)
")" <> rest -> Ok(#(List(list.reverse(elements)), rest))
Expand All @@ -146,7 +146,7 @@ fn tail_recursive_parse_list(

/// Parse_atom function takes a string as a source and returns a result
/// Atoms can be integers, booleans or symbols.
/// This function also checks for unexpected end of file and
/// This function also checks for unexpected end of file and
/// unexpected close parenthesis.
fn parse_atom(source: String) -> Parsed {
let #(content, rest) = parse_atom_content(source, "")
Expand Down Expand Up @@ -461,7 +461,7 @@ fn let_builtin(expressions: List(Expression), state: State) -> Evaluated {
Ok(#(value, set_locals(state, original_locals)))
}

/// Evaluate_binding function takes a state and a binding and returns a result
/// Evaluate_binding function takes a state and a binding and returns a result
/// after evaluating the binding.
fn evaluate_binding(state: State, binding: Expression) -> Result(State, Error) {
use binding <- result.try(expect_list(binding))
Expand Down Expand Up @@ -575,7 +575,7 @@ fn type_error(expected: String, value: Expression) -> Result(anything, Error) {
/// arity_error function takes an expected arity and a list of expressions and
/// returns a result after creating an arity error.
/// It is used to create an arity error when the expected arity and the length
///
///
fn arity_error(expected: Int, got: List(a)) -> Result(anything, Error) {
Error(IncorrectArity(expected: expected, got: list.length(got)))
}
Expand Down Expand Up @@ -665,7 +665,7 @@ fn type_name(value: Expression) -> String {
}
}

/// Print function takes an expression and prints a string representing the
/// Print function takes an expression and prints a string representing the
/// expression.
fn print(value: Expression) -> String {
case value {
Expand Down