Sha256: 35748b1459942ca365e84912a4c50bc9769dfe0e20ec76513ce57915bde8cc20

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

require "hemingway/text/text_nodes"

module Hemingway
  grammar Text

    # Example: blah blah blah
    # Notes:
    #  - Okay so this is midly confusing. It's super important to keep the idea
    # of what text is consumed in mind. If I just have the rule as
    #
    #                          !( non_text / eop)+
    #
    # it will never consume any text [because negative lookahead assertions
    # don't consume text]. When this runs it would just sit on the first
    # character and continually check for non_text, causing a deadspin if it
    # wasn't a non_text. To fix this, make it a sequence with '.'. The '.' will
    # consume any input and keep that index moving along until in fact we find
    # our non_text.
    #  - Okay another super important consideration: I MUST use
    # the + rather than the *. If I use *, then the empty string will match
    # text, and because the parent rule of paragraph has zero or more texts in
    # a sequence, it will forever match the empty string and never move onto
    # eop. We much only match text when there is one or more characters, a
    # totally reasonable rule.
    rule text
      ( !non_text . )+ <TextNode>
    end

    # If you hit any of these while chomping on text you should pop out
    rule non_text
      escape / tag_end / math_start / newline
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hemingway-0.0.3 lib/hemingway/text/text.treetop
hemingway-0.0.2 lib/hemingway/text/text.treetop