File: phrase_lists_parser.rb

package info (click to toggle)
ruby-mail 2.6.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,092 kB
  • ctags: 1,281
  • sloc: ruby: 43,919; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 829 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module Mail::Parsers
  class PhraseListsParser

    def parse(s)
      actions, error = Ragel.parse(:phrase_lists, s)
      if error
        raise Mail::Field::ParseError.new(Mail::PhraseList, s, error)
      end

      phrase_lists = PhraseListsStruct.new([])

      phrase_s = nil
      actions.each_slice(2) do |action_id, p|
        action = Mail::Parsers::Ragel::ACTIONS[action_id]
        case action

        # Phrase
        when :phrase_s then phrase_s = p
        when :phrase_e
          phrase_lists.phrases << s[phrase_s..(p-1)] if phrase_s
          phrase_s = nil

        when :comment_e, :comment_s, :qstr_s, :qstr_e then nil

        else
          raise Mail::Field::ParseError.new(Mail::PhraseList, s, "Failed to process unknown action: #{action}")
        end
      end

      phrase_lists
    end
  end
end