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, included, #loop, #maybe, #peek?, #shift
Constructor Details
#initialize(scanner) ⇒ Base
Initializes the compiler.
19 20 21 22 23 |
# File 'lib/liquidscript/compiler/base.rb', line 19 def initialize(scanner) @scanner = scanner.each @action = Action.new reset! end |
Instance Method Details
#compile ⇒ Array
Begins the compiliation. Continues until the iterator raises a ‘StopIteration` error, and then returns the top set with #top.
41 42 43 44 45 46 47 48 49 |
# File 'lib/liquidscript/compiler/base.rb', line 41 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.
55 56 57 58 59 60 61 62 |
# File 'lib/liquidscript/compiler/base.rb', line 55 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.
84 85 86 87 88 |
# File 'lib/liquidscript/compiler/base.rb', line 84 def peek @scanner.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.
73 74 75 76 77 |
# File 'lib/liquidscript/compiler/base.rb', line 73 def pop @scanner.next rescue StopIteration scanner_nil end |
#reset! ⇒ void Also known as: rewind
This method returns an undefined value.
Resets the state of the compiler.
93 94 95 |
# File 'lib/liquidscript/compiler/base.rb', line 93 def reset! @scanner.rewind end |
#scanner_nil ⇒ Object
64 65 66 |
# File 'lib/liquidscript/compiler/base.rb', line 64 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.
29 30 31 |
# File 'lib/liquidscript/compiler/base.rb', line 29 def top @top ||= [] end |