Class: MVinl::Context
- Inherits:
-
Object
- Object
- MVinl::Context
- Defined in:
- lib/mvinl/context.rb
Overview
Lexer and parser shared context
Constant Summary collapse
- RESERVED =
I[def]
- CONSTANTS =
{}
Instance Attribute Summary collapse
-
#functions ⇒ Object
Returns the value of attribute functions.
-
#state ⇒ Object
Returns the value of attribute state.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
- #define_constant(name, value) ⇒ Object
- #define_function(name, args, body) ⇒ Object
- #define_variable(name, value) ⇒ Object
-
#initialize ⇒ Context
constructor
A new instance of Context.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
13 14 15 |
# File 'lib/mvinl/context.rb', line 13 def initialize reset end |
Instance Attribute Details
#functions ⇒ Object
Returns the value of attribute functions.
8 9 10 |
# File 'lib/mvinl/context.rb', line 8 def functions @functions end |
#state ⇒ Object
Returns the value of attribute state.
8 9 10 |
# File 'lib/mvinl/context.rb', line 8 def state @state end |
#variables ⇒ Object
Returns the value of attribute variables.
8 9 10 |
# File 'lib/mvinl/context.rb', line 8 def variables @variables end |
Instance Method Details
#define_constant(name, value) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mvinl/context.rb', line 34 def define_constant(name, value) if RESERVED.include? name nil elsif CONSTANTS[name] false else @state[:in_var] = false CONSTANTS[name] = value end end |
#define_function(name, args, body) ⇒ Object
30 31 32 |
# File 'lib/mvinl/context.rb', line 30 def define_function(name, args, body) @functions[name] = { args: args, body: body } end |
#define_variable(name, value) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/mvinl/context.rb', line 45 def define_variable(name, value) if RESERVED.include? name nil else @state[:in_var] = false @variables[name] = value end end |
#reset ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mvinl/context.rb', line 17 def reset @variables = {} @functions = {} @state = { in_prop: false, in_var: false, in_keyword_arg: false, keyword_arg_depth: 0, lines: 0, depth: 0 } end |