Class: Liquidscript::Compiler::Base
- Inherits:
-
Object
- Object
- Liquidscript::Compiler::Base
- Extended by:
- Forwardable
- Includes:
- Helpers
- Defined in:
- lib/liquidscript/compiler/base.rb,
lib/liquidscript/compiler/base/blank.rb,
lib/liquidscript/compiler/base/action.rb,
lib/liquidscript/compiler/base/helpers.rb,
lib/liquidscript/compiler/base/callable.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Helpers Classes: Action, Blank, Callable
Instance Method Summary collapse
-
#compile ⇒ Array
Begins the compiliation.
-
#compile? ⇒ Boolean
Checks to see if the given input compiles.
-
#initialize(scanner) ⇒ Base
constructor
Initializes the compiler.
-
#peek ⇒ #type, Blank
Peeks at the next argument on the scanner.
-
#pop ⇒ #type?, Blank
Pops the next argument off of the scanner.
-
#reset! ⇒ void
(also: #rewind)
Resets the state of the compiler.
- #scanner_nil ⇒ Object
-
#top ⇒ Array, #push
Returns the top set.
Methods included from Helpers
#action, #collect_compiles, #expect, #loop, #maybe, #peek?, #shift
Constructor Details
Instance Method Details
#compile ⇒ Array
Begins the compiliation. Continues until the iterator raises a ‘StopIteration` error, and then returns the top set with #top.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/liquidscript/compiler/base.rb', line 42 def compile # We're using this cool property of Base::Blank such that it # will return a nil to any method call. while !peek.is_a?(Blank) do top.push compile_start end top rescue CompileError => e token = peek part = "#{File.(@scanner.[:file])}" + ":#{token.line}:#{token.column}: " + "before #{token.type.to_s.upcase}" raise e, e., [part, *e.backtrace] end |
#compile? ⇒ Boolean
Checks to see if the given input compiles.
63 64 65 66 67 68 69 70 |
# File 'lib/liquidscript/compiler/base.rb', line 63 def compile? compile true rescue CompileError false ensure reset! end |
#peek ⇒ #type, Blank
Peeks at the next argument on the scanner. If the call raises a StopIteration error, it returns the value of #scanner_nil instead.
92 93 94 95 96 |
# File 'lib/liquidscript/compiler/base.rb', line 92 def peek @iterator.peek rescue StopIteration scanner_nil end |
#pop ⇒ #type?, Blank
Pops the next argument off of the scanner. If the call raises a StopIteration error, it returns the value of #scanner_nil instead.
81 82 83 84 85 |
# File 'lib/liquidscript/compiler/base.rb', line 81 def pop @iterator.next rescue StopIteration scanner_nil end |
#reset! ⇒ void Also known as: rewind
This method returns an undefined value.
Resets the state of the compiler.
101 102 103 |
# File 'lib/liquidscript/compiler/base.rb', line 101 def reset! @iterator.rewind end |
#scanner_nil ⇒ Object
72 73 74 |
# File 'lib/liquidscript/compiler/base.rb', line 72 def scanner_nil @_blank ||= Blank.new end |
#top ⇒ Array, #push
Returns the top set. If the variable @top isn’t set by the inheriting class, then it defaults to the value of an array.
30 31 32 |
# File 'lib/liquidscript/compiler/base.rb', line 30 def top @top ||= [] end |