Module: PFM::Message::Parser
- Included in:
- State, UI::Message::Window
- Defined in:
- scripts/01450 Systems/00004 Message/00001 Logic/00001 Parser.rb
Overview
Module parsing a message to a set of instruction the message displayer can show
Class Attribute Summary collapse
-
.code_replacer ⇒ Array<Proc>
readonly
Get the list of code replacer.
Class Method Summary collapse
-
.register_marker(regexp, code) {|captures| ... }
Register a text marker to make text easier to parse.
Instance Method Summary collapse
-
#convert_text_to_properties(text) ⇒ Message::Properties
Function that parses the message text so it's easier to work with it.
-
#make_instructions(properties, width, width_computer)
Function that generate the instructions based on properties & text surface.
Class Attribute Details
.code_replacer ⇒ Array<Proc> (readonly)
Get the list of code replacer
33 34 35 |
# File 'scripts/01450 Systems/00004 Message/00001 Logic/00001 Parser.rb', line 33 def code_replacer @code_replacer end |
Class Method Details
.register_marker(regexp, code) {|captures| ... }
Note:
If no block is given, the function will assume the regexp has 1 match
Register a text marker to make text easier to parse
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'scripts/01450 Systems/00004 Message/00001 Logic/00001 Parser.rb', line 41 def register_marker(regexp, code) if block_given? @code_replacer[code] = proc do |text| text.gsub!(regexp) do parameters = yield(Regexp.last_match.captures) parameters = [parameters] unless parameters.is_a?(Array) next "#{code.chr}[#{parameters.join(',')}]" end end else @code_replacer[code] = proc { |text| text.gsub!(regexp, "#{code.chr}[\\1]") } end end |
Instance Method Details
#convert_text_to_properties(text) ⇒ Message::Properties
Function that parses the message text so it's easier to work with it
14 15 16 17 18 |
# File 'scripts/01450 Systems/00004 Message/00001 Logic/00001 Parser.rb', line 14 def convert_text_to_properties(text) parsed_text = Text.(text.dup).dup Parser.code_replacer.each { |replacer| replacer&.call(parsed_text) } return Properties.new(parsed_text) end |
#make_instructions(properties, width, width_computer)
Function that generate the instructions based on properties & text surface
24 25 26 27 28 |
# File 'scripts/01450 Systems/00004 Message/00001 Logic/00001 Parser.rb', line 24 def make_instructions(properties, width, width_computer) instructions = Instructions.new(properties, width, width_computer) instructions.parse return instructions end |