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
- #delegate_if_class ⇒ Object
Instance Method Details
#_compile_class_body(mod = false) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 61 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
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 84 def _compile_class_body_key(mod) item = shift :identifier, :istring item = compile_property(item) if item.type == :identifier && peek?(:prop) && !mod if item.type == :identifier && !mod set(item) end shift :colon item end |
#_new_token(old, type) ⇒ Object
56 57 58 59 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 56 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 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 6 def compile_class delegate_if_class do shift :class name = shift :identifier inherit = nil existed = check(name) set(name) # Inheritance ftw! if peek?(:colon) shift :colon inherit = shift :identifier inherit = ref(inherit) end @classes[name.value] = expressions = Liquidscript::ICR::Set.new expressions.context = Liquidscript::ICR::Context.new.tap(&:class!) expressions.parent = if inherit @classes[inherit.name.to_s].tap { |t| t.parent = top } else top end @set << expressions body = _compile_class_body(false) expressions.context.force_defined! out = code(:class, name, inherit, body) @set.pop out[:existed] = existed out end end |
#compile_module ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 40 def compile_module m = shift :module if peek? :identifier name = shift :identifier existed = check(name) set(name) body = _compile_class_body(true) out = code :module, name, body out[:existed] = existed out else value_expect _new_token(m, :identifier) end end |
#delegate_if_class ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 98 def delegate_if_class if top.context.class? top.context.delegate(&Proc.new) else yield end end |