Skip to content

EBNF::Base#make_bnf with native parser fails on grammars which use :diff / exception operator #16

@phdavis1027

Description

@phdavis1027

Describe the bug
When trying to convert the EBNF specification of XML 1.0 found here, I get this exception:

/home/phillipdavis/everyday/dev/mboa/maqam/.gems/ruby/3.4.0/gems/ebnf-2.6.0/lib/ebnf/rule.rb:304:in 'EBNF::Rule#to_bnf': Encountered :diff, which is a rule, not :terminal (RuntimeError)
        from /home/phillipdavis/everyday/dev/mboa/maqam/.gems/ruby/3.4.0/gems/ebnf-2.6.0/lib/ebnf/rule.rb:279:in 'block in EBNF::Rule#to_bnf'
        from /home/phillipdavis/everyday/dev/mboa/maqam/.gems/ruby/3.4.0/gems/ebnf-2.6.0/lib/ebnf/rule.rb:279:in 'Array#map'
        from /home/phillipdavis/everyday/dev/mboa/maqam/.gems/ruby/3.4.0/gems/ebnf-2.6.0/lib/ebnf/rule.rb:279:in 'EBNF::Rule#to_bnf'
        from /home/phillipdavis/everyday/dev/mboa/maqam/.gems/ruby/3.4.0/gems/ebnf-2.6.0/lib/ebnf/bnf.rb:15:in 'block in EBNF::BNF#make_bnf'
        from /home/phillipdavis/everyday/dev/mboa/maqam/.gems/ruby/3.4.0/gems/ebnf-2.6.0/lib/ebnf/bnf.rb:13:in 'Array#each'
        from /home/phillipdavis/everyday/dev/mboa/maqam/.gems/ruby/3.4.0/gems/ebnf-2.6.0/lib/ebnf/bnf.rb:13:in 'EBNF::BNF#make_bnf'
        from (irb):10:in '<main>'
        from <internal:kernel>:168:in 'Kernel#loop'
        from /home/phillipdavis/everyday/dev/mboa/maqam/.gems/ruby/3.4.0/gems/irb-1.17.0/exe/irb:9:in '<top (required)>'
        from /home/phillipdavis/everyday/dev/mboa/maqam/.gems/ruby/3.4.0/bin/irb:25:in 'Kernel#load'
        from /home/phillipdavis/everyday/dev/mboa/maqam/.gems/ruby/3.4.0/bin/irb:25:in '<top (required)>'
        from /home/phillipdavis/.local/share/gem/ruby/gems/bundler-2.6.9/lib/bundler/cli/exec.rb:59:in 'Kernel.load'
        from /home/phillipdavis/.local/share/gem/ruby/gems/bundler-2.6.9/lib/bundler/cli/exec.rb:59:in 'Bundler::CLI::Exec#kernel_load'
        from /home/phillipdavis/.local/share/gem/ruby/gems/bundler-2.6.9/lib/bundler/cli/exec.rb:23:in 'Bundler::CLI::Exec#run'
        from /home/phillipdavis/.local/share/gem/ruby/gems/bundler-2.6.9/lib/bundler/cli.rb:452:in 'Bundler::CLI#exec'
        from /home/phillipdavis/.local/share/gem/ruby/gems/bundler-2.6.9/lib/bundler/vendor/thor/lib/thor/command.rb:28:in 'Bundler::Thor::Command#run'
        ... 10 levels...

To reproduce
Steps to reproduce the behavior:

EBNF.parse(/* the grammar */, format: native).make_bnf

Expected behavior
It converts the grammar into a BNF

Screenshots
N/A

Desktop (please complete the following information):
N/A
Smartphone (please complete the following information):
N/A

Additional context

Gems included by the bundle:
  * addressable (2.8.9)
  * ast (2.4.3)
  * base64 (0.3.0)
  * bcp47_spec (0.2.1)
  * bigdecimal (3.3.1)
  * date (3.5.1)
  * ebnf (2.6.0)
  * erb (6.0.2)
  * htmlentities (4.4.2)
  * io-console (0.8.2)
  * irb (1.17.0)
  * jennifer (0.0.0 5f71c9d)
  * json (2.18.1)
  * json-schema (6.1.0)
  * language_server-protocol (3.17.0.5)
  * link_header (0.0.8)
  * lint_roller (1.1.0)
  * logger (1.7.0)
  * maqam (0.1.0)
  * matrix (0.4.3)
  * mcp (0.8.0)
  * minitest (5.27.0)
  * ostruct (0.6.3)
  * parallel (1.27.0)
  * parser (3.3.10.2)
  * pp (0.6.3)
  * prettyprint (0.2.0)
  * prism (1.9.0)
  * psych (5.3.1)
  * public_suffix (7.0.5)
  * racc (1.8.1)
  * rainbow (3.1.1)
  * rake (13.3.1)
  * rantly (3.0.0)
  * rbs (3.10.3)
  * rdf (3.3.4)
  * rdoc (7.2.0)
  * readline (0.0.4)
  * regexp_parser (2.11.3)
  * reline (0.6.3)
  * rubocop (1.85.0)
  * rubocop-ast (1.49.0)
  * ruby-progressbar (1.13.0)
  * scanf (1.0.0)
  * stringio (3.2.0)
  * sxp (2.0.0)
  * tsort (0.2.0)
  * unicode-display_width (3.2.0)
  * unicode-emoji (4.2.0)
  * unicode-types (1.11.0)
phillipdavis in ~/.../mboa/maqam on master✗  λ bundle exec ruby --version
ruby 3.4.8 (2025-12-17 revision 995b59f666) +PRISM [x86_64-linux]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions