Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Goで軽量マークアップ言語のパーサーを書く / Writing a parser with Go
Search
aereal
April 29, 2017
Programming
0
1.4k
Goで軽量マークアップ言語のパーサーを書く / Writing a parser with Go
そうだGo、京都 (
https://go-kyoto.connpass.com/event/55599/
) で発表した資料です。
aereal
April 29, 2017
Tweet
Share
More Decks by aereal
See All by aereal
How to send distibuted traces to Datadog using build own OpenTelemetry-Lambda distribution
aereal
3
210
好きな技術《コト》で、 生きていく技術 / life with what you like
aereal
5
2.3k
qron: Cloud Native Cron Alternativeの今
aereal
2
2.1k
自動作曲入門 / introduction to programatic music composition
aereal
1
530k
はてなブログ タグとCDK / The epic of AWS CDK and Hatena Blog Tag
aereal
3
200k
はてなブログ タグの技術選択 / The technical details of Hatena Blog Tag
aereal
3
200k
ブログサービスのHTTPS化を支えたAWSで作るピタゴラスイッチ / The construction of large scale TLS certificates management system with AWS
aereal
3
400k
AWSではてなブログの常時HTTPS配信をバーンとやる話 / The Epic of migration from HTTP to HTTPS on Hatena Blog with AWS
aereal
14
17k
ScalaとPerlでMicroservices in production / Building microservices with Perl and Scala in production
aereal
0
5.4k
Other Decks in Programming
See All in Programming
新規学習のハードルを下げる方法とは?/ How to Make Learning Something New Easier?
nobuoooo
1
120
cmp.Or に感動した
otakakot
3
320
Full stack testing :: basic to basic
up1
1
730
Jakarta EE meets AI
ivargrimstad
0
1.2k
DevTools extensions で 独自の DevTool を開発する | FlutterKaigi 2024
kokiyoshida
0
220
TypeScript でバックもやるって実際どう? 実運用で困ったこと3選
yuichiro_serita
17
6.3k
物流システムにおけるリファクタリングとアーキテクチャの再構築 〜依存関係とモジュール分割の重要性〜
deeprain
1
220
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
190
Remix on Hono on Cloudflare Workers
yusukebe
1
370
かんたんデザイン編集やってみた~「完全に理解した」までの道のり~
morit4ryo
1
100
Serverless苦闘史
mosh_inc
0
130
eBPF Deep Dive: Architecture and Safety Mechanisms
takehaya
12
1.1k
Featured
See All Featured
A better future with KSS
kneath
238
17k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Being A Developer After 40
akosma
87
590k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
Faster Mobile Websites
deanohume
305
30k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Transcript
GoͰܰྔϚʔΫΞοϓݴޠ ͷύʔαʔΛॻ͘ id:aereal
ܰྔϚʔΫΞοϓݴޠͱ • ҎԼ LML = Lightweight Markup Language • HTMLXMLͱϓϨʔϯςΩετͷதؒ
• Markdown, Textile, ͯͳه๏, etc.
ܰྔϚʔΫΞοϓݴޠͱ • ҎԼ LML = Lightweight Markup Language • HTMLXMLͱϓϨʔϯςΩετͷதؒ
• Markdown, Textile, ͯͳه๏, etc.
GoͰͯͳه๏ͷ ύʔαʔΛॻ͘ id:aereal
ࣗݾհ • id:aereal • Twitter: aereal • GitHub: aereal •
גࣜձࣾͯͳ ΞϓϦέʔγϣϯΤϯδχΞ
!͓͜ͱΘΓ! • ࠓճհ͢Δͯͳه๏ύʔαʔ ϓϥΠϕʔτϫʔΫͰ͢ • ͯͳͷαʔϏεʹ࠾༻͞ΕΔ͔ͳͲ ͯ͢ະఆͰ͢
ࢀߟใ • ͜ͷࢿྉͰհ͢Δใͯ͢ 2017gokyoto ͱ ͍͏λάΛ͚ͭͯϒοΫϚʔΫ͍ͯ͠·͢ • http://b.hatena.ne.jp/aereal/2017gokyoto/
ͯͳه๏ͱ • ͯͳ͕ఏڙ͢ΔαʔϏεͷҰ෦Ͱ͑ΔLML • ͯͳϒϩάɺͯͳμΠΞϦʔ • org-modeͱͪΐͬͱࣅ͍ͯΔ
ͯͳه๏ͷྫ * ݟग़͠1 ** ݟग़͠2 - Ruby - Perl -
Go + ى + ঝ + స + ݁
ͳͥύʔαʔΛॻ͘? • طʹಈ͍͍ͯΔͷʹखΛՃ͑ΔͷͰμϝ? • ͳͥͯͳه๏? • ͳͥGoͰ?
Ϟνϕʔγϣϯ • طଘͷ࣮ʹखΛՃ͑ΔͷΉ͔͍ͣ͠ • ͯͳه๏Λύʔε͍ͨ͠χʔζ͋Δ! • Go͕ॻ͖͔ͨͬͨ
طଘͷ࣮ʹखΛՃ͑Δͷ Ή͔͍ͣ͠ • ܗࣜతͳఆ͕ٛͳ͍ = ಈ͘ίʔυ͕༷ • ਖ਼نදݱ
ͯͳه๏Λύʔε͍ͨ͠ χʔζ͋Δ! • ͯͳάϧʔϓͰීஈ͔Βॻ͍͍ͯΔ • ͯͳϒϩάͰهΛॻ͘ͷ͕झຯ • →ͯͳه๏ʹৗతʹ৮Ε͍ͯΔ • Markdownͷม
(...)
Go͕ॻ͖͔ͨͬͨ • ීஈPerlJavaScriptɺͨ·ʹScala • ۀͱҟͳΔίϯςΩετͰίʔυΛॻ͖͔ͨͬͨ
ͪΐ͏Ͳ͍͍ඪ • Ͱ͖Δ͜ͱɺΓ͍ͨ͜ͱɺؔ৺ͷ͋Δ͜ͱ͕ ͍͍͔Μ͡ʹόϥϯε͞Ε͍ͯΔ • WebͱςΩετϓϩηογϯά • খඪΛੵΈॏͶ͍͚ͯΔ • ʮࠓ͜ͷه๏ΛՃ͠Α͏ʯ
108͋Δͯͳه๏ύʔαʔ • ͯͳμΠΞϦʔ • ͯͳάϧʔϓ • Text-Hatena (CPAN) • Text-Xatena
• chris4403/WikiTextConverter • ...
108͋Δͯͳه๏ύʔαʔ • ͦΕͧΕඍົʹ༷͕ҟͳΔ • ৽͘͠࡞ΒΕͨͷ΄ͲεʔύʔηοτͷఆٛΛ ࢼΈΔ͕͋Δ
ܗࣜతͳఆٛΛ༩͍͑ͨ • ࣮ͱఆٛΛૄʹ͍ͨ͠ • ఆ͚ٛͩΛࢀর͍ͨ͠ • ͤΊͯCommonMark͘Β͍ͷͷ…… • (ͱ͍࣮͑ͱϦϯΫͤ͞ΒΕΔ΄͏͕Α͍)
aereal/go-text-hatena https://github.com/aereal/go-text-hatena
࣮ͨ͠ه๏ • ݟग़͠ • Ϧετ • Ҿ༻ • HTTPه๏ (Ұ෦)
ࢦ͢ͱ͜Ζ • ϙʔλϒϧͰ͋Δ͜ͱ • ݴޠʹґΒͣར༻Ͱ͖Δ • ར༻ऀ͕ҙͷHTMLมϧʔϧΛద༻Ͱ͖Δ • ࣮ͱఆٛΛૄʹ •
ఆٛΛ੩తʹࢀরͰ͖Δ • ࣮ݴޠ (Go) ͷ͕ࣝͳͯ͘งғؾ௫ΊΔ
࣮ • GoͰೖग़ྗΛΠϯλʔϑΣʔεͱ͢ΔόΠφϦ • → ݴޠʹґΒͣར༻Ͱ͖Δ • ASTΛJSONͰग़ྗ͢Δ͚ͩ • →
ར༻ऀ͕ҙͷHTMLมϧʔϧΛద༻ (࣮) Ͱ͖Δ
࣮ • goyaccΛ͍YACCͰจ๏ఆٛ • → ఆٛΛ੩తʹࢀরͰ͖Δ (parser.go.y) • ࣮ݴޠ (Go)
ͷ͕ࣝͳͯ͘งғؾ௫ΊΔ
HTMLͷม • αʔϏεʹΑͬͯͲΕ͘Β͍HTMLͷೖྗΛ ڐ༰͢Δ͔ͷํ͕ҟͳΔ • ͯͳϒϩάࣗ༝͕ͩɺͯͳμΠΞϦʔ ϗϫΠτϦετܗࣜ • ηΩϡϦςΟ্ͷࣄ
มσϞ • aereal/sketch-hatena-notation-api
GoͰύʔαʔΛॻ͘
ͬͨπʔϧ • Go • goyacc • text/scanner
goyacc • yaccͷGo൛ • ࠷ۙ go tool ͔Β֎Εͨ • go
get golang.org/x/tools/cmd/goyacc
yacc • ύʔαʔδΣωϨʔλʔ • BNF • ఆٛʹରͯ͠ίʔϧόοΫΛॻ͍͍ͯ͘ • ؐݩͱΞΫγϣϯͱݺΕΔ •
शyacc͕͓͢͢Ί • ࣮ྫͱͯ͠ mattn/streeem ࢀߟʹͳΔ
yaccͷ͍͍ͱ͜Ζ • BNFʹΑΔఆٛͱɺؐݩ͢Δίʔυ͕Ͱ͖Δ • ݴޠDSLΛ͏ύʔαʔίϯϏωʔλʔΑΓ ଞͷਓʹݺΜͰΒ͍͍͢ؾ͕͢Δ
yaccͷඍົͳͱ͜Ζ • *.go.y ͰΤσΟλͷࢧԉ͕ड͚ΒΕͳ͍ • ͏·͍͜ͱઃఆͨ͠ΒͰ͖ͦ͏Ͱ͋Δ • ࣈ۟ղੳࣗͰؤுΔඞཁ͕͋Δ • GoͰ
text/scanner ͱ͍͏ඪ४ϥΠϒϥϦ͕ ͋ΔͷͰָͰ͖Δ
ίʔυΛಡΜͰΈΔ • lex.go • parser.go.y • parser_test.go
·ͱΊ
·ͱΊ • ͯͳه๏ύʔαʔΛGoͰॻ͍ͨ • Goʹgoyacctext/scannerͳͲ ߏจղੳࣈ۟ղੳͷͨΊͷπʔϧ͕ἧ͍ͬͯΔ
ࢀߟใ • ͜ͷࢿྉͰհ͢Δใͯ͢ 2017gokyoto ͱ ͍͏λάΛ͚ͭͯϒοΫϚʔΫ͍ͯ͠·͢ • http://b.hatena.ne.jp/aereal/2017gokyoto/