Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Gorgos-parser-combinator-written-in-scheme
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Niyarin
November 26, 2020
Programming
0
410
Gorgos-parser-combinator-written-in-scheme
Schemeでパーサコンビネータを作りました
Niyarin
November 26, 2020
Tweet
Share
More Decks by Niyarin
See All by Niyarin
Scheme用nREPLの開発(エラー出力の改善)
niyarin
0
170
bel lispの紹介
niyarin
0
780
nanopass-compiler-frameworkを使ってみました
niyarin
0
460
outputting-beautiful-s-expression
niyarin
0
410
Serialisp
niyarin
1
700
Mongo DBとS式検索
niyarin
0
350
goodbye-python-repl
niyarin
0
390
SchemeのEphemeronとWeak Pairの説明
niyarin
0
1.1k
red-paren-scheme-rev-macro.pdf
niyarin
0
440
Other Decks in Programming
See All in Programming
JPUG勉強会 OSSデータベースの内部構造を理解しよう
oga5
2
250
CSC307 Lecture 13
javiergs
PRO
0
310
CSC307 Lecture 11
javiergs
PRO
0
590
Unity6.3 AudioUpdate
cova8bitdots
0
110
AWS Infrastructure as Code の新機能 2025 総まとめ 〜SA 4人による怒涛のデモ祭り〜
konokenj
10
3.2k
The Ralph Wiggum Loop: First Principles of Autonomous Development
sembayui
0
3.7k
「やめとこ」がなくなった — 1月にZennを始めて22本書いた AI共創開発のリアル
atani14
0
360
15年目のiOSアプリを1から作り直す技術
teakun
1
610
Head of Engineeringが現場で回した生産性向上施策 2025→2026
gessy0129
0
210
Rails Girls Tokyo 18th GMO Pepabo Sponsor Talk
yutokyokutyo
0
200
nilとは何か 〜interfaceの構造とnil!=nilから理解する〜
kuro_kurorrr
3
1.7k
AI駆動開発の本音 〜Claude Code並列開発で見えたエンジニアの新しい役割〜
hisuzuya
4
480
Featured
See All Featured
It's Worth the Effort
3n
188
29k
Accessibility Awareness
sabderemane
0
73
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
380
The agentic SEO stack - context over prompts
schlessera
0
680
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
210
Design in an AI World
tapps
0
160
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
370
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
470
Designing for Performance
lara
611
70k
The Invisible Side of Design
smashingmag
302
51k
Transcript
Parser combinator (written in Scheme) 「Gorgos」 Niyarin
Schemeでparser combinator を作った ・私はパーサに関しては素人です ・文字列を入れるとSchemeオブジェクトを返す手続きを作成する (Scheme手続きを組み合わせて)
返り値は多値 ・”受理したもの”と、”のこりの文字列”が返る ・文字aのパーサに”abcdef”を入れると、 受理した#\aと残りの”bcdef”が返る
“ab”を受け取るパーサ1 ・”gchar”を2回使って実装する
“ab”を受け取るパーサ2 ・よく使いそうなものは楽できるような部品が提供されている 特定の文字列を受け取るパーサ “gstring”
リストを意識したパーサコンビネータ1 ・gorgosはリストを返すことを意識した作りになっている ・受理→ 変換の”変換”を簡潔に書くため リストリーダの例
リストを意識したパーサコンビネータ2 ・なるべく変換を手抜きしたいので、gpairというpairを返すも のも作った ab…. を受け取る例
Schemeにcharsetがあって楽できた ・Schemeには文字の集合というデータ構造がある (SRFI 14) or (scheme charset) ・charsetに含まれているかどうかの部分だけでよかった ・組み込みも充実している char-set:upper-case
char-set:digit char-set:whitespace など
macro/手続きでありがちなやつ ・glistは最初は手続きだった → piyo-parserがfoo-parserの前に来ていないとだめ (右)再帰する場合もlambdaで囲わないと再帰できない ・parserを受け取るものをすべてマクロに書き換えた ・applyとかに渡すことができなくなったので、glist-fという関数版も用意 した
未完成な部分 ・文字列→ Scheme objectはできている ・今作り込んでいる部分 1.エラー表示 2.1文字先読みだけでいけるように変換orチェックする対応 port (fileストリームなど)から使えるようにしたい 1文字先読み