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
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
200
好きな技術《コト》で、 生きていく技術 / 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
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1.2k
Jakarta EE meets AI
ivargrimstad
0
380
Modular Monolith Monorepo ~シンプルさを保ちながらmonorepoのメリットを最大化する~
yuisakamoto
9
1.4k
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
3
1.2k
CSC509 Lecture 11
javiergs
PRO
0
180
flutterkaigi_2024.pdf
kyoheig3
0
210
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
260
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
as(型アサーション)を書く前にできること
marokanatani
10
2.8k
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
140
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
740
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Featured
See All Featured
Producing Creativity
orderedlist
PRO
341
39k
For a Future-Friendly Web
brad_frost
175
9.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Writing Fast Ruby
sferik
627
61k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
KATA
mclloyd
29
14k
Thoughts on Productivity
jonyablonski
67
4.3k
4 Signs Your Business is Dying
shpigford
180
21k
GitHub's CSS Performance
jonrohan
1030
460k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
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/