Skip to content
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

fix: pull unicode character checks from guard to a function #7

Merged
merged 5 commits into from
Jan 17, 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
5 changes: 4 additions & 1 deletion .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ jobs:
name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
matrix:
otp: ["24.2", "25.3", "26.2"]
otp: ["24.3", "25.3", "26.2"]
elixir: ["1.14.5", "1.15.6", "1.16.1"]
include:
- otp: "27.2"
elixir: "1.18.1"
steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
Expand Down
27 changes: 13 additions & 14 deletions lib/json5/ecma.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ defmodule Json5.ECMA do

defguard is_reserved_word(input) when input in @reserved_names

defguard is_unicode_identifier_letter(x)
when Unicode.Set.match?(
x,
"[[:Lu:][:Ll:][:Lt:][:Lm:][:Lo:][:Nl:][:Mn:][:Mc:][:Nd:][:Pc:]]"
)

defguard is_unicode_letter(x)
when Unicode.Set.match?(
x,
"[[:Lu:][:Ll:][:Lt:][:Lm:][:Lo:][:Nl:]]"
)

def reserved_words do
@reserved_names
end
Expand Down Expand Up @@ -101,14 +89,25 @@ defmodule Json5.ECMA do
defp ecma_identifier_part do
either(
ecma_identifier_start(),
satisfy(char(), &is_unicode_identifier_letter/1)
satisfy(char(), &unicode_identifier_letter?/1)
)
end

defp ecma_unicode_letter do
satisfy(char(), fn
<<ch>> when is_unicode_letter(ch) -> true
<<ch>> -> unicode_letter?(ch)
_ -> false
end)
end

defp unicode_identifier_letter?(x) do
Unicode.Set.match?(
x,
"[[:Lu:][:Ll:][:Lt:][:Lm:][:Lo:][:Nl:][:Mn:][:Mc:][:Nd:][:Pc:]]"
)
end

defp unicode_letter?(x) do
Unicode.Set.match?(x, "[[:Lu:][:Ll:][:Lt:][:Lm:][:Lo:][:Nl:]]")
end
end
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ defmodule Json5.MixProject do
def project do
[
app: :json5,
version: "0.3.2",
elixir: "~> 1.10",
version: "0.4.0",
elixir: "~> 1.14",
description: "Json5 in Elixir",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"makeup_erlang": {:hex, :makeup_erlang, "1.0.0", "6f0eff9c9c489f26b69b61440bf1b238d95badae49adac77973cbacae87e3c2e", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "ea7a9307de9d1548d2a72d299058d1fd2339e3d398560a0e46c27dab4891e4d2"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"},
"unicode": {:hex, :unicode, "1.19.0", "264191eacb1d44039d0dbb9fd936c557431825373b6e7b18d77e80cb0cc344bd", [:mix], [], "hexpm", "ae83bbf54429a67bc6fa9c941a6e9f0ec38dd9c2a32b21583ad511d3b6555631"},
"unicode_set": {:hex, :unicode_set, "1.4.0", "d7f005d5227768fb13a507433925b685be76acfbe6e5a25323c8231b54f59a96", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:unicode, "~> 1.13", [hex: :unicode, repo: "hexpm", optional: false]}], "hexpm", "096d84ecd1f7965b0f0073f00a51bdc9c8d400f085730fcee6f735f1c2d676ef"},
"unicode": {:hex, :unicode, "1.20.0", "10189cfe98b03ebb8be6efd00df0936c1c94d75bfbd62cba2bdf958fef3ee4a7", [:mix], [], "hexpm", "fa581cf80b3b1b7f42e4d24a69109dfac465cec27a62c661306c81f4ab35894c"},
"unicode_set": {:hex, :unicode_set, "1.4.1", "0c5b7498e05acc3104a3fa10d99c0ec9dfa8acd5c9cbfb65b4ae0cc7f210e2e2", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:unicode, "~> 1.13", [hex: :unicode, repo: "hexpm", optional: false]}], "hexpm", "349e38d2843eaa7ea8e6dbded7ffcbb9d54d74ee7524adb7d5c575d468daac3f"},
}
Loading