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
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 53 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
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 76 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
48 49 50 51 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 48 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 |
# 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 inherit = ref(inherit) end new_context = Liquidscript::ICR::Context.new new_context.parents << top.context new_context.class! @classes[name.value] = new_context new_context.parents << @classes[inherit.name.to_s] if inherit top.context = new_context body = _compile_class_body(false) new_context.undefined.each do |f| raise f[1] end code :class, name, inherit, body, top.contexts.pop end |
#compile_module ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/liquidscript/compiler/icr/classes.rb', line 35 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 |