From db7b25d0423550aed2cb9e283c1b04f2468acdd4 Mon Sep 17 00:00:00 2001 From: Jerry Luk Date: Sat, 11 Jul 2026 18:33:22 +0000 Subject: [PATCH] Namespace leex/yecc modules to localize_* to coexist with ex_cldr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit localize's parsers were extracted from ex_cldr with their module names intact (rbnf_parser, plural_rules_lexer, ...), so an app that depends on both localize (e.g. via ex_money 6) and ex_cldr/ex_cldr_numbers fails `mix release` with "Duplicated modules" — the BEAM has one flat module namespace and release assembly rejects the clash. Renaming the grammar files (module name = filename for leex/yecc) with a localize_ prefix and updating the 12 call sites resolves it; full suite passes unchanged. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01JUoqST4frEDRNjMyVnKZhT --- lib/localize/datetime/format/compiler.ex | 4 ++-- lib/localize/number/format/compiler.ex | 6 +++--- lib/localize/number/plural_rules/compiler.ex | 10 +++++----- lib/localize/number/rbnf/rule.ex | 4 ++-- ...t_lexer.xrl => localize_date_time_format_lexer.xrl} | 0 ...ts_lexer.xrl => localize_decimal_formats_lexer.xrl} | 0 ..._parser.yrl => localize_decimal_formats_parser.yrl} | 0 ...rules_lexer.xrl => localize_plural_rules_lexer.xrl} | 0 ...les_parser.yrl => localize_plural_rules_parser.yrl} | 0 src/{rbnf_lexer.xrl => localize_rbnf_lexer.xrl} | 0 src/{rbnf_parser.yrl => localize_rbnf_parser.yrl} | 0 test/localize/number/rbnf_rule_processor_test.exs | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) rename src/{date_time_format_lexer.xrl => localize_date_time_format_lexer.xrl} (100%) rename src/{decimal_formats_lexer.xrl => localize_decimal_formats_lexer.xrl} (100%) rename src/{decimal_formats_parser.yrl => localize_decimal_formats_parser.yrl} (100%) rename src/{plural_rules_lexer.xrl => localize_plural_rules_lexer.xrl} (100%) rename src/{plural_rules_parser.yrl => localize_plural_rules_parser.yrl} (100%) rename src/{rbnf_lexer.xrl => localize_rbnf_lexer.xrl} (100%) rename src/{rbnf_parser.yrl => localize_rbnf_parser.yrl} (100%) diff --git a/lib/localize/datetime/format/compiler.ex b/lib/localize/datetime/format/compiler.ex index 45b284d4b..d6ccc4be7 100644 --- a/lib/localize/datetime/format/compiler.ex +++ b/lib/localize/datetime/format/compiler.ex @@ -34,7 +34,7 @@ defmodule Localize.DateTime.Format.Compiler do def tokenize(format_string) when is_binary(format_string) do format_string |> String.to_charlist() - |> :date_time_format_lexer.string() + |> :localize_date_time_format_lexer.string() |> maybe_add_decimal_separator() |> maybe_return_error(format_string) end @@ -67,7 +67,7 @@ defmodule Localize.DateTime.Format.Compiler do [first | seconds_followed_by_fraction(rest)] end - defp maybe_return_error({:error, {_, :date_time_format_lexer, {_, error}}, _}, format) do + defp maybe_return_error({:error, {_, :localize_date_time_format_lexer, {_, error}}, _}, format) do {:error, Localize.DateTimeFormatError.exception( format: format, diff --git a/lib/localize/number/format/compiler.ex b/lib/localize/number/format/compiler.ex index 494886f9f..eb0c468ad 100644 --- a/lib/localize/number/format/compiler.ex +++ b/lib/localize/number/format/compiler.ex @@ -60,7 +60,7 @@ defmodule Localize.Number.Format.Compiler do def tokenize(definition) when is_binary(definition) do definition |> String.to_charlist() - |> :decimal_formats_lexer.string() + |> :localize_decimal_formats_lexer.string() end @doc """ @@ -88,7 +88,7 @@ defmodule Localize.Number.Format.Compiler do """ @spec parse(String.t() | list()) :: {:ok, Keyword.t()} | {:error, term()} def parse(tokens) when is_list(tokens) do - :decimal_formats_parser.parse(tokens) + :localize_decimal_formats_parser.parse(tokens) end def parse("") do @@ -97,7 +97,7 @@ defmodule Localize.Number.Format.Compiler do def parse(definition) when is_binary(definition) do {:ok, tokens, _end_line} = tokenize(definition) - :decimal_formats_parser.parse(tokens) + :localize_decimal_formats_parser.parse(tokens) end def parse(nil) do diff --git a/lib/localize/number/plural_rules/compiler.ex b/lib/localize/number/plural_rules/compiler.ex index de9e256a0..b0753dea8 100644 --- a/lib/localize/number/plural_rules/compiler.ex +++ b/lib/localize/number/plural_rules/compiler.ex @@ -3,8 +3,8 @@ defmodule Localize.Number.PluralRule.Compiler do # Compiles CLDR plural rule definitions into Elixir AST. # - # Uses the Erlang leex lexer (`:plural_rules_lexer`) and yecc parser - # (`:plural_rules_parser`) to tokenize and parse rule definitions + # Uses the Erlang leex lexer (`:localize_plural_rules_lexer`) and yecc parser + # (`:localize_plural_rules_parser`) to tokenize and parse rule definitions # from the ICU/CLDR plural rules syntax. @doc """ @@ -27,7 +27,7 @@ defmodule Localize.Number.PluralRule.Compiler do def tokenize(definition) when is_binary(definition) do definition |> String.to_charlist() - |> :plural_rules_lexer.string() + |> :localize_plural_rules_lexer.string() end @doc """ @@ -49,11 +49,11 @@ defmodule Localize.Number.PluralRule.Compiler do """ def parse(tokens) when is_list(tokens) do - :plural_rules_parser.parse(tokens) + :localize_plural_rules_parser.parse(tokens) end def parse(definition) when is_binary(definition) do {:ok, tokens, _end_line} = tokenize(definition) - :plural_rules_parser.parse(tokens) + :localize_plural_rules_parser.parse(tokens) end end diff --git a/lib/localize/number/rbnf/rule.ex b/lib/localize/number/rbnf/rule.ex index 0cdc8c6a6..aca8174b9 100644 --- a/lib/localize/number/rbnf/rule.ex +++ b/lib/localize/number/rbnf/rule.ex @@ -59,7 +59,7 @@ defmodule Localize.Number.Rbnf.Rule do definition |> String.trim_leading("'") |> String.to_charlist() - |> :rbnf_lexer.string() + |> :localize_rbnf_lexer.string() end def tokenize(%__MODULE__{definition: definition}) do @@ -86,6 +86,6 @@ defmodule Localize.Number.Rbnf.Rule do end def parse(tokens) when is_list(tokens) do - :rbnf_parser.parse(tokens) + :localize_rbnf_parser.parse(tokens) end end diff --git a/src/date_time_format_lexer.xrl b/src/localize_date_time_format_lexer.xrl similarity index 100% rename from src/date_time_format_lexer.xrl rename to src/localize_date_time_format_lexer.xrl diff --git a/src/decimal_formats_lexer.xrl b/src/localize_decimal_formats_lexer.xrl similarity index 100% rename from src/decimal_formats_lexer.xrl rename to src/localize_decimal_formats_lexer.xrl diff --git a/src/decimal_formats_parser.yrl b/src/localize_decimal_formats_parser.yrl similarity index 100% rename from src/decimal_formats_parser.yrl rename to src/localize_decimal_formats_parser.yrl diff --git a/src/plural_rules_lexer.xrl b/src/localize_plural_rules_lexer.xrl similarity index 100% rename from src/plural_rules_lexer.xrl rename to src/localize_plural_rules_lexer.xrl diff --git a/src/plural_rules_parser.yrl b/src/localize_plural_rules_parser.yrl similarity index 100% rename from src/plural_rules_parser.yrl rename to src/localize_plural_rules_parser.yrl diff --git a/src/rbnf_lexer.xrl b/src/localize_rbnf_lexer.xrl similarity index 100% rename from src/rbnf_lexer.xrl rename to src/localize_rbnf_lexer.xrl diff --git a/src/rbnf_parser.yrl b/src/localize_rbnf_parser.yrl similarity index 100% rename from src/rbnf_parser.yrl rename to src/localize_rbnf_parser.yrl diff --git a/test/localize/number/rbnf_rule_processor_test.exs b/test/localize/number/rbnf_rule_processor_test.exs index f2ee48f17..b63107db0 100644 --- a/test/localize/number/rbnf_rule_processor_test.exs +++ b/test/localize/number/rbnf_rule_processor_test.exs @@ -62,7 +62,7 @@ defmodule Localize.Number.RbnfRuleProcessorTest do end test "returns a parser error for an unterminated construct" do - assert {:error, {1, :rbnf_parser, _reason}} = Rule.parse("twenty[->>];") + assert {:error, {1, :localize_rbnf_parser, _reason}} = Rule.parse("twenty[->>];") end end