wlang 0.10.2 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -121
- data/Gemfile +23 -1
- data/Gemfile.lock +32 -28
- data/LICENCE.md +18 -21
- data/Manifest.txt +4 -5
- data/README.md +100 -174
- data/Rakefile +1 -13
- data/bin/wlang +3 -29
- data/lib/wlang.rb +21 -394
- data/lib/wlang/command.rb +94 -0
- data/lib/wlang/compiler.rb +78 -0
- data/lib/wlang/compiler/autospacing.rb +60 -0
- data/lib/wlang/compiler/dialect_enforcer.rb +91 -0
- data/lib/wlang/compiler/filter.rb +32 -0
- data/lib/wlang/compiler/grammar.citrus +67 -0
- data/lib/wlang/compiler/parser.rb +26 -0
- data/lib/wlang/compiler/proc_call_removal.rb +15 -0
- data/lib/wlang/compiler/static_merger.rb +28 -0
- data/lib/wlang/compiler/strconcat_flattener.rb +25 -0
- data/lib/wlang/compiler/to_ruby_abstraction.rb +22 -0
- data/lib/wlang/compiler/to_ruby_code.rb +55 -0
- data/lib/wlang/dialect.rb +40 -237
- data/lib/wlang/dialect/dispatching.rb +51 -0
- data/lib/wlang/dialect/evaluation.rb +30 -0
- data/lib/wlang/dialect/tags.rb +50 -0
- data/lib/wlang/dummy.rb +32 -0
- data/lib/wlang/html.rb +106 -0
- data/lib/wlang/loader.rb +6 -0
- data/lib/wlang/mustang.rb +90 -0
- data/lib/wlang/scope.rb +57 -0
- data/lib/wlang/scope/binding_scope.rb +18 -0
- data/lib/wlang/scope/object_scope.rb +25 -0
- data/lib/wlang/scope/proxy_scope.rb +18 -0
- data/lib/wlang/scope/root_scope.rb +24 -0
- data/lib/wlang/template.rb +16 -86
- data/lib/wlang/version.rb +9 -8
- data/spec/fixtures/dialect/foobar.rb +31 -0
- data/spec/fixtures/dialect/upcasing.rb +13 -0
- data/spec/fixtures/templates/hello.tpl +1 -0
- data/spec/integration/examples/1-basics.txt +65 -0
- data/spec/integration/examples/2-imperative.txt +51 -0
- data/spec/integration/examples/3-partials.txt +76 -0
- data/spec/integration/examples/4-recursion.txt +16 -0
- data/spec/integration/html/test_ampersand.rb +15 -0
- data/spec/integration/html/test_bang.rb +38 -0
- data/spec/integration/html/test_caret.rb +33 -0
- data/spec/integration/html/test_dollar.rb +16 -0
- data/spec/integration/html/test_greater.rb +23 -0
- data/spec/integration/html/test_modulo.rb +16 -0
- data/spec/integration/html/test_plus.rb +48 -0
- data/spec/integration/html/test_question.rb +33 -0
- data/spec/integration/html/test_sharp.rb +21 -0
- data/spec/integration/html/test_slash.rb +16 -0
- data/spec/integration/html/test_star.rb +37 -0
- data/spec/integration/test_dummy.rb +51 -0
- data/spec/integration/test_examples.rb +29 -0
- data/spec/integration/test_mustang.rb +120 -0
- data/spec/integration/test_readme.rb +56 -0
- data/spec/integration/test_upcasing.rb +22 -0
- data/spec/spec_helper.rb +62 -1
- data/spec/test_wlang.rb +101 -0
- data/spec/unit/compiler/autospacing/test_right_strip.rb +30 -0
- data/spec/unit/compiler/autospacing/test_unindent.rb +30 -0
- data/spec/unit/compiler/test_dialect_enforcer.rb +168 -0
- data/spec/unit/compiler/test_grammar.rb +207 -0
- data/spec/unit/compiler/test_parser.rb +69 -0
- data/spec/unit/compiler/test_proc_call_removal.rb +24 -0
- data/spec/unit/compiler/test_static_merger.rb +29 -0
- data/spec/unit/compiler/test_strconcat_flattener.rb +30 -0
- data/spec/unit/compiler/test_to_ruby_abstraction.rb +59 -0
- data/spec/unit/compiler/test_to_ruby_code.rb +24 -0
- data/spec/unit/dialect/test_compile.rb +52 -0
- data/spec/unit/dialect/test_dispatching.rb +19 -0
- data/spec/unit/dialect/test_evaluate.rb +41 -0
- data/spec/unit/dialect/test_render.rb +33 -0
- data/spec/unit/dialect/test_tags.rb +32 -0
- data/spec/unit/dialect/test_with_scope.rb +18 -0
- data/spec/unit/scope/test_binding_scope.rb +27 -0
- data/spec/unit/scope/test_coerce.rb +22 -0
- data/spec/unit/scope/test_object_scope.rb +38 -0
- data/spec/unit/scope/test_proxy_scope.rb +22 -0
- data/spec/unit/scope/test_root_scope.rb +22 -0
- data/spec/unit/test_assumptions.rb +29 -0
- data/spec/unit/test_scope.rb +57 -0
- data/tasks/debug_mail.rake +42 -45
- data/tasks/gem.rake +22 -17
- data/tasks/spec_test.rake +9 -17
- data/tasks/unit_test.rake +11 -12
- data/tasks/yard.rake +13 -13
- data/wlang.gemspec +36 -32
- data/wlang.noespec +27 -35
- metadata +268 -451
- data/doc/specification/about.rdoc +0 -61
- data/doc/specification/analytics.wtpl +0 -13
- data/doc/specification/dialect.wtpl +0 -14
- data/doc/specification/dialects.wtpl +0 -3
- data/doc/specification/examples.rb +0 -3
- data/doc/specification/glossary.wtpl +0 -14
- data/doc/specification/hosting.rdoc +0 -0
- data/doc/specification/overview.rdoc +0 -116
- data/doc/specification/rulesets.wtpl +0 -87
- data/doc/specification/specification.css +0 -53
- data/doc/specification/specification.html +0 -1690
- data/doc/specification/specification.js +0 -8
- data/doc/specification/specification.wtpl +0 -42
- data/doc/specification/specification.yml +0 -432
- data/doc/specification/symbols.wtpl +0 -16
- data/lib/wlang/dialect_dsl.rb +0 -141
- data/lib/wlang/dialect_loader.rb +0 -74
- data/lib/wlang/dialects/bluecloth_dialect.rb +0 -16
- data/lib/wlang/dialects/coderay_dialect.rb +0 -45
- data/lib/wlang/dialects/hosted_dialect.rb +0 -50
- data/lib/wlang/dialects/plain_text_dialect.rb +0 -69
- data/lib/wlang/dialects/rdoc_dialect.rb +0 -33
- data/lib/wlang/dialects/redcloth_dialect.rb +0 -16
- data/lib/wlang/dialects/ruby_dialect.rb +0 -118
- data/lib/wlang/dialects/sql_dialect.rb +0 -38
- data/lib/wlang/dialects/standard_dialects.rb +0 -181
- data/lib/wlang/dialects/xhtml_dialect.rb +0 -63
- data/lib/wlang/dialects/yaml_dialect.rb +0 -30
- data/lib/wlang/encoder.rb +0 -62
- data/lib/wlang/encoder_set.rb +0 -122
- data/lib/wlang/errors.rb +0 -80
- data/lib/wlang/ext/hash_methodize.rb +0 -13
- data/lib/wlang/ext/string.rb +0 -44
- data/lib/wlang/hash_scope.rb +0 -89
- data/lib/wlang/hosted_language.rb +0 -146
- data/lib/wlang/intelligent_buffer.rb +0 -94
- data/lib/wlang/parser.rb +0 -332
- data/lib/wlang/parser_state.rb +0 -94
- data/lib/wlang/rule.rb +0 -66
- data/lib/wlang/rule_set.rb +0 -106
- data/lib/wlang/rulesets/basic_ruleset.rb +0 -83
- data/lib/wlang/rulesets/buffering_ruleset.rb +0 -115
- data/lib/wlang/rulesets/context_ruleset.rb +0 -111
- data/lib/wlang/rulesets/encoding_ruleset.rb +0 -73
- data/lib/wlang/rulesets/imperative_ruleset.rb +0 -132
- data/lib/wlang/rulesets/ruleset_utils.rb +0 -317
- data/lib/wlang/wlang_command.rb +0 -51
- data/lib/wlang/wlang_command_options.rb +0 -163
- data/spec/basic_object.spec +0 -40
- data/spec/coderay_dialect.spec +0 -8
- data/spec/dialect/apply_post_transform.spec +0 -16
- data/spec/global_extensions.rb +0 -2
- data/spec/hash_scope.spec +0 -76
- data/spec/redcloth_dialect.spec +0 -24
- data/spec/test_all.rb +0 -8
- data/spec/wlang.spec +0 -53
- data/spec/wlang_spec.rb +0 -8
- data/spec/xhtml_dialect.spec +0 -22
- data/tasks/genspec.rake +0 -5
- data/test/blackbox/basic/execution_1.exp +0 -1
- data/test/blackbox/basic/execution_1.tpl +0 -1
- data/test/blackbox/basic/execution_2.exp +0 -1
- data/test/blackbox/basic/execution_2.tpl +0 -1
- data/test/blackbox/basic/execution_3.exp +0 -1
- data/test/blackbox/basic/execution_3.tpl +0 -1
- data/test/blackbox/basic/execution_4.exp +0 -1
- data/test/blackbox/basic/execution_4.tpl +0 -1
- data/test/blackbox/basic/inclusion_1.exp +0 -1
- data/test/blackbox/basic/inclusion_1.tpl +0 -1
- data/test/blackbox/basic/inclusion_2.exp +0 -1
- data/test/blackbox/basic/inclusion_2.tpl +0 -1
- data/test/blackbox/basic/injection_1.exp +0 -1
- data/test/blackbox/basic/injection_1.tpl +0 -1
- data/test/blackbox/basic/injection_2.exp +0 -1
- data/test/blackbox/basic/injection_2.tpl +0 -1
- data/test/blackbox/basic/modulation_1.exp +0 -1
- data/test/blackbox/basic/modulation_1.tpl +0 -1
- data/test/blackbox/basic/modulation_2.exp +0 -1
- data/test/blackbox/basic/modulation_2.tpl +0 -1
- data/test/blackbox/basic/recursive_app_1.exp +0 -1
- data/test/blackbox/basic/recursive_app_1.tpl +0 -1
- data/test/blackbox/basic/recursive_app_2.exp +0 -1
- data/test/blackbox/basic/recursive_app_2.tpl +0 -1
- data/test/blackbox/buffering/data_1.rb +0 -1
- data/test/blackbox/buffering/data_assignment_1.exp +0 -1
- data/test/blackbox/buffering/data_assignment_1.tpl +0 -1
- data/test/blackbox/buffering/data_assignment_2.exp +0 -1
- data/test/blackbox/buffering/data_assignment_2.tpl +0 -1
- data/test/blackbox/buffering/data_assignment_3.exp +0 -1
- data/test/blackbox/buffering/data_assignment_3.tpl +0 -1
- data/test/blackbox/buffering/data_assignment_4.exp +0 -1
- data/test/blackbox/buffering/data_assignment_4.tpl +0 -1
- data/test/blackbox/buffering/input_1.exp +0 -1
- data/test/blackbox/buffering/input_1.tpl +0 -1
- data/test/blackbox/buffering/input_2.exp +0 -1
- data/test/blackbox/buffering/input_2.tpl +0 -1
- data/test/blackbox/buffering/input_3.exp +0 -1
- data/test/blackbox/buffering/input_3.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion.exp +0 -1
- data/test/blackbox/buffering/input_inclusion.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_1.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_1.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_2.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_2.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_3.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_3.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_4.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_4.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_5.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_5.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_6.exp +0 -1
- data/test/blackbox/buffering/input_inclusion_6.tpl +0 -1
- data/test/blackbox/buffering/input_inclusion_7.exp +0 -0
- data/test/blackbox/buffering/input_inclusion_7.tpl +0 -1
- data/test/blackbox/buffering/text_1.txt +0 -1
- data/test/blackbox/buffering/wlang.txt +0 -1
- data/test/blackbox/context/assignment_1.exp +0 -1
- data/test/blackbox/context/assignment_1.tpl +0 -1
- data/test/blackbox/context/assignment_2.exp +0 -1
- data/test/blackbox/context/assignment_2.tpl +0 -1
- data/test/blackbox/context/assignment_3.exp +0 -2
- data/test/blackbox/context/assignment_3.tpl +0 -2
- data/test/blackbox/context/assignment_4.exp +0 -1
- data/test/blackbox/context/assignment_4.tpl +0 -1
- data/test/blackbox/context/block_assignment_1.exp +0 -1
- data/test/blackbox/context/block_assignment_1.tpl +0 -1
- data/test/blackbox/context/block_assignment_2.exp +0 -1
- data/test/blackbox/context/block_assignment_2.tpl +0 -1
- data/test/blackbox/context/modulo_assignment_1.exp +0 -1
- data/test/blackbox/context/modulo_assignment_1.tpl +0 -1
- data/test/blackbox/context/modulo_assignment_2.exp +0 -1
- data/test/blackbox/context/modulo_assignment_2.tpl +0 -1
- data/test/blackbox/data_1.rb +0 -1
- data/test/blackbox/postblock/hello.exp +0 -1
- data/test/blackbox/postblock/hello.pre +0 -1
- data/test/blackbox/postblock/hello.tpl +0 -1
- data/test/blackbox/postblock/hello_input_inclusion.exp +0 -1
- data/test/blackbox/postblock/hello_input_inclusion.tpl +0 -1
- data/test/blackbox/postblock/hello_to_authors.exp +0 -1
- data/test/blackbox/postblock/hello_to_authors.tpl +0 -1
- data/test/blackbox/poststring/hello.exp +0 -1
- data/test/blackbox/poststring/hello.tpl +0 -1
- data/test/blackbox/test_all.rb +0 -70
- data/test/standard_dialects/ruby/data.rb +0 -7
- data/test/standard_dialects/ruby/inclusion.exp +0 -6
- data/test/standard_dialects/ruby/inclusion.tpl +0 -6
- data/test/standard_dialects/test_all.rb +0 -29
- data/test/standard_dialects/yaml/assumptions_test.rb +0 -13
- data/test/standard_dialects/yaml/data.rb +0 -3
- data/test/standard_dialects/yaml/inclusion_1.exp +0 -7
- data/test/standard_dialects/yaml/inclusion_1.tpl +0 -2
- data/test/standard_dialects/yaml/inclusion_2.exp +0 -5
- data/test/standard_dialects/yaml/inclusion_2.tpl +0 -3
- data/test/unit/test_all.rb +0 -9
- data/test/unit/wlang/anagram_bugs_test.rb +0 -111
- data/test/unit/wlang/basic_ruleset_test.rb +0 -52
- data/test/unit/wlang/buffering_ruleset_test.rb +0 -102
- data/test/unit/wlang/buffering_template1.wtpl +0 -1
- data/test/unit/wlang/buffering_template2.wtpl +0 -1
- data/test/unit/wlang/buffering_template3.wtpl +0 -1
- data/test/unit/wlang/buffering_template4.wtpl +0 -1
- data/test/unit/wlang/buffering_template5.wtpl +0 -1
- data/test/unit/wlang/context_ruleset_test.rb +0 -32
- data/test/unit/wlang/data.rb +0 -3
- data/test/unit/wlang/encoder_set_test.rb +0 -42
- data/test/unit/wlang/imperative_ruleset_test.rb +0 -107
- data/test/unit/wlang/intelligent_buffer_test.rb +0 -194
- data/test/unit/wlang/othersymbols_test.rb +0 -16
- data/test/unit/wlang/parser_test.rb +0 -88
- data/test/unit/wlang/plain_text_dialect_test.rb +0 -21
- data/test/unit/wlang/ruby_dialect_test.rb +0 -100
- data/test/unit/wlang/ruby_expected.rb +0 -3
- data/test/unit/wlang/ruby_template.wrb +0 -3
- data/test/unit/wlang/ruleset_utils_test.rb +0 -245
- data/test/unit/wlang/specification_examples_test.rb +0 -54
- data/test/unit/wlang/test_utils.rb +0 -25
- data/test/unit/wlang/wlang_test.rb +0 -80
data/lib/wlang/rule.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
module WLang
|
2
|
-
|
3
|
-
#
|
4
|
-
# A Rule is designed to perform a replacement job when the special tag associated
|
5
|
-
# with it is found in a Template. Rules are always installed on a RuleSet (using
|
6
|
-
# RuleSet#add_rule), which is itself installed on a Dialect. Note that the method
|
7
|
-
# mentionned previously provides a DRY shortcut, allowing not using this class
|
8
|
-
# directly.
|
9
|
-
#
|
10
|
-
# Example:
|
11
|
-
# # Rule subclassing can be avoided by providing a block to new
|
12
|
-
# # The following rule job is to upcase the text inside +{...} tags:
|
13
|
-
# rule = Rule.new do |parser,offset|
|
14
|
-
# parsed, reached = parser.parse(offset)
|
15
|
-
# [parsed.upcase, reached]
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# Creating a a new rule can be made in two ways: by subclassing this class and
|
19
|
-
# overriding the start_tag method or by passing a block to new. In both cases,
|
20
|
-
# <b>rules should always be stateless</b>, to allow reusable dialects that could
|
21
|
-
# even be used in a multi-threading environment. Implementing a rule correctly
|
22
|
-
# must be considered non trivial due to the strong protocol between the parser
|
23
|
-
# and its rules and the stateless convention. Always have a look to helpers
|
24
|
-
# provided by RuleSet (to create simple rules easily) before deciding to implement
|
25
|
-
# a rule using this class.
|
26
|
-
#
|
27
|
-
# == Detailed API
|
28
|
-
class Rule
|
29
|
-
|
30
|
-
#
|
31
|
-
# Creates a new rule. If no block is given, the invocation of new MUST be made
|
32
|
-
# on a subclass overriding start_tag. Otherwise, the block is considered as the
|
33
|
-
# effective stateless implementation of start_tag and will be called with the
|
34
|
-
# same arguments.
|
35
|
-
#
|
36
|
-
def initialize(&block)
|
37
|
-
unless block.nil?
|
38
|
-
raise(ArgumentError, "Expected a rule block of arity 2")\
|
39
|
-
unless block.arity==2
|
40
|
-
end
|
41
|
-
@block = block
|
42
|
-
end
|
43
|
-
|
44
|
-
#
|
45
|
-
# Fired when the parser has reached an offset matching this rule.
|
46
|
-
#
|
47
|
-
# This method MUST return an array [_replacement_, _offset_] where _replacement_
|
48
|
-
# is what replaces the tag itself in the resulting text and _offset_ is the
|
49
|
-
# new offset reached in the source text (where parsing will continue).
|
50
|
-
# _offset_ should always be such that <tt>text[offset,1]=='}'</tt> to allow
|
51
|
-
# higher stages to continue their job correctly. Utility methods for parsing
|
52
|
-
# text parts are provided by the parser itself (see WLang::Parser).
|
53
|
-
#
|
54
|
-
# Arguments:
|
55
|
-
# - parser: WLang parser currently parsing the text.
|
56
|
-
# - offset: offset reached in the text, corresponding to the first character
|
57
|
-
# of the first block associated with the matching tag.
|
58
|
-
#
|
59
|
-
def start_tag(parser, offset)
|
60
|
-
raise(NotImplementedError) unless @block
|
61
|
-
@block.call(parser, offset)
|
62
|
-
end
|
63
|
-
|
64
|
-
end # class Rule
|
65
|
-
|
66
|
-
end # module WLang
|
data/lib/wlang/rule_set.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'wlang/rule'
|
2
|
-
module WLang
|
3
|
-
|
4
|
-
#
|
5
|
-
# This class allows grouping matching rules together to build a given dialect.
|
6
|
-
# Rules are always added with add_rule, which also allows creating simple rules
|
7
|
-
# on the fly (that is, without subclassing Rule).
|
8
|
-
#
|
9
|
-
# Examples:
|
10
|
-
# # we will create a simple dialect with a special tag:
|
11
|
-
# # <tt>+{...}</tt> which will uppercase its contents
|
12
|
-
# upcaser = RuleSet.new
|
13
|
-
# upcaser.add_rule '+' do |parser,offset|
|
14
|
-
# parsed, offset = parser.parse(offset)
|
15
|
-
# [parsed.upcase, offset]
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# == Detailed API
|
19
|
-
class RuleSet
|
20
|
-
|
21
|
-
# Which modules are reused
|
22
|
-
attr_reader :reuse
|
23
|
-
|
24
|
-
#
|
25
|
-
# Creates an new dialect rule set.
|
26
|
-
#
|
27
|
-
def initialize()
|
28
|
-
@rules = {}
|
29
|
-
@reuse = []
|
30
|
-
@patterns = Hash.new{|h, k| h[k] = build_pattern(k)}
|
31
|
-
end
|
32
|
-
|
33
|
-
# Yields the block with name, rule pairs
|
34
|
-
def each
|
35
|
-
@rules.each_pair{|name,rule| yield(name, rule)}
|
36
|
-
end
|
37
|
-
|
38
|
-
#
|
39
|
-
# Adds a tag matching rule to this rule set. _tag_ must be a String with the
|
40
|
-
# tag associated to the rule (without the '{', that is '$' for the tag ${...}
|
41
|
-
# for example. If rule is ommited and a block is given, a new Rule instance is
|
42
|
-
# created on the fly with _block_ as implementation (see Rule#new).
|
43
|
-
# Otherwise rule is expected to be a Rule instance. This method check its
|
44
|
-
# arguments, raising an ArgumentError if incorrect.
|
45
|
-
#
|
46
|
-
def add_rule(tag, rule=nil, &block)
|
47
|
-
if rule.nil?
|
48
|
-
raise(ArgumentError,"Block required") unless block_given?
|
49
|
-
rule = Rule.new(&block)
|
50
|
-
end
|
51
|
-
raise(ArgumentError, "Rule expected") unless Rule===rule
|
52
|
-
@rules[tag] = rule
|
53
|
-
@patterns.clear
|
54
|
-
end
|
55
|
-
|
56
|
-
#
|
57
|
-
# Add rules defined in a given RuleSet module.
|
58
|
-
#
|
59
|
-
def add_rules(mod, pairs=nil)
|
60
|
-
raise(ArgumentError,"Module expected") unless Module===mod
|
61
|
-
reuse << mod
|
62
|
-
pairs = mod::DEFAULT_RULESET if pairs.nil?
|
63
|
-
pairs.each_pair do |symbol,method|
|
64
|
-
meth = mod.method(method)
|
65
|
-
raise(ArgumentError,"No such method: #{method}") if meth.nil?
|
66
|
-
add_rule(symbol, &meth.to_proc)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
#
|
71
|
-
# Returns a Regexp instance with recognizes all tags installed in the rule set.
|
72
|
-
# The returned Regexp is backslashing aware (it matches <tt>\${</tt> for example)
|
73
|
-
# as well as '{' and '}' aware. This pattern is used by WLang::Parser and is
|
74
|
-
# not intended to be used by users themselve.
|
75
|
-
#
|
76
|
-
def pattern(block_symbols)
|
77
|
-
@patterns[block_symbols]
|
78
|
-
end
|
79
|
-
|
80
|
-
#
|
81
|
-
# Returns the Rule associated with a given tag, _nil_ if no such rule.
|
82
|
-
#
|
83
|
-
def [](tag) @rules[tag]; end
|
84
|
-
|
85
|
-
|
86
|
-
### protected section ######################################################
|
87
|
-
protected
|
88
|
-
|
89
|
-
# Internal implementation of pattern.
|
90
|
-
def build_pattern(block_symbols)
|
91
|
-
start, stop = WLang::Template::BLOCK_SYMBOLS[block_symbols]
|
92
|
-
start, stop = Regexp.escape(start), Regexp.escape(stop)
|
93
|
-
s = '([\\\\]{0,2}('
|
94
|
-
i=0
|
95
|
-
@rules.each_key do |tag|
|
96
|
-
s << '|' if i>0
|
97
|
-
s << '(' << Regexp.escape(tag) << ')'
|
98
|
-
i += 1
|
99
|
-
end
|
100
|
-
s << ")#{start})|[\\\\]{0,2}#{start}|[\\\\]{0,2}#{stop}"
|
101
|
-
Regexp.new(s)
|
102
|
-
end
|
103
|
-
|
104
|
-
end # class RuleSet
|
105
|
-
|
106
|
-
end # module WLang
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'wlang/rulesets/ruleset_utils'
|
2
|
-
module WLang
|
3
|
-
class RuleSet
|
4
|
-
|
5
|
-
#
|
6
|
-
# Basic ruleset, commonly included by any wlang dialect (but some tags, like
|
7
|
-
# <tt>${...}</tt> may be overriden). This ruleset is often installed conjointly
|
8
|
-
# with WLang::RuleSet::Encoding which provides interresting overridings of
|
9
|
-
# <tt>${...}</tt> and <tt>+{...}</tt>.
|
10
|
-
#
|
11
|
-
# For an overview of this ruleset, see the wlang {specification file}[link://files/specification.html].
|
12
|
-
#
|
13
|
-
module Basic
|
14
|
-
U=WLang::RuleSet::Utils
|
15
|
-
|
16
|
-
# Default mapping between tag symbols and methods
|
17
|
-
DEFAULT_RULESET = {'!' => :execution, '%' => :modulation, '^' => :encoding,
|
18
|
-
'+' => :inclusion, '$' => :injection, '%!' => :recursive_application}
|
19
|
-
|
20
|
-
# Rule implementation of <tt>!{wlang/ruby}</tt>.
|
21
|
-
def self.execution(parser, offset)
|
22
|
-
expression, reached = parser.parse(offset, "wlang/hosted")
|
23
|
-
value = parser.evaluate(expression)
|
24
|
-
result = value.nil? ? "" : value.to_s
|
25
|
-
[result, reached]
|
26
|
-
end
|
27
|
-
|
28
|
-
# Rule implementation of <tt>%{wlang/active-string}{...}</tt>.
|
29
|
-
def self.modulation(parser, offset)
|
30
|
-
dialect, reached = parser.parse(offset, "wlang/active-string")
|
31
|
-
result, reached = parser.parse_block(reached, dialect)
|
32
|
-
[result, reached]
|
33
|
-
end
|
34
|
-
|
35
|
-
# Rule implementation of <tt>^{wlang/active-string}{...}</tt>
|
36
|
-
def self.encoding(parser, offset)
|
37
|
-
encoder, reached = parser.parse(offset, "wlang/active-string")
|
38
|
-
result, reached = parser.parse_block(reached)
|
39
|
-
result = parser.encode(result, encoder)
|
40
|
-
[result, reached]
|
41
|
-
end
|
42
|
-
|
43
|
-
# Rule implementation of <tt>${wlang/ruby}</tt>
|
44
|
-
def self.injection(parser, offset)
|
45
|
-
execution(parser, offset)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Rule implementation of <tt>+{wlang/ruby}</tt>
|
49
|
-
def self.inclusion(parser, offset)
|
50
|
-
execution(parser, offset)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Rule implementation of <tt>%!{wlang/ruby using ... with ...}{...}</tt>
|
54
|
-
def self.recursive_application(parser, offset)
|
55
|
-
dialect, reached = parser.parse(offset, "wlang/active-string")
|
56
|
-
text, reached = parser.parse_block(reached)
|
57
|
-
|
58
|
-
# decode expression
|
59
|
-
decoded = U.expr(:qdialect,
|
60
|
-
["share", :share, false],
|
61
|
-
["using", :expr, false],
|
62
|
-
["with", :with, false]).decode(dialect, parser)
|
63
|
-
parser.syntax_error(offset) if decoded.nil?
|
64
|
-
|
65
|
-
# build context
|
66
|
-
dialect2 = decoded[:qdialect]
|
67
|
-
shared = decoded[:share].nil? ? :root : decoded[:share]
|
68
|
-
context = U.context_from_using_and_with(decoded)
|
69
|
-
|
70
|
-
# TODO: refactor me!!
|
71
|
-
parser.branch(:template => WLang::template(text, dialect2),
|
72
|
-
:offset => 0,
|
73
|
-
:shared => shared,
|
74
|
-
:scope => context) {
|
75
|
-
instantiated, forget = parser.instantiate(true)
|
76
|
-
[instantiated, reached]
|
77
|
-
}
|
78
|
-
end
|
79
|
-
|
80
|
-
end # module Basic
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
require 'wlang/rulesets/ruleset_utils'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module WLang
|
5
|
-
class RuleSet
|
6
|
-
|
7
|
-
#
|
8
|
-
# Buffering ruleset, providing special tags to load/instantiate accessible files
|
9
|
-
# and outputting instantiation results in other files.
|
10
|
-
#
|
11
|
-
# For an overview of this ruleset, see the wlang {specification file}[link://files/specification.html].
|
12
|
-
#
|
13
|
-
module Buffering
|
14
|
-
U=WLang::RuleSet::Utils
|
15
|
-
|
16
|
-
# Default mapping between tag symbols and methods
|
17
|
-
DEFAULT_RULESET = {'<<' => :input, '>>' => :output,
|
18
|
-
'<<=' => :data_assignment, '<<+' => :input_inclusion}
|
19
|
-
|
20
|
-
# Rule implementation of <tt><<{wlang/uri}</tt>
|
21
|
-
def self.input(parser, offset)
|
22
|
-
uri, reached = parser.parse(offset, "wlang/uri")
|
23
|
-
file = parser.template.file_resolve(uri, false)
|
24
|
-
if File.file?(file) and File.readable?(file)
|
25
|
-
[File.read(file), reached]
|
26
|
-
else
|
27
|
-
text = parser.parse(offset, "wlang/dummy")[0]
|
28
|
-
parser.error(offset, "unable to apply input rule <<{#{text}}, not a file or not readable (#{file})")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# Rule implementation of <tt>>>{wlang/uri}</tt>
|
33
|
-
def self.output(parser, offset)
|
34
|
-
uri, reached = parser.parse(offset, "wlang/uri")
|
35
|
-
file = parser.template.file_resolve(uri, false)
|
36
|
-
dir = File.dirname(file)
|
37
|
-
if File.writable?(dir) or not(File.exists?(dir))
|
38
|
-
FileUtils.mkdir_p(dir) unless File.exists?(dir)
|
39
|
-
File.open(file, "w") do |file|
|
40
|
-
text, reached = parser.parse_block(reached, nil, file)
|
41
|
-
end
|
42
|
-
["", reached]
|
43
|
-
else
|
44
|
-
text = parser.parse(offset, "wlang/dummy")[0]
|
45
|
-
parser.error(offset, "unable to apply output rule >>{#{text}}, not a writable directory (#{file})")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Rule implementation of <<={wlang/uri as x}{...}
|
50
|
-
def self.data_assignment(parser, offset)
|
51
|
-
uri, reached = parser.parse(offset, "wlang/uri")
|
52
|
-
|
53
|
-
# decode expression
|
54
|
-
decoded = U.decode_uri_as(uri)
|
55
|
-
parser.syntax_error(offset) if decoded.nil?
|
56
|
-
|
57
|
-
file = parser.template.file_resolve(decoded[:uri], false)
|
58
|
-
if File.file?(file) and File.readable?(file)
|
59
|
-
data = WLang::load_data(file)
|
60
|
-
|
61
|
-
# handle two different cases
|
62
|
-
if parser.has_block?(reached)
|
63
|
-
parser.branch_scope(decoded[:variable] => data) {
|
64
|
-
parser.parse_block(reached)
|
65
|
-
}
|
66
|
-
else
|
67
|
-
parser.scope_define(decoded[:variable], data)
|
68
|
-
["", reached]
|
69
|
-
end
|
70
|
-
else
|
71
|
-
text = parser.parse(offset, "wlang/dummy")[0]
|
72
|
-
parser.error(offset, "unable to apply data-assignment rule <<={#{text}} (#{file}), not a file or not readable (#{file})")
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Rule implementation of <<+{wlang/uri with ...}
|
77
|
-
def self.input_inclusion(parser, offset)
|
78
|
-
uri, reached = parser.parse(offset, "wlang/uri")
|
79
|
-
|
80
|
-
# decode the expression
|
81
|
-
decoded = U.expr(:uri,
|
82
|
-
["share", :share, false],
|
83
|
-
["using", :using, false],
|
84
|
-
["with", :with, false]).decode(uri, parser)
|
85
|
-
parser.syntax_error(offset) if decoded.nil?
|
86
|
-
|
87
|
-
# Look for share and context
|
88
|
-
shared = decoded[:share].nil? ? :none : decoded[:share]
|
89
|
-
context = U.context_from_using_and_with(decoded, parser)
|
90
|
-
|
91
|
-
# Resolve the file by delegation to the parser
|
92
|
-
file = parser.file_resolve(decoded[:uri])
|
93
|
-
|
94
|
-
# Go for it
|
95
|
-
if File.file?(file) and File.readable?(file)
|
96
|
-
parser.branch(:template => parser.file_template(file),
|
97
|
-
:offset => 0,
|
98
|
-
:shared => shared,
|
99
|
-
:scope => context) {
|
100
|
-
# We ask the parser to instantiate and apply
|
101
|
-
# post transformation in all cases
|
102
|
-
instantiated, forget = parser.instantiate(true)
|
103
|
-
[instantiated, reached]
|
104
|
-
}
|
105
|
-
else
|
106
|
-
text = parser.parse(offset, "wlang/dummy")[0]
|
107
|
-
parser.error(offset, "unable to apply input-inclusion rule <<+{#{text}}, not a file or not readable (#{file})")
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
end # module Buffering
|
113
|
-
|
114
|
-
end
|
115
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require 'wlang/rulesets/ruleset_utils'
|
2
|
-
module WLang
|
3
|
-
class RuleSet
|
4
|
-
|
5
|
-
#
|
6
|
-
# Provides a ruleset for managing the context/scoping during instantitation.
|
7
|
-
#
|
8
|
-
# For an overview of this ruleset, see the wlang {specification file}[link://files/specification.html].
|
9
|
-
#
|
10
|
-
module Context
|
11
|
-
U=WLang::RuleSet::Utils
|
12
|
-
|
13
|
-
# Default mapping between tag symbols and methods
|
14
|
-
DEFAULT_RULESET = {'=' => :assignment,
|
15
|
-
'#=' => :block_assignment,
|
16
|
-
'%=' => :modulo_assignment,
|
17
|
-
'^=' => :encoding_assignment}
|
18
|
-
|
19
|
-
# Rule implementation of <tt>={wlang/hosted as x}{...}</tt>
|
20
|
-
def self.assignment(parser, offset)
|
21
|
-
expr, reached = parser.parse(offset, "wlang/hosted")
|
22
|
-
|
23
|
-
# decode expression
|
24
|
-
decoded = U.decode_expr_as(expr)
|
25
|
-
parser.syntax_error(offset) if decoded.nil?
|
26
|
-
|
27
|
-
# evaluate it
|
28
|
-
value = parser.evaluate(decoded[:expr])
|
29
|
-
|
30
|
-
# handle two different cases
|
31
|
-
if parser.has_block?(reached)
|
32
|
-
parser.branch_scope(decoded[:variable] => value) {
|
33
|
-
parser.parse_block(reached)
|
34
|
-
}
|
35
|
-
else
|
36
|
-
parser.scope_define(decoded[:variable], value)
|
37
|
-
["", reached]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Rule implementation of <tt>#={wlang/active-string}{...}{...}</tt>
|
42
|
-
def self.block_assignment(parser, offset)
|
43
|
-
variable, reached = parser.parse(offset, "wlang/active-string")
|
44
|
-
|
45
|
-
# decode expression
|
46
|
-
decoded = U.decode_var(variable)
|
47
|
-
parser.syntax_error(offset) if decoded.nil?
|
48
|
-
|
49
|
-
# parse second block in that dialect
|
50
|
-
value, reached = parser.parse_block(reached)
|
51
|
-
|
52
|
-
# handle two different cases
|
53
|
-
if parser.has_block?(reached)
|
54
|
-
parser.branch_scope(decoded[:variable] => value) {
|
55
|
-
parser.parse_block(reached)
|
56
|
-
}
|
57
|
-
else
|
58
|
-
parser.scope_define(decoded[:variable], value)
|
59
|
-
["", reached]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# Rule implementation of <tt>%={wlang/active-string as x}{...}{...}</tt>
|
64
|
-
def self.modulo_assignment(parser, offset)
|
65
|
-
dialect_as, reached = parser.parse(offset, "wlang/hosted")
|
66
|
-
|
67
|
-
# decode expression
|
68
|
-
decoded = U.decode_qdialect_as(dialect_as)
|
69
|
-
parser.syntax_error(offset) if decoded.nil?
|
70
|
-
|
71
|
-
# parse second block in that dialect
|
72
|
-
value, reached = parser.parse_block(reached, decoded[:dialect])
|
73
|
-
|
74
|
-
# handle two different cases
|
75
|
-
if parser.has_block?(reached)
|
76
|
-
parser.branch_scope(decoded[:variable] => value) {
|
77
|
-
parser.parse_block(reached)
|
78
|
-
}
|
79
|
-
else
|
80
|
-
parser.scope_define(decoded[:variable], value)
|
81
|
-
["", reached]
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Rule implementation of <tt>^={wlang/active-string as x}{...}{...}</tt>
|
86
|
-
def self.encoding_assignment(parser, offset)
|
87
|
-
encoding_as, reached = parser.parse(offset, "wlang/hosted")
|
88
|
-
|
89
|
-
# decode expression
|
90
|
-
decoded = U.decode_qencoder_as(encoding_as)
|
91
|
-
parser.syntax_error(offset) if decoded.nil?
|
92
|
-
|
93
|
-
# parse second block in that dialect
|
94
|
-
value, reached = parser.parse_block(reached)
|
95
|
-
value = parser.encode(value, decoded[:encoder])
|
96
|
-
|
97
|
-
# handle two different cases
|
98
|
-
if parser.has_block?(reached)
|
99
|
-
parser.branch_scope(decoded[:variable] => value) {
|
100
|
-
parser.parse_block(reached)
|
101
|
-
}
|
102
|
-
else
|
103
|
-
parser.scope_define(decoded[:variable], value)
|
104
|
-
["", reached]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
end # module Context
|
109
|
-
|
110
|
-
end
|
111
|
-
end
|