Class: Litbuild::BlueprintParser
- Inherits:
-
Object
- Object
- Litbuild::BlueprintParser
- Includes:
- StringIndentation
- Defined in:
- lib/litbuild/blueprint_parser.rb
Overview
This is a kludgy hand-built parser. Blueprint structure is not (at least, at this point) complicated enough that I can see any point in defining a grammar and using a parser generator. The structure of blueprints is described informally in ‘doc/blueprints.txt` (and blueprint-type-specific files under `doc` as well).
Instance Attribute Summary collapse
-
#base_directives ⇒ Object
readonly
directives are for use in scripts.
-
#base_grafs ⇒ Object
readonly
directives are for use in scripts.
-
#phase_directives ⇒ Object
readonly
directives are for use in scripts.
-
#phase_grafs ⇒ Object
readonly
directives are for use in scripts.
Instance Method Summary collapse
-
#initialize(file_text) ⇒ BlueprintParser
constructor
A new instance of BlueprintParser.
Methods included from StringIndentation
#indent_for, #strip_indentation_from_array, #strip_indentation_from_string, #strip_indentation_from_value
Constructor Details
#initialize(file_text) ⇒ BlueprintParser
Returns a new instance of BlueprintParser.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/litbuild/blueprint_parser.rb', line 20 def initialize(file_text) @text = file_text @phase_directives = {} @phase_grafs = {} phase_chunks = @text.split(/^phase: ([a-z -_]+)$/) # The first part of the blueprint, before any phase directive, # becomes the base directives and base narrative for the # blueprint. If there are no phase directives, this is the entire # blueprint, obvs. @base_grafs = [] @base_directives = parse_phase(phase_chunks.shift, {}, @base_grafs) @base_directives['full-name'] ||= @base_directives['name'] # The rest of the blueprint, if any, consists of directives and # narrative for specific phases. The directives for each phase # include all the base directives, as well as those specific to # the phase. until phase_chunks.empty? phase_name = phase_chunks.shift phase_contents = phase_chunks.shift grafs = [] @phase_directives[phase_name] = parse_phase(phase_contents, @base_directives, grafs) @phase_grafs[phase_name] = grafs end # Any directives at the beginning of a blueprint are actually a # file header that should not be considered as part of the # narrative for it. @base_grafs.shift while @base_grafs[0].is_a?(Hash) rescue StandardError => e msg = "Cannot parse blueprint starting: #{@text.lines[0..3].join}" raise(Litbuild::ParseError, "#{msg} -- #{e}") end |
Instance Attribute Details
#base_directives ⇒ Object (readonly)
directives are for use in scripts. grafs are for use in documents.
18 19 20 |
# File 'lib/litbuild/blueprint_parser.rb', line 18 def base_directives @base_directives end |
#base_grafs ⇒ Object (readonly)
directives are for use in scripts. grafs are for use in documents.
18 19 20 |
# File 'lib/litbuild/blueprint_parser.rb', line 18 def base_grafs @base_grafs end |
#phase_directives ⇒ Object (readonly)
directives are for use in scripts. grafs are for use in documents.
18 19 20 |
# File 'lib/litbuild/blueprint_parser.rb', line 18 def phase_directives @phase_directives end |
#phase_grafs ⇒ Object (readonly)
directives are for use in scripts. grafs are for use in documents.
18 19 20 |
# File 'lib/litbuild/blueprint_parser.rb', line 18 def phase_grafs @phase_grafs end |