Module: Liquidscript::Compiler::ICR::Classes
- Included in:
- Liquidscript::Compiler::ICR
- Defined in:
- lib/liquidscript/compiler/icr/classes.rb
Instance Method Summary collapse
- #_compile_class_body(mod = false) ⇒ Object
- #_compile_class_body_key(mod) ⇒ Object
- #_new_token(old, type) ⇒ Object
- #compile_class ⇒ Object
- #compile_module ⇒ Object
Instance Method Details
#_compile_class_body(mod = false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 41 def _compile_class_body(mod = false) shift :lbrace components = [] compile_object = action do components << [ _compile_class_body_key(mod), compile_vexpression ] end loop do expect :newline, :rbrace => action.end_loop, :comma => action.shift, :module => action { components << compile_module }, :class => action { components << compile_class }, [:identifier, :istring] => compile_object end components end |
#_compile_class_body_key(mod) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 64 def _compile_class_body_key(mod) item = shift :identifier, :istring item = compile_property(item) if item.type == :identifier && peek?(:prop) && !mod shift :colon item end |
#_new_token(old, type) ⇒ Object
36 37 38 39 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 36 def _new_token(old, type) Scanner::Token.new(type, old.type.to_s, old.line, old.column) end |
#compile_class ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 6 def compile_class shift :class name = shift :identifier inherit = nil set name # Inheritance ftw! if peek?(:colon) shift :colon inherit = shift :identifier ref inherit end body = _compile_class_body(false) code :class, name, inherit, body end |
#compile_module ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 23 def compile_module m = shift :module if peek? :identifier name = shift :identifier set name body = _compile_class_body(true) code :module, name, body else value_expect _new_token(m, :identifier) end end |