Module: WLang::RuleSet::Context

Defined in:
lib/wlang/rulesets/context_ruleset.rb

Overview

Provides a ruleset for managing the context/scoping during instantitation.

For an overview of this ruleset, see the wlang specification file.

Constant Summary

U =
WLang::RuleSet::Utils
DEFAULT_RULESET =

Default mapping between tag symbols and methods

{'=' => :assignment,
'#=' => :block_assignment, 
'%=' => :modulo_assignment, 
'^=' => :encoding_assignment}

Class Method Summary (collapse)

Class Method Details

+ (Object) assignment(parser, offset)

Rule implementation of ={wlang/hosted as x}{...}



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wlang/rulesets/context_ruleset.rb', line 20

def self.assignment(parser, offset)
  expr, reached = parser.parse(offset, "wlang/hosted")
    
  # decode expression
  decoded = U.decode_expr_as(expr)
  parser.syntax_error(offset) if decoded.nil?
    
  # evaluate it
  value = parser.evaluate(decoded[:expr])
    
  # handle two different cases
  if parser.has_block?(reached)
    parser.branch_scope(decoded[:variable] => value) {
      parser.parse_block(reached)
    }
  else
    parser.scope_define(decoded[:variable], value)
    ["", reached]
  end
end

+ (Object) block_assignment(parser, offset)

Rule implementation of #={wlang/active-string}{...}{...}



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/wlang/rulesets/context_ruleset.rb', line 42

def self.block_assignment(parser, offset)
  variable, reached = parser.parse(offset, "wlang/active-string")

  # decode expression
  decoded = U.decode_var(variable)
  parser.syntax_error(offset) if decoded.nil?
    
  # parse second block in that dialect
  value, reached = parser.parse_block(reached)
    
  # handle two different cases
  if parser.has_block?(reached)
    parser.branch_scope(decoded[:variable] => value) {
      parser.parse_block(reached)
    }
  else
    parser.scope_define(decoded[:variable], value)
    ["", reached]
  end
end

+ (Object) encoding_assignment(parser, offset)

Rule implementation of ^={wlang/active-string as x}{...}{...}



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/wlang/rulesets/context_ruleset.rb', line 86

def self.encoding_assignment(parser, offset)
  encoding_as, reached = parser.parse(offset, "wlang/hosted")

  # decode expression
  decoded = U.decode_qencoder_as(encoding_as)
  parser.syntax_error(offset) if decoded.nil?
    
  # parse second block in that dialect
  value, reached = parser.parse_block(reached)
  value = parser.encode(value, decoded[:encoder])
    
  # handle two different cases
  if parser.has_block?(reached)
    parser.branch_scope(decoded[:variable] => value) {
      parser.parse_block(reached)
    }
  else
    parser.scope_define(decoded[:variable], value)
    ["", reached]
  end
end

+ (Object) modulo_assignment(parser, offset)

Rule implementation of %={wlang/active-string as x}{...}{...}



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/wlang/rulesets/context_ruleset.rb', line 64

def self.modulo_assignment(parser, offset)
  dialect_as, reached = parser.parse(offset, "wlang/hosted")

  # decode expression
  decoded = U.decode_qdialect_as(dialect_as)
  parser.syntax_error(offset) if decoded.nil?
    
  # parse second block in that dialect
  value, reached = parser.parse_block(reached, decoded[:dialect])
    
  # handle two different cases
  if parser.has_block?(reached)
    parser.branch_scope(decoded[:variable] => value) {
      parser.parse_block(reached)
    }
  else
    parser.scope_define(decoded[:variable], value)
    ["", reached]
  end
end