wlang 0.8.5 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +65 -0
- data/README.rdoc +85 -31
- data/bin/wlang +5 -0
- data/doc/specification/dialect.wtpl +14 -0
- data/doc/specification/dialects.wtpl +3 -0
- data/doc/specification/glossary.wtpl +4 -4
- data/doc/specification/rulesets.wtpl +9 -9
- data/doc/specification/specification.css +1 -0
- data/doc/specification/specification.html +68 -5
- data/doc/specification/specification.wtpl +12 -12
- data/doc/specification/specification.yml +9 -9
- data/doc/specification/symbols.wtpl +8 -8
- data/lib/wlang.rb +297 -75
- data/lib/wlang/dialect.rb +7 -3
- data/lib/wlang/dialects/coderay_dialect.rb +4 -4
- data/lib/wlang/dialects/plain_text_dialect.rb +13 -19
- data/lib/wlang/dialects/redcloth_dialect.rb +16 -0
- data/lib/wlang/dialects/ruby_dialect.rb +16 -2
- data/lib/wlang/dialects/standard_dialects.rb +20 -0
- data/lib/wlang/dialects/xhtml_dialect.rb +24 -1
- data/lib/wlang/encoder.rb +1 -1
- data/lib/wlang/encoder_set.rb +5 -0
- data/lib/wlang/errors.rb +70 -6
- data/lib/wlang/ext/hash_methodize.rb +13 -0
- data/lib/wlang/{ruby_extensions.rb → ext/string.rb} +9 -5
- data/lib/wlang/hash_scope.rb +89 -0
- data/lib/wlang/hosted_language.rb +146 -0
- data/lib/wlang/parser.rb +189 -126
- data/lib/wlang/parser_state.rb +94 -0
- data/lib/wlang/rule_set.rb +16 -3
- data/lib/wlang/rulesets/basic_ruleset.rb +14 -6
- data/lib/wlang/rulesets/buffering_ruleset.rb +20 -29
- data/lib/wlang/rulesets/context_ruleset.rb +16 -20
- data/lib/wlang/rulesets/imperative_ruleset.rb +4 -4
- data/lib/wlang/rulesets/ruleset_utils.rb +26 -5
- data/lib/wlang/template.rb +16 -34
- data/lib/wlang/wlang_command.rb +4 -7
- data/lib/wlang/wlang_command_options.rb +5 -0
- data/test/blackbox/basic/execution_1.exp +1 -0
- data/test/blackbox/basic/execution_1.tpl +1 -0
- data/test/blackbox/basic/execution_2.exp +1 -0
- data/test/blackbox/basic/execution_2.tpl +1 -0
- data/test/blackbox/basic/execution_3.exp +1 -0
- data/test/blackbox/basic/execution_3.tpl +1 -0
- data/test/blackbox/basic/execution_4.exp +1 -0
- data/test/blackbox/basic/execution_4.tpl +1 -0
- data/test/blackbox/basic/inclusion_1.exp +1 -0
- data/test/blackbox/basic/inclusion_1.tpl +1 -0
- data/test/blackbox/basic/inclusion_2.exp +1 -0
- data/test/blackbox/basic/inclusion_2.tpl +1 -0
- data/test/blackbox/basic/injection_1.exp +1 -0
- data/test/blackbox/basic/injection_1.tpl +1 -0
- data/test/blackbox/basic/injection_2.exp +1 -0
- data/test/blackbox/basic/injection_2.tpl +1 -0
- data/test/blackbox/basic/modulation_1.exp +1 -0
- data/test/blackbox/basic/modulation_1.tpl +1 -0
- data/test/blackbox/basic/modulation_2.exp +1 -0
- data/test/blackbox/basic/modulation_2.tpl +1 -0
- data/test/blackbox/basic/recursive_app_1.exp +1 -0
- data/test/blackbox/basic/recursive_app_1.tpl +1 -0
- data/test/blackbox/basic/recursive_app_2.exp +1 -0
- data/test/blackbox/basic/recursive_app_2.tpl +1 -0
- data/test/blackbox/buffering/data_1.rb +1 -0
- data/test/blackbox/buffering/data_assignment_1.exp +1 -0
- data/test/blackbox/buffering/data_assignment_1.tpl +1 -0
- data/test/blackbox/buffering/data_assignment_2.exp +1 -0
- data/test/blackbox/buffering/data_assignment_2.tpl +1 -0
- data/test/blackbox/buffering/data_assignment_3.exp +1 -0
- data/test/blackbox/buffering/data_assignment_3.tpl +1 -0
- data/test/blackbox/buffering/data_assignment_4.exp +1 -0
- data/test/blackbox/buffering/data_assignment_4.tpl +1 -0
- data/test/blackbox/buffering/input_1.exp +1 -0
- data/test/blackbox/buffering/input_1.tpl +1 -0
- data/test/blackbox/buffering/input_2.exp +1 -0
- data/test/blackbox/buffering/input_2.tpl +1 -0
- data/test/blackbox/buffering/input_3.exp +1 -0
- data/test/blackbox/buffering/input_3.tpl +1 -0
- data/test/blackbox/buffering/input_inclusion.exp +1 -0
- data/test/blackbox/buffering/input_inclusion.tpl +1 -0
- data/test/blackbox/buffering/input_inclusion_1.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_1.tpl +1 -0
- data/test/blackbox/buffering/input_inclusion_2.exp +1 -0
- data/test/blackbox/buffering/input_inclusion_2.tpl +1 -0
- data/test/blackbox/buffering/input_inclusion_3.exp +1 -0
- data/test/blackbox/buffering/input_inclusion_3.tpl +1 -0
- data/test/blackbox/buffering/input_inclusion_4.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_4.tpl +1 -0
- data/test/blackbox/buffering/input_inclusion_5.exp +1 -0
- data/test/blackbox/buffering/input_inclusion_5.tpl +1 -0
- data/test/blackbox/buffering/input_inclusion_6.exp +1 -0
- data/test/blackbox/buffering/input_inclusion_6.tpl +1 -0
- data/test/blackbox/buffering/input_inclusion_7.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_7.tpl +1 -0
- data/test/blackbox/buffering/text_1.txt +1 -0
- data/test/blackbox/buffering/wlang.txt +1 -0
- data/test/blackbox/context/assignment_1.exp +1 -0
- data/test/blackbox/context/assignment_1.tpl +1 -0
- data/test/blackbox/context/assignment_2.exp +1 -0
- data/test/blackbox/context/assignment_2.tpl +1 -0
- data/test/blackbox/context/assignment_3.exp +2 -0
- data/test/blackbox/context/assignment_3.tpl +2 -0
- data/test/blackbox/context/assignment_4.exp +1 -0
- data/test/blackbox/context/assignment_4.tpl +1 -0
- data/test/blackbox/context/block_assignment_1.exp +1 -0
- data/test/blackbox/context/block_assignment_1.tpl +1 -0
- data/test/blackbox/context/block_assignment_2.exp +1 -0
- data/test/blackbox/context/block_assignment_2.tpl +1 -0
- data/test/blackbox/context/modulo_assignment_1.exp +1 -0
- data/test/blackbox/context/modulo_assignment_1.tpl +1 -0
- data/test/blackbox/context/modulo_assignment_2.exp +1 -0
- data/test/blackbox/context/modulo_assignment_2.tpl +1 -0
- data/test/blackbox/data_1.rb +1 -0
- data/test/blackbox/test_all.rb +59 -0
- data/test/spec/basic_object.spec +40 -0
- data/test/spec/global_extensions.rb +2 -0
- data/test/spec/hash_scope.spec +76 -0
- data/test/spec/redcloth_dialect.spec +24 -0
- data/test/spec/test_all.rb +8 -0
- data/test/spec/wlang.spec +53 -0
- data/test/spec/xhtml_dialect.spec +23 -0
- data/test/{test_all.rb → unit/test_all.rb} +1 -1
- data/test/{wlang → unit/wlang}/anagram_bugs_test.rb +2 -2
- data/test/{wlang → unit/wlang}/basic_ruleset_test.rb +1 -1
- data/test/{wlang → unit/wlang}/buffering_ruleset_test.rb +4 -4
- data/test/{wlang → unit/wlang}/buffering_template1.wtpl +0 -0
- data/test/{wlang → unit/wlang}/buffering_template2.wtpl +0 -0
- data/test/{wlang → unit/wlang}/buffering_template3.wtpl +0 -0
- data/test/unit/wlang/buffering_template4.wtpl +1 -0
- data/test/unit/wlang/buffering_template5.wtpl +1 -0
- data/test/{wlang → unit/wlang}/context_ruleset_test.rb +0 -0
- data/test/{wlang → unit/wlang}/data.rb +0 -0
- data/test/{wlang → unit/wlang}/encoder_set_test.rb +0 -0
- data/test/{wlang → unit/wlang}/imperative_ruleset_test.rb +0 -0
- data/test/{wlang → unit/wlang}/intelligent_buffer_test.rb +0 -0
- data/test/{wlang → unit/wlang}/othersymbols_test.rb +0 -0
- data/test/{wlang → unit/wlang}/parser_test.rb +10 -11
- data/test/{wlang → unit/wlang}/plain_text_dialect_test.rb +0 -0
- data/test/{wlang → unit/wlang}/ruby_dialect_test.rb +0 -0
- data/test/{wlang → unit/wlang}/ruby_expected.rb +0 -0
- data/test/{wlang → unit/wlang}/ruby_template.wrb +0 -0
- data/test/{wlang → unit/wlang}/ruleset_utils_test.rb +0 -0
- data/test/{wlang → unit/wlang}/specification_examples_test.rb +2 -2
- data/test/{wlang → unit/wlang}/test_utils.rb +1 -1
- data/test/{wlang → unit/wlang}/wlang_test.rb +0 -0
- metadata +135 -42
- data/lib/wlang/basic_object.rb +0 -19
- data/lib/wlang/parser_context.rb +0 -139
- data/test/sandbox.rb +0 -1
- data/test/wlang/buffering_template4.wtpl +0 -1
- data/test/wlang/buffering_template5.wtpl +0 -1
- data/test/wlang/parser_context_test.rb +0 -29
data/lib/wlang/basic_object.rb
DELETED
@@ -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
|
data/lib/wlang/parser_context.rb
DELETED
@@ -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
|
data/test/sandbox.rb
DELETED
@@ -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
|