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.3k
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
170
好きな技術《コト》で、 生きていく技術 / life with what you like
aereal
5
2k
qron: Cloud Native Cron Alternativeの今
aereal
2
1.8k
自動作曲入門 / 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
From Spring Boot 2 to Spring Boot 3 with Java 22 and Jakarta EE
ivargrimstad
0
1.1k
New Order in Cascade Sorting Order
mugi_uno
3
2.5k
Why Prism?
kddnewton
4
1.4k
LangChainでWebサイトの内容取得やGitHubソースコード取得
shukob
0
130
Meet BrowserEngineKit
swiftty
0
310
Using Livebook to build and deploy internal tools @ ElixirConf 2024
hugobarauna
0
230
私の考える初学者がBlazorできるまでの学習方法
tomokusaba
1
250
The Future of Frontend i18n : Intl.MessageFormat
sajikix
1
2.4k
BasicBasic認証
sadnessojisan
5
3.1k
GraphQL あるいは React における自律的なデータ取得について
quramy
6
1.7k
大公開!iOS開発の悩みトップ5 〜iOSDC Japan 2024〜
ryunakayama
0
190
暴走のウホーレン 〜想いってのはvimrcにしないと伝わらないんだぜ〜 / iosdc_japan_2024
uhooi
1
240
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
PRO
27
7.4k
GitHub's CSS Performance
jonrohan
1029
450k
Facilitating Awesome Meetings
lara
49
5.9k
Testing 201, or: Great Expectations
jmmastey
35
6.9k
Art, The Web, and Tiny UX
lynnandtonic
294
20k
Raft: Consensus for Rubyists
vanstee
135
6.5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
52k
A Modern Web Designer's Workflow
chriscoyier
690
190k
How GitHub (no longer) Works
holman
310
140k
Happy Clients
brianwarren
96
6.6k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
23
580
The Illustrated Children's Guide to Kubernetes
chrisshort
46
48k
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/