Class: CSVPlusPlus::Language::Compiler
- Inherits:
-
Object
- Object
- CSVPlusPlus::Language::Compiler
- Defined in:
- lib/csv_plus_plus/language/compiler.rb
Overview
Encapsulates the parsing and building of objects (Template -> Row -> Cell). Variable resolution is delegated to the Scope
Instance Attribute Summary collapse
-
#benchmark ⇒ Object
readonly
Returns the value of attribute benchmark.
-
#options ⇒ Options
readonly
The
Optionsto compile with. -
#runtime ⇒ Runtime
readonly
The runtime execution.
-
#scope ⇒ Scope
readonly
Scopefor variable resolution. -
#timings ⇒ Object
readonly
Returns the value of attribute timings.
Class Method Summary collapse
-
.with_compiler(runtime:, options:, &block) ⇒ Object
Create a compiler and make sure it gets cleaned up.
Instance Method Summary collapse
-
#compile_template ⇒ Template
Compile a template and return a
::CSVPlusPlus::Templateinstance ready to be written with aWriter. -
#initialize(runtime:, options:, scope: nil) ⇒ Compiler
constructor
A new instance of Compiler.
-
#outputting! ⇒ Object
Write the compiled results.
- #to_s ⇒ String
Constructor Details
#initialize(runtime:, options:, scope: nil) ⇒ Compiler
Returns a new instance of Compiler.
42 43 44 45 46 |
# File 'lib/csv_plus_plus/language/compiler.rb', line 42 def initialize(runtime:, options:, scope: nil) @options = @runtime = runtime @scope = scope || ::CSVPlusPlus::Language::Scope.new(runtime:) end |
Instance Attribute Details
#benchmark ⇒ Object (readonly)
Returns the value of attribute benchmark.
20 21 22 |
# File 'lib/csv_plus_plus/language/compiler.rb', line 20 def benchmark @benchmark end |
#options ⇒ Options (readonly)
The Options to compile with
19 20 21 |
# File 'lib/csv_plus_plus/language/compiler.rb', line 19 def @options end |
#runtime ⇒ Runtime (readonly)
The runtime execution
19 20 21 |
# File 'lib/csv_plus_plus/language/compiler.rb', line 19 def runtime @runtime end |
#scope ⇒ Scope (readonly)
Scope for variable resolution
19 20 21 |
# File 'lib/csv_plus_plus/language/compiler.rb', line 19 def scope @scope end |
#timings ⇒ Object (readonly)
Returns the value of attribute timings.
20 21 22 |
# File 'lib/csv_plus_plus/language/compiler.rb', line 20 def timings @timings end |
Class Method Details
.with_compiler(runtime:, options:, &block) ⇒ Object
Create a compiler and make sure it gets cleaned up
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/csv_plus_plus/language/compiler.rb', line 26 def self.with_compiler(runtime:, options:, &block) compiler = new(options:, runtime:) if .verbose ::CSVPlusPlus::Language::BenchmarkedCompiler.with_benchmarks(compiler) do |c| block.call(c) end else yield(compiler) end ensure runtime.cleanup! end |
Instance Method Details
#compile_template ⇒ Template
Compile a template and return a ::CSVPlusPlus::Template instance ready to be written with a Writer
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/csv_plus_plus/language/compiler.rb', line 57 def compile_template parse_code_section! rows = parse_csv_section! ::CSVPlusPlus::Template.new(rows:, code_section: scope.code_section).tap do |t| t.(@runtime) { t. } resolve_all_cells!(t) end end |
#outputting! ⇒ Object
Write the compiled results
49 50 51 52 |
# File 'lib/csv_plus_plus/language/compiler.rb', line 49 def outputting! @runtime.start_at_csv! yield end |
#to_s ⇒ String
69 70 71 |
# File 'lib/csv_plus_plus/language/compiler.rb', line 69 def to_s "Compiler(options: #{@options}, runtime: #{@runtime}, scope: #{@scope})" end |