Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Goで実装する軽量マークアップ言語パーサー / Gohn: parser written in Go

aereal
August 04, 2017
3.7k

Goで実装する軽量マークアップ言語パーサー / Gohn: parser written in Go

talked at builderscon tokyo 2017

aereal

August 04, 2017
Tweet

More Decks by aereal

Transcript

  1. ࣮૷͍Ζ͍Ζ • ࢓༷ ≈ ࣮૷ • ࣮૷͕͍Ζ͍Ζ͋Δ • ͭ·Γ •

    ࣮૷ͷ਺͚ͩ࢓༷͕ଘࡏ͢Δ • ࢓༷Λ஌Δʹ͸Perlͱਖ਼نදݱΛಡΈղ͘ඞཁ͕͋Δ
  2. ঢ়ଶભҠΛ؅ཧ var isInIdNotation = false; while (1) { if (isInIdNotation)

    { var name = readText(); // => "aereal" } else { switch (readChar()) { case ':': isInIdNotation = true; default: // ... } } }
  3. ঢ়ଶભҠΛ؅ཧ var isInIdNotation = false; var isInHeading = false; var

    isInUnorderedList = false; var isInOrderedList = false; while (1) { if (isInIdNotation) if (isInHeading) if (isInUnorderedList) if (isInOrderedList) }
  4. ࠷ॳʹݱΕΔ `:` ͸εΩʔϜ෦ͱݟͳͯ͠ແࢹ͢Δ͜ͱʹ if !l.seenColon { l.seenColon = true return

    false // maybe part of URL } else { return true } https://github.com/aereal/gohn/blob/master/parser/ lex.go#L100
  5. http_options: http_option { $$ = []string{$1} } | http_option http_options

    { options := $2 $$ = append([]string{$1}, options...) }
  6. ׬