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 |
# 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 end |
#compile? ⇒ Boolean
Checks to see if the given input compiles.
56 57 58 59 60 61 62 63 |
# File 'lib/liquidscript/compiler/base.rb', line 56 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.
85 86 87 88 89 |
# File 'lib/liquidscript/compiler/base.rb', line 85 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.
74 75 76 77 78 |
# File 'lib/liquidscript/compiler/base.rb', line 74 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.
94 95 96 |
# File 'lib/liquidscript/compiler/base.rb', line 94 def reset! @iterator.rewind end |
#scanner_nil ⇒ Object
65 66 67 |
# File 'lib/liquidscript/compiler/base.rb', line 65 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 |