Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby Parser progress report 2025

Avatar for yui-knk yui-knk
August 30, 2025

Ruby Parser progress report 2025

RubyKaigi 2025 follow up
https://rhc.connpass.com/event/356128/

リンク:
Understanding Ruby Grammar Through Conflicts in RubyConf Taiwan 2025
https://speakerdeck.com/yui_knk/understanding-ruby-grammar-through-conflicts

Avatar for yui-knk

yui-knk

August 30, 2025
Tweet

More Decks by yui-knk

Other Decks in Programming

Transcript

  1. Ruby Parser progress report 2025 April 30, 2025 in RubyKaigi

    2025 follow up @yui-knk Yuichiro Kaneko
  2. ✦ Yuichiro Kaneko ✦ yui-knk (GitHub) / spikeolaf (Twitter) ✦

    Treasure Data ✦ Engineering Manager of Applications Backend ✦ CRuby committer, mainly develop parser generator and parser ✦ Lrama LALR (1) parser generator (2023, Ruby 3.3) ✦ Love LR parser About me
  3. ✦ ٕज़ॻయ18Ͱ৽ץΛ൦෍ ✦ ෺ཧຊ ¥1,000 ✦ ॏ൛ग़དྷʂʂ ✦ ୈ3࡮ ✦

    ిࢠຊ ¥500 ✦ ٕज़ॻయͷαΠτ͔ΒߪೖՄೳ ਐḿ 1.ʮLR parserೖ໳ʯ
  4. ✦ ΈΜͳ͕ࢥ͍ͭ͘Ͱ͋Ζ͏จ๏ͷมߋΛ͍ΕͯΈΔ ✦ ίϯϑϦΫτ͕͓͖ΔͷͰղੳ͢Δ ✦ Rubyͷจ๏ͷσβΠϯ΍੍໿Λߟ͑Δ ✦ Arguments and parameters

    ✦ Command call ✦ Endless method de fi nitions ✦ Pattern matching “Understanding Ruby Grammar Through Con fl icts”
  5. • [Bug #17925] Pattern matching syntax using semicolon one-line •

    https://bugs.ruby-lang.org/issues/17925 • [Bug #18080] Syntax error on one-line pattern matching • https://bugs.ruby-lang.org/issues/18080 • [Bug #21378] variable pinning does not look for method arguments • https://bugs.ruby-lang.org/issues/21378 • [Bug #21097] `x = a rescue b in c` and `def f = a rescue b in c` parsed differently between parse.y and prism • https://bugs.ruby-lang.org/issues/21097 Pattern matchingʹؔ͢Δνέοτ
  6. ✦ pattern matching: “|” (pipe)͸ෳ਺ͷύλʔϯΛ۠੾Δͷʹ࢖ΘΕ Δ ✦ binary operator: “|”

    ͸ೋ߲ԋࢉࢠͰ΋͋Δ Con fl icts on “|” Pattern 1 Pattern 2 Pattern matching arg
  7. ✦ ํ๏1: “,” ͕ଓ͘ݶΓpattern matchingͰ͋ Δͱղऍ͢Δ ✦ ෳ਺ͷҾ਺͕͋Γɺͦ͜ʹpattern matchingؚ͕·ΕΔέʔεΛͲ͏͢Δ͔ ✦

    1. pattern matching͸࠷ޙͷҾ਺ʹ͚ͩॻ ͘͜ͱ͕Ͱ͖Δ ✦ 2. pattern matchingͷͱ͖͸Ҿ਺͸1ͭͩ ͚ॻ͚Δ Con fl ictʹରԠ͢Δ
  8. ✦ IELRͷߴ଎Խ (by junk0612) ✦ ࣮ઓ౤ೖͰ͖Δ଎౓ʹͳͬͨͷͰɺLrama΋LR(1) parser parser generatorΛ ໊৐Δͱ͖͕͖ͨͷͰ͸?

    ✦ Support parameterized rule's arguments include inline (by ydah) ✦ Grammar fi leͰڐՄ͢Δsyntaxͷ֦ு (by ydah) ✦ Output fi leͷ֦ॆ ✦ Con fl ictʹؔ͢Δ৘ใ ✦ ༏ઌ౓ʹؔ͢Δ৘ใ Lrama 0.7.1
  9. ✦ ಺༰ ✦ ୈ1ষ LR parserͷ֓࿦ ✦ ୈ2ষ ޮ཰తͳLookaheadͷܭࢉ ✦

    ෺ཧຊ ¥1,000 ✦ େ޷ධʂʂ ✦ ຊ೔΋ઈࢍൢചதʂ ʮޮ཰తͳLookaheadͷܭࢉʯͱ͍͑͹
  10. ✦ ‘=’ ͱ “rescue” ͱ ‘in’ (ͱ “=>” ?)ͷ༏ઌ౓ͷ໰୊ ✦

    Rubyʹ͓͍ͯଟ͘ͷ୅ೖ͸Ҿ਺ͷཁૉ(arg)Ͱ͋Δ ✦ pattern matchingΛargʹ͠Α͏ͱ͢Δͱແཧ͕͋Δ ✦ ͜Ε΋·ͨstmtϨϕϧͰͷΈڐՄ͢Δํ޲͕Α͍ͷͰ͸ [Bug #21097]
  11. ✦ parser͔Βlexerʹvalidͳlookahead tokenͷू߹Λ౉͢Ξϓϩʔν ✦ LALR͸ෳ਺ͷঢ়ଶΛmerge͢ΔͷͰຊདྷ(Canonical LRతʹ ͸)invalidͳtokenͰ΋reduceΛਐΊΔ͜ͱ͕͋Δ ✦ lexerͷ࢖༻͢Δvalid lookahead

    tokenʹج͍ͮͯಛఆͷঢ়ଶΛ merge͠ͳ͍Α͏ʹ͢ΔͱΑ͍ͷͰ͸? ✦ IELRͷܭࢉ଎౓͕े෼ʹૣ͘ͳͬͨΒݕূ͍ͨ͠ ✦ IELRͷܭࢉ଎౓͕े෼ʹૣ͘ͳͬͨ…!!! LALRͷ໰୊఺
  12. ✦ ਐḿ ✦ ʮLR parserೖ໳ʯΛॻ͍ͨ ✦ RubyConf Taiwan 2025Ͱొஃͨ͠ ✦

    pattern matching΍endless method de fi nitionΛΊ͙Δจ๏มߋ ʹ͍ͭͯߟ࡯ͨ͠ ✦ Lrama 0.7.1 ✦ Output fi leͷ֦ॆΛͨ͠ ·ͱΊ
  13. ✦ ͜Ε͔Β ✦ Lrama 0.7.1ΛϦϦʔε͢Δ ✦ Lrama 0.7.2Ͱ͸Grammar fi leͷߏจղੳΛASTʹ͍ͨ͠

    ✦ “จ๏Λ͍ͬͯ͡Con fl ictͱٔΕΔপ”ʹ΋ͬͱਓΛམͱͨ͢Ίͷ͍Ζ͍Ζ ✦ IELRΛ༻͍ͯ੔ཧͰ͖ͦ͏ͳ෦෼Λ੔ཧ͢Δ ✦ [Bug #21097]ͷ੔ཧ ✦ lexer stateͷ੔ཧ & lexer stateΛফ͢ ·ͱΊ