wlang 0.8.5 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/CHANGELOG.rdoc +65 -0
  2. data/README.rdoc +85 -31
  3. data/bin/wlang +5 -0
  4. data/doc/specification/dialect.wtpl +14 -0
  5. data/doc/specification/dialects.wtpl +3 -0
  6. data/doc/specification/glossary.wtpl +4 -4
  7. data/doc/specification/rulesets.wtpl +9 -9
  8. data/doc/specification/specification.css +1 -0
  9. data/doc/specification/specification.html +68 -5
  10. data/doc/specification/specification.wtpl +12 -12
  11. data/doc/specification/specification.yml +9 -9
  12. data/doc/specification/symbols.wtpl +8 -8
  13. data/lib/wlang.rb +297 -75
  14. data/lib/wlang/dialect.rb +7 -3
  15. data/lib/wlang/dialects/coderay_dialect.rb +4 -4
  16. data/lib/wlang/dialects/plain_text_dialect.rb +13 -19
  17. data/lib/wlang/dialects/redcloth_dialect.rb +16 -0
  18. data/lib/wlang/dialects/ruby_dialect.rb +16 -2
  19. data/lib/wlang/dialects/standard_dialects.rb +20 -0
  20. data/lib/wlang/dialects/xhtml_dialect.rb +24 -1
  21. data/lib/wlang/encoder.rb +1 -1
  22. data/lib/wlang/encoder_set.rb +5 -0
  23. data/lib/wlang/errors.rb +70 -6
  24. data/lib/wlang/ext/hash_methodize.rb +13 -0
  25. data/lib/wlang/{ruby_extensions.rb → ext/string.rb} +9 -5
  26. data/lib/wlang/hash_scope.rb +89 -0
  27. data/lib/wlang/hosted_language.rb +146 -0
  28. data/lib/wlang/parser.rb +189 -126
  29. data/lib/wlang/parser_state.rb +94 -0
  30. data/lib/wlang/rule_set.rb +16 -3
  31. data/lib/wlang/rulesets/basic_ruleset.rb +14 -6
  32. data/lib/wlang/rulesets/buffering_ruleset.rb +20 -29
  33. data/lib/wlang/rulesets/context_ruleset.rb +16 -20
  34. data/lib/wlang/rulesets/imperative_ruleset.rb +4 -4
  35. data/lib/wlang/rulesets/ruleset_utils.rb +26 -5
  36. data/lib/wlang/template.rb +16 -34
  37. data/lib/wlang/wlang_command.rb +4 -7
  38. data/lib/wlang/wlang_command_options.rb +5 -0
  39. data/test/blackbox/basic/execution_1.exp +1 -0
  40. data/test/blackbox/basic/execution_1.tpl +1 -0
  41. data/test/blackbox/basic/execution_2.exp +1 -0
  42. data/test/blackbox/basic/execution_2.tpl +1 -0
  43. data/test/blackbox/basic/execution_3.exp +1 -0
  44. data/test/blackbox/basic/execution_3.tpl +1 -0
  45. data/test/blackbox/basic/execution_4.exp +1 -0
  46. data/test/blackbox/basic/execution_4.tpl +1 -0
  47. data/test/blackbox/basic/inclusion_1.exp +1 -0
  48. data/test/blackbox/basic/inclusion_1.tpl +1 -0
  49. data/test/blackbox/basic/inclusion_2.exp +1 -0
  50. data/test/blackbox/basic/inclusion_2.tpl +1 -0
  51. data/test/blackbox/basic/injection_1.exp +1 -0
  52. data/test/blackbox/basic/injection_1.tpl +1 -0
  53. data/test/blackbox/basic/injection_2.exp +1 -0
  54. data/test/blackbox/basic/injection_2.tpl +1 -0
  55. data/test/blackbox/basic/modulation_1.exp +1 -0
  56. data/test/blackbox/basic/modulation_1.tpl +1 -0
  57. data/test/blackbox/basic/modulation_2.exp +1 -0
  58. data/test/blackbox/basic/modulation_2.tpl +1 -0
  59. data/test/blackbox/basic/recursive_app_1.exp +1 -0
  60. data/test/blackbox/basic/recursive_app_1.tpl +1 -0
  61. data/test/blackbox/basic/recursive_app_2.exp +1 -0
  62. data/test/blackbox/basic/recursive_app_2.tpl +1 -0
  63. data/test/blackbox/buffering/data_1.rb +1 -0
  64. data/test/blackbox/buffering/data_assignment_1.exp +1 -0
  65. data/test/blackbox/buffering/data_assignment_1.tpl +1 -0
  66. data/test/blackbox/buffering/data_assignment_2.exp +1 -0
  67. data/test/blackbox/buffering/data_assignment_2.tpl +1 -0
  68. data/test/blackbox/buffering/data_assignment_3.exp +1 -0
  69. data/test/blackbox/buffering/data_assignment_3.tpl +1 -0
  70. data/test/blackbox/buffering/data_assignment_4.exp +1 -0
  71. data/test/blackbox/buffering/data_assignment_4.tpl +1 -0
  72. data/test/blackbox/buffering/input_1.exp +1 -0
  73. data/test/blackbox/buffering/input_1.tpl +1 -0
  74. data/test/blackbox/buffering/input_2.exp +1 -0
  75. data/test/blackbox/buffering/input_2.tpl +1 -0
  76. data/test/blackbox/buffering/input_3.exp +1 -0
  77. data/test/blackbox/buffering/input_3.tpl +1 -0
  78. data/test/blackbox/buffering/input_inclusion.exp +1 -0
  79. data/test/blackbox/buffering/input_inclusion.tpl +1 -0
  80. data/test/blackbox/buffering/input_inclusion_1.exp +0 -0
  81. data/test/blackbox/buffering/input_inclusion_1.tpl +1 -0
  82. data/test/blackbox/buffering/input_inclusion_2.exp +1 -0
  83. data/test/blackbox/buffering/input_inclusion_2.tpl +1 -0
  84. data/test/blackbox/buffering/input_inclusion_3.exp +1 -0
  85. data/test/blackbox/buffering/input_inclusion_3.tpl +1 -0
  86. data/test/blackbox/buffering/input_inclusion_4.exp +0 -0
  87. data/test/blackbox/buffering/input_inclusion_4.tpl +1 -0
  88. data/test/blackbox/buffering/input_inclusion_5.exp +1 -0
  89. data/test/blackbox/buffering/input_inclusion_5.tpl +1 -0
  90. data/test/blackbox/buffering/input_inclusion_6.exp +1 -0
  91. data/test/blackbox/buffering/input_inclusion_6.tpl +1 -0
  92. data/test/blackbox/buffering/input_inclusion_7.exp +0 -0
  93. data/test/blackbox/buffering/input_inclusion_7.tpl +1 -0
  94. data/test/blackbox/buffering/text_1.txt +1 -0
  95. data/test/blackbox/buffering/wlang.txt +1 -0
  96. data/test/blackbox/context/assignment_1.exp +1 -0
  97. data/test/blackbox/context/assignment_1.tpl +1 -0
  98. data/test/blackbox/context/assignment_2.exp +1 -0
  99. data/test/blackbox/context/assignment_2.tpl +1 -0
  100. data/test/blackbox/context/assignment_3.exp +2 -0
  101. data/test/blackbox/context/assignment_3.tpl +2 -0
  102. data/test/blackbox/context/assignment_4.exp +1 -0
  103. data/test/blackbox/context/assignment_4.tpl +1 -0
  104. data/test/blackbox/context/block_assignment_1.exp +1 -0
  105. data/test/blackbox/context/block_assignment_1.tpl +1 -0
  106. data/test/blackbox/context/block_assignment_2.exp +1 -0
  107. data/test/blackbox/context/block_assignment_2.tpl +1 -0
  108. data/test/blackbox/context/modulo_assignment_1.exp +1 -0
  109. data/test/blackbox/context/modulo_assignment_1.tpl +1 -0
  110. data/test/blackbox/context/modulo_assignment_2.exp +1 -0
  111. data/test/blackbox/context/modulo_assignment_2.tpl +1 -0
  112. data/test/blackbox/data_1.rb +1 -0
  113. data/test/blackbox/test_all.rb +59 -0
  114. data/test/spec/basic_object.spec +40 -0
  115. data/test/spec/global_extensions.rb +2 -0
  116. data/test/spec/hash_scope.spec +76 -0
  117. data/test/spec/redcloth_dialect.spec +24 -0
  118. data/test/spec/test_all.rb +8 -0
  119. data/test/spec/wlang.spec +53 -0
  120. data/test/spec/xhtml_dialect.spec +23 -0
  121. data/test/{test_all.rb → unit/test_all.rb} +1 -1
  122. data/test/{wlang → unit/wlang}/anagram_bugs_test.rb +2 -2
  123. data/test/{wlang → unit/wlang}/basic_ruleset_test.rb +1 -1
  124. data/test/{wlang → unit/wlang}/buffering_ruleset_test.rb +4 -4
  125. data/test/{wlang → unit/wlang}/buffering_template1.wtpl +0 -0
  126. data/test/{wlang → unit/wlang}/buffering_template2.wtpl +0 -0
  127. data/test/{wlang → unit/wlang}/buffering_template3.wtpl +0 -0
  128. data/test/unit/wlang/buffering_template4.wtpl +1 -0
  129. data/test/unit/wlang/buffering_template5.wtpl +1 -0
  130. data/test/{wlang → unit/wlang}/context_ruleset_test.rb +0 -0
  131. data/test/{wlang → unit/wlang}/data.rb +0 -0
  132. data/test/{wlang → unit/wlang}/encoder_set_test.rb +0 -0
  133. data/test/{wlang → unit/wlang}/imperative_ruleset_test.rb +0 -0
  134. data/test/{wlang → unit/wlang}/intelligent_buffer_test.rb +0 -0
  135. data/test/{wlang → unit/wlang}/othersymbols_test.rb +0 -0
  136. data/test/{wlang → unit/wlang}/parser_test.rb +10 -11
  137. data/test/{wlang → unit/wlang}/plain_text_dialect_test.rb +0 -0
  138. data/test/{wlang → unit/wlang}/ruby_dialect_test.rb +0 -0
  139. data/test/{wlang → unit/wlang}/ruby_expected.rb +0 -0
  140. data/test/{wlang → unit/wlang}/ruby_template.wrb +0 -0
  141. data/test/{wlang → unit/wlang}/ruleset_utils_test.rb +0 -0
  142. data/test/{wlang → unit/wlang}/specification_examples_test.rb +2 -2
  143. data/test/{wlang → unit/wlang}/test_utils.rb +1 -1
  144. data/test/{wlang → unit/wlang}/wlang_test.rb +0 -0
  145. metadata +135 -42
  146. data/lib/wlang/basic_object.rb +0 -19
  147. data/lib/wlang/parser_context.rb +0 -139
  148. data/test/sandbox.rb +0 -1
  149. data/test/wlang/buffering_template4.wtpl +0 -1
  150. data/test/wlang/buffering_template5.wtpl +0 -1
  151. data/test/wlang/parser_context_test.rb +0 -29
@@ -1,19 +0,0 @@
1
- module WLang
2
-
3
- #
4
- # Provides an Object with all inherited instance methods removed.
5
- #
6
- class BasicObject
7
-
8
- # Methods that we keep
9
- KEPT_METHODS = ["__send__", "__id__", "instance_eval", "initialize", "object_id",
10
- :__send__, :__id__, :instance_eval, :initialize, :object_id]
11
-
12
- # Removes all methods that are not needed to the class
13
- (instance_methods + private_instance_methods).each do |m|
14
- undef_method(m) unless KEPT_METHODS.include?(m)
15
- end
16
-
17
- end # class BasicObject
18
-
19
- end
@@ -1,139 +0,0 @@
1
- require 'wlang/basic_object'
2
- module WLang
3
- class Parser
4
-
5
- #
6
- # Execution context of the Parser for <tt>!{wlang/hosted}</tt> and associated
7
- # tags. The execution context defines the semantics of executed code in those
8
- # tags as well as utilities to handle semantical scoping.
9
- #
10
- # TODO: define context and scoping semantics more precisely and extend the
11
- # documentation
12
- #
13
- class Context
14
-
15
- # Common methods of scope instances
16
- class Scope < WLang::BasicObject
17
- attr_accessor :__parent
18
-
19
- end # module Scope
20
-
21
- # Hash scoping mechanism
22
- class HashScope < Scope
23
- attr_reader :__hash
24
-
25
- # Decorates a hash as a scope.
26
- def initialize(hash={}, parent=nil)
27
- @__hash = hash
28
- @__parent = parent
29
- end
30
-
31
- def nil?
32
- false
33
- end
34
-
35
- def dup
36
- HashScope.new(@__hash.dup, @__parent)
37
- end
38
-
39
- def __branch(other)
40
- HashScope.new(other, self)
41
- end
42
-
43
- # Tries to convert found value to a given variable.
44
- def method_missing(symbol, *args)
45
- varname = symbol.to_s
46
- if @__hash.has_key?(varname)
47
- @__hash[varname]
48
- elsif @__parent
49
- @__parent.method_missing(symbol, *args)
50
- else
51
- nil
52
- end
53
- end
54
-
55
- # Returns underlying object
56
- def __underlying
57
- return @__hash
58
- end
59
-
60
- # See Scope#__evaluate
61
- def __evaluate(expr)
62
- self.instance_eval(expr)
63
- end
64
-
65
- # See Scope#__define
66
- def __define(key, value);
67
- @__hash[key]=value;
68
- end
69
-
70
- def /(symb)
71
- s = symb.to_s
72
- if @__hash.has_key?(s)
73
- return WLang::Parser::Context.to_scope(@__hash[s])
74
- else
75
- return nil
76
- end
77
- end
78
-
79
- def inspect
80
- "#{__underlying.inspect} with parent #{@__parent.inspect}"
81
- end
82
-
83
- end # class HashScope
84
-
85
- # Creates an empty context on an init scope object.
86
- def initialize(init=nil)
87
- if (Scope===init)
88
- @current_scope = init
89
- else
90
- @current_scope = HashScope.new
91
- push(init) unless init.nil?
92
- end
93
- end
94
-
95
- # Evaluates a ruby expression on the current context.
96
- def evaluate(expression)
97
- if "self" == expression.strip
98
- @current_scope
99
- elsif /[a-z]+(\/[a-z]+)+/ =~ expression
100
- expression = ("self/" + expression).gsub(/\//,"/:")
101
- expr = @current_scope.__evaluate(expression)
102
- expr = expr.__underlying if Scope===expr
103
- return expr
104
- else
105
- @current_scope.__evaluate(expression)
106
- end
107
- end
108
-
109
- # Pushes a new scope instance.
110
- def push(who={})
111
- who = WLang::Parser::Context.to_scope(who)
112
- who.__parent = @current_scope
113
- @current_scope = who
114
- end
115
-
116
- # Pops the last added scope.
117
- def pop
118
- parent = @current_scope.__parent
119
- raise "Bad scope usage, nothing to pop" if parent.nil?
120
- @current_scope = parent
121
- end
122
-
123
- # Defines a variable/value mapping in the current scope.
124
- def define(key, value)
125
- @current_scope.__define(key,value)
126
- end
127
-
128
- # Converts a given instance to a Scope.
129
- def self.to_scope(who)
130
- return who if Scope===who
131
- return who.to_wlang_scope if who.respond_to?(:to_wlang_scope)
132
- return HashScope.new(who) if Hash===who
133
- return who
134
- end
135
-
136
- end # class Context
137
-
138
- end
139
- end
@@ -1 +0,0 @@
1
- puts "blambeau".to_sym
@@ -1 +0,0 @@
1
- <<+{buffering_template5.wtpl using self with who2: who, hello: 'world'}
@@ -1 +0,0 @@
1
- +{who} +{hello}
@@ -1,29 +0,0 @@
1
- require 'test/unit'
2
- require 'wlang'
3
- require 'wlang/parser_context'
4
- module WLang
5
-
6
- #
7
- # Tests WLang::Parser::Context class
8
- #
9
- class ParserContextTest < Test::Unit::TestCase
10
-
11
- # Sets a context instance
12
- def setup
13
- customer = Struct.new(:name, :address)
14
- hash = {"name" => "blambeau", "age" => 28,
15
- "customer" => customer.new("Dave", "123 Main")}
16
- @context = WLang::Parser::Context.new(hash)
17
- end
18
-
19
- # Tests Context#evaluate
20
- def test_evaluate
21
- assert_equal("blambeau", @context.evaluate("name"))
22
- assert_equal(28, @context.evaluate("age"))
23
- assert_equal("123 Main", @context.evaluate("customer.address"))
24
- assert_not_nil @context.evaluate("self")
25
- end
26
-
27
- end # class ParserContextTest
28
-
29
- end # module WLang