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
210
好きな技術《コト》で、 生きていく技術 / life with what you like
aereal
5
2.4k
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
return文におけるstd::moveについて
onihusube
1
750
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
920
Criando Commits Incríveis no Git
marcelgsantos
2
170
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
200
今からはじめるAndroidアプリ開発 2024 / DevFest 2024
star_zero
0
1k
Refactor your code - refactor yourself
xosofox
1
260
複雑な仕様に立ち向かうアーキテクチャ
myohei
0
170
Featured
See All Featured
Music & Morning Musume
bryan
46
6.2k
Side Projects
sachag
452
42k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Fireside Chat
paigeccino
34
3.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Done Done
chrislema
181
16k
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/