diff --git a/doc/specification/specification.yml b/doc/specification/specification.yml
index 476302e..90cf44c 100644
--- a/doc/specification/specification.yml
+++ b/doc/specification/specification.yml
@@ -1,6 +1,6 @@
---
title: WLang
-version: 0.9.1
+version: 0.9.3
sections:
- identifier: about
name: About
@@ -254,15 +254,15 @@ rulesets:
scope is provided by the Context ruleset. All are variants of 'saving previous instantiations' in
scope variables...
examples:
- - ["wlang/*", '={name as n}{Hello +{n}}', "Hello O'Neil"]
- - ["wlang/*", '={name as n}Hello +{n}', "Hello O'Neil"]
- - ["wlang/*", '#={name}{blambeau}{Hello +{name}} and +{name}', "Hello blambeau and O'Neil"]
- - ["wlang/*", '#={name}{blambeau}Hello +{name} and +{name}', "Hello blambeau and blambeau"]
- - ["wlang/*", '={author as name}{Hello +{name}} and +{name}', "Hello blambeau and O'Neil"]
- - ["wlang/*", '={author as name}Hello +{name} and +{name}', "Hello blambeau and blambeau"]
- - ["wlang/*", '%={wlang/dummy as hello}{Hello +{name}}{+{hello}}', "Hello +{name}"]
- - ["wlang/*", '^={plain-text/upcase as name}{+{author}}{Hello +{name}} and +{name}', "Hello BLAMBEAU and O'Neil"]
- - ["wlang/*", '^={plain-text/upcase as name}{+{author}}Hello +{name} and +{name}', "Hello BLAMBEAU and BLAMBEAU"]
+ - ["wlang/*", '={name as n}{Hello !{n}}', "Hello O'Neil"]
+ - ["wlang/*", '={name as n}Hello !{n}', "Hello O'Neil"]
+ - ["wlang/*", '#={name}{blambeau}{Hello !{name}} and !{name}', "Hello blambeau and O'Neil"]
+ - ["wlang/*", '#={name}{blambeau}Hello !{name} and !{name}', "Hello blambeau and blambeau"]
+ - ["wlang/*", '={author as name}{Hello !{name}} and !{name}', "Hello blambeau and O'Neil"]
+ - ["wlang/*", '={author as name}Hello !{name} and !{name}', "Hello blambeau and blambeau"]
+ - ["wlang/*", '%={wlang/dummy as hello}{Hello !{name}}{!{hello}}', "Hello !{name}"]
+ - ["wlang/*", '^={plain-text/upcase as name}{!{author}}{Hello !{name}} and !{name}', "Hello BLAMBEAU and O'Neil"]
+ - ["wlang/*", '^={plain-text/upcase as name}{!{author}}Hello !{name} and !{name}', "Hello BLAMBEAU and BLAMBEAU"]
rules:
# ={wlang/hosted as x}{...}
diff --git a/lib/wlang.rb b/lib/wlang.rb
index 6d4ab3b..9bd952b 100644
--- a/lib/wlang.rb
+++ b/lib/wlang.rb
@@ -20,7 +20,7 @@
module WLang
# Current version of WLang
- VERSION = "0.9.2".freeze
+ VERSION = "0.9.3".freeze
######################################################################## About files and extensions
diff --git a/lib/wlang/dialects/hosted_dialect.rb b/lib/wlang/dialects/hosted_dialect.rb
new file mode 100644
index 0000000..6ed74e7
--- /dev/null
+++ b/lib/wlang/dialects/hosted_dialect.rb
@@ -0,0 +1,50 @@
+module WLang
+ class EncoderSet
+
+ # Encoders for ruby
+ module Hosted
+
+ # Default encoders
+ DEFAULT_ENCODERS = {"main-encoding" => :main_encoding,
+ "single-quoting" => :single_quoting,
+ "double-quoting" => :double_quoting,
+ "regex-escaping" => :regex_escaping,
+ "method-case" => :method_case}
+
+ # No-op encoding here
+ def self.main_encoding(src, options); src; end
+
+ # Single-quoting encoding
+ def self.single_quoting(src, options); src.gsub(/([^\\])'/,%q{\1\\\'}); end
+
+ # Double-quoting encoding
+ def self.double_quoting(src, options); src.gsub('"','\"'); end
+
+ # Regexp-escaping encoding
+ def self.regex_escaping(src, options); Regexp.escape(src); end
+
+ # Converts any source to a typical ruby method name
+ def self.method_case(src, options)
+ src.strip.gsub(/[^a-zA-Z0-9\s]/," ").
+ gsub(/([A-Z])/){ " " + $1.downcase}.
+ strip.
+ gsub(/^([^a-z])/){ "_" + $1 }.
+ gsub(/\s+/){"_"}
+ end
+
+
+ end # module Hosted
+
+ end
+ class RuleSet
+
+ # Defines rulset of the wlang/ruby dialect
+ module Hosted
+
+ # Default mapping between tag symbols and methods
+ DEFAULT_RULESET = {}
+
+ end # module Hosted
+
+ end # class RuleSet
+end # module WLang
diff --git a/lib/wlang/dialects/plain_text_dialect.rb b/lib/wlang/dialects/plain_text_dialect.rb
index fedb829..1e563ae 100644
--- a/lib/wlang/dialects/plain_text_dialect.rb
+++ b/lib/wlang/dialects/plain_text_dialect.rb
@@ -47,7 +47,7 @@ module PlainText
# Upcase rule as +{wlang/hosted}
def self.upcase(parser, offset)
- expression, reached = parser.parse(offset, "wlang/ruby")
+ expression, reached = parser.parse(offset, "wlang/hosted")
value = parser.evaluate(expression)
value = value.nil? ? "" : value.to_s
result = WLang::EncoderSet::PlainText.upcase(value)
@@ -56,7 +56,7 @@ def self.upcase(parser, offset)
# Downcase rule as -{wlang/hosted}
def self.downcase(parser, offset)
- expression, reached = parser.parse(offset, "wlang/ruby")
+ expression, reached = parser.parse(offset, "wlang/hosted")
value = parser.evaluate(expression)
value = value.nil? ? "" : value.to_s
result = EncoderSet::PlainText.downcase(value)
diff --git a/lib/wlang/dialects/ruby_dialect.rb b/lib/wlang/dialects/ruby_dialect.rb
index 596de4e..8bb2580 100644
--- a/lib/wlang/dialects/ruby_dialect.rb
+++ b/lib/wlang/dialects/ruby_dialect.rb
@@ -106,7 +106,7 @@ module Ruby
# Rule implementation of +{wlang/ruby}.
def self.inclusion(parser, offset)
- expression, reached = parser.parse(offset, "wlang/ruby")
+ expression, reached = parser.parse(offset, "wlang/hosted")
value = parser.evaluate(expression)
result = WLang::EncoderSet::Ruby.to_literal(value)
[result, reached]
@@ -115,4 +115,4 @@ def self.inclusion(parser, offset)
end # module Ruby
end # class RuleSet
-end # module WLang
\ No newline at end of file
+end # module WLang
diff --git a/lib/wlang/dialects/standard_dialects.rb b/lib/wlang/dialects/standard_dialects.rb
index 4f8c3d3..66fbbf0 100644
--- a/lib/wlang/dialects/standard_dialects.rb
+++ b/lib/wlang/dialects/standard_dialects.rb
@@ -72,6 +72,18 @@
dialect("dummy") do
end
+ # wlang/ruby dialect
+ dialect("hosted") do
+ ruby_require "wlang/dialects/hosted_dialect" do
+ encoders WLang::EncoderSet::Hosted
+ rules WLang::RuleSet::Basic
+ rules WLang::RuleSet::Encoding
+ rules WLang::RuleSet::Imperative
+ rules WLang::RuleSet::Context
+ rules WLang::RuleSet::Hosted
+ end
+ end
+
# wlang/active-string dialect
dialect("active-string") do
rules WLang::RuleSet::Basic
diff --git a/lib/wlang/rulesets/basic_ruleset.rb b/lib/wlang/rulesets/basic_ruleset.rb
index 90a81d9..8f3540a 100644
--- a/lib/wlang/rulesets/basic_ruleset.rb
+++ b/lib/wlang/rulesets/basic_ruleset.rb
@@ -19,7 +19,7 @@ module Basic
# Rule implementation of !{wlang/ruby}.
def self.execution(parser, offset)
- expression, reached = parser.parse(offset, "wlang/ruby")
+ expression, reached = parser.parse(offset, "wlang/hosted")
value = parser.evaluate(expression)
result = value.nil? ? "" : value.to_s
[result, reached]
diff --git a/lib/wlang/rulesets/context_ruleset.rb b/lib/wlang/rulesets/context_ruleset.rb
index eb7cea1..c424c4e 100644
--- a/lib/wlang/rulesets/context_ruleset.rb
+++ b/lib/wlang/rulesets/context_ruleset.rb
@@ -18,7 +18,7 @@ module Context
# Rule implementation of ={wlang/hosted as x}{...}
def self.assignment(parser, offset)
- expr, reached = parser.parse(offset, "wlang/ruby")
+ expr, reached = parser.parse(offset, "wlang/hosted")
# decode expression
decoded = U.decode_expr_as(expr)
@@ -62,7 +62,7 @@ def self.block_assignment(parser, offset)
# Rule implementation of %={wlang/active-string as x}{...}{...}
def self.modulo_assignment(parser, offset)
- dialect_as, reached = parser.parse(offset, "wlang/ruby")
+ dialect_as, reached = parser.parse(offset, "wlang/hosted")
# decode expression
decoded = U.decode_qdialect_as(dialect_as)
@@ -84,7 +84,7 @@ def self.modulo_assignment(parser, offset)
# Rule implementation of ^={wlang/active-string as x}{...}{...}
def self.encoding_assignment(parser, offset)
- encoding_as, reached = parser.parse(offset, "wlang/ruby")
+ encoding_as, reached = parser.parse(offset, "wlang/hosted")
# decode expression
decoded = U.decode_qencoder_as(encoding_as)
diff --git a/lib/wlang/rulesets/encoding_ruleset.rb b/lib/wlang/rulesets/encoding_ruleset.rb
index 166a798..60b3919 100644
--- a/lib/wlang/rulesets/encoding_ruleset.rb
+++ b/lib/wlang/rulesets/encoding_ruleset.rb
@@ -45,7 +45,7 @@ def self.double_quoting(parser, offset)
# Injection as ${wlang/ruby}
def self.injection(parser, offset)
- expression, reached = parser.parse(offset, "wlang/ruby")
+ expression, reached = parser.parse(offset, "wlang/hosted")
result = parser.evaluate(expression)
encoded = parser.encode(result.to_s, "main-encoding")
[encoded, reached]
@@ -53,7 +53,7 @@ def self.injection(parser, offset)
# Single-quoted as '{wlang/ruby}
def self.single_quoted(parser, offset)
- expression, reached = parser.parse(offset, "wlang/ruby")
+ expression, reached = parser.parse(offset, "wlang/hosted")
result = parser.evaluate(expression)
encoded = parser.encode(result.to_s, "single-quoting")
["'" << encoded, reached]
@@ -61,7 +61,7 @@ def self.single_quoted(parser, offset)
# Double-quoted as "{wlang/ruby}
def self.double_quoted(parser, offset)
- expression, reached = parser.parse(offset, "wlang/ruby")
+ expression, reached = parser.parse(offset, "wlang/hosted")
result = parser.evaluate(expression)
encoded = parser.encode(result.to_s, "double-quoting")
['"' << encoded, reached]
diff --git a/lib/wlang/rulesets/imperative_ruleset.rb b/lib/wlang/rulesets/imperative_ruleset.rb
index fd66e13..fee4814 100644
--- a/lib/wlang/rulesets/imperative_ruleset.rb
+++ b/lib/wlang/rulesets/imperative_ruleset.rb
@@ -27,7 +27,7 @@ module Imperative
# otherwise instantiates #3 if present.
#
def self.conditional(parser, offset)
- expression, reached = parser.parse(offset, "wlang/ruby")
+ expression, reached = parser.parse(offset, "wlang/hosted")
value = parser.evaluate(expression)
if value
then_block, reached = parser.parse_block(reached)
@@ -64,7 +64,7 @@ def self.merge_each_args(names, args)
# name x in the scope). If #3 is present, it is instantiated between elements.
#
def self.enumeration(parser, offset)
- expression, reached = parser.parse(offset, "wlang/ruby")
+ expression, reached = parser.parse(offset, "wlang/hosted")
# decode 'wlang/hosted using each as x' expression
hash = U.expr(:expr,