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
190
好きな技術《コト》で、 生きていく技術 / life with what you like
aereal
5
2.2k
qron: Cloud Native Cron Alternativeの今
aereal
2
2k
自動作曲入門 / 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.3k
Other Decks in Programming
See All in Programming
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
880
役立つログに取り組もう
irof
18
5.3k
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.2k
僕がつくった48個のWebサービス達
yusukebe
17
16k
Vitest Browser Mode への期待 / Vitest Browser Mode
odanado
PRO
2
1.6k
Golang と Erlang
taiyow
8
1.8k
CSC509 Lecture 06
javiergs
PRO
0
140
Honoの来た道とこれから
yusukebe
18
2.9k
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
4
2.2k
Why Spring Matters to Jakarta EE - and Vice Versa
ivargrimstad
0
520
CSC305 Lecture 13
javiergs
PRO
0
120
Java ジェネリクス入門 2024
nagise
0
480
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
32
2.4k
[RailsConf 2023] Rails as a piece of cake
palkan
50
4.8k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.5k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
For a Future-Friendly Web
brad_frost
174
9.4k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Agile that works and the tools we love
rasmusluckow
327
21k
Visualization
eitanlees
143
15k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
The Cult of Friendly URLs
andyhume
78
6k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.8k
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/