Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
UNTIL. LT #0x07 n4mlz
Search
n4mlz
May 17, 2025
1.7k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
UNTIL. LT #0x07 n4mlz
n4mlz
May 17, 2025
More Decks by n4mlz
See All by n4mlz
自作OSでLinuxコンテナを動かす
n4mlz
2
4k
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
470
NUMA環境とコンテナランタイム ― youki における Linux Memory Policy 実装
n4mlz
1
1.7k
Featured
See All Featured
A better future with KSS
kneath
240
18k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
It's Worth the Effort
3n
188
29k
The browser strikes back
jonoalderson
0
1.7k
The Language of Interfaces
destraynor
162
27k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
First, design no harm
axbom
PRO
2
1.3k
Paper Plane
katiecoart
PRO
4
53k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
240
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Transcript
TypeScript 小ネタ: 型のみで実装する正規表現エンジン n4mlz GitHub: https://github.com/n4mlz Twitter: https://twitter.com/n4mlz UNTIL. LT
#0x07 2025-05-17
2 後で書く 自己紹介
3 TypeScript の型はチューリング完全 ⚫ 例: 数独チェッカー TypeScript の型 ⚫ 例:
Brainfuck インタプリタ https://github.com/gruhn/typescript-sudoku/ https://github.com/susisu/typefuck
4 TypeScript の型はチューリング完全 TypeScript の型 うおお、俺もなんか作りてえ 正規表現エンジン作るぞ
5 TypeScript の型だけで正規表現エンジン作った ⚫ Regex<Pattern, Text> により true または false
に評価される 成果物
6 準備: 論理演算の定義 ⚫ 条件型 (Conditional Types) を使用して分岐を作る 型で正規表現エンジンを作る
7 準備: 文字列操作の定義 ⚫ テンプレートリテラル型 (Template Literal Types) を使用して 先頭文字の抽出、残りの文字の抽出、文字の結合を作る
型で正規表現エンジンを作る
8 1文字に対するマッチング ⚫ Pattern も Text も1文字であると仮定しているので、 ワイルドカード (.) のみ気にすればよい
型で正規表現エンジンを作る
9 ? や * を先頭に含む文字列に対応する ⚫ ? や * がマッチした場合、その後は自身を再帰的に適用することで
「文字列」に対応 型で正規表現エンジンを作る
10 文字の終端に対応する ⚫ ? や * を含む文字列を取りまとめ、 パターンの終端が $ であるかをチェックする
型で正規表現エンジンを作る
11 マッチングの開始点を作る ⚫ 先頭が ^ でない場合: ‹Pattern› と ^.*‹Pattern› が等価であること
を利用し、任意の開始点からのマッチングに対応する (テク) ⚫ Regexp<“bc”, “abcd”> が true に評価されるようになる 型で正規表現エンジンを作る
12 完成 ⚫ 型のみで簡易的な正規表現エンジンを作ることができた 完成
13 最後に Gist に公開しています! 気になったら見ていってください https://gist.github.com/n4mlz 次はスタックマシンや一次元セルオートマトンを作りたい