walrus 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/walrus +19 -12
- data/lib/walrus.rb +27 -70
- data/lib/walrus/additions/string.rb +21 -35
- data/lib/walrus/compile_error.rb +19 -16
- data/lib/walrus/compiler.rb +66 -55
- data/lib/walrus/contrib/spec/walruscloth_spec.rb +21 -17
- data/lib/walrus/contrib/walruscloth.rb +19 -11
- data/lib/walrus/document.rb +41 -33
- data/lib/walrus/grammar.rb +474 -162
- data/lib/walrus/grammar/assignment_expression.rb +33 -0
- data/lib/walrus/grammar/block_directive.rb +37 -0
- data/lib/walrus/grammar/comment.rb +33 -0
- data/lib/walrus/grammar/def_directive.rb +80 -0
- data/lib/walrus/grammar/echo_directive.rb +56 -0
- data/lib/walrus/grammar/escape_sequence.rb +33 -0
- data/lib/walrus/grammar/import_directive.rb +54 -0
- data/lib/walrus/grammar/include_directive.rb +36 -0
- data/lib/walrus/grammar/instance_variable.rb +33 -0
- data/lib/walrus/grammar/literal.rb +33 -0
- data/lib/walrus/grammar/message_expression.rb +34 -0
- data/lib/walrus/grammar/multiline_comment.rb +70 -0
- data/lib/walrus/grammar/placeholder.rb +47 -0
- data/lib/walrus/grammar/raw_directive.rb +50 -0
- data/lib/walrus/grammar/raw_text.rb +56 -0
- data/lib/walrus/grammar/ruby_directive.rb +41 -0
- data/lib/walrus/grammar/ruby_expression.rb +42 -0
- data/lib/walrus/grammar/set_directive.rb +34 -0
- data/lib/walrus/grammar/silent_directive.rb +51 -0
- data/lib/walrus/grammar/slurp_directive.rb +36 -0
- data/lib/walrus/grammar/super_directive.rb +34 -0
- data/lib/walrus/parser.rb +26 -408
- data/lib/walrus/runner.rb +37 -20
- data/lib/walrus/template.rb +34 -25
- data/lib/walrus/version.rb +24 -1
- metadata +57 -71
- data/ext/extconf.rb +0 -16
- data/ext/jindex.c +0 -92
- data/lib/walrus/diff.rb +0 -95
- data/lib/walrus/grammar/additions/proc.rb +0 -26
- data/lib/walrus/grammar/additions/regexp.rb +0 -27
- data/lib/walrus/grammar/additions/string.rb +0 -58
- data/lib/walrus/grammar/additions/symbol.rb +0 -49
- data/lib/walrus/grammar/and_predicate.rb +0 -46
- data/lib/walrus/grammar/array_result.rb +0 -25
- data/lib/walrus/grammar/continuation_wrapper_exception.rb +0 -34
- data/lib/walrus/grammar/left_recursion_exception.rb +0 -33
- data/lib/walrus/grammar/location_tracking.rb +0 -115
- data/lib/walrus/grammar/match_data_wrapper.rb +0 -71
- data/lib/walrus/grammar/memoizing.rb +0 -47
- data/lib/walrus/grammar/memoizing_cache.rb +0 -103
- data/lib/walrus/grammar/node.rb +0 -66
- data/lib/walrus/grammar/not_predicate.rb +0 -46
- data/lib/walrus/grammar/parse_error.rb +0 -45
- data/lib/walrus/grammar/parser_state.rb +0 -187
- data/lib/walrus/grammar/parslet.rb +0 -34
- data/lib/walrus/grammar/parslet_choice.rb +0 -128
- data/lib/walrus/grammar/parslet_combination.rb +0 -32
- data/lib/walrus/grammar/parslet_combining.rb +0 -160
- data/lib/walrus/grammar/parslet_merge.rb +0 -94
- data/lib/walrus/grammar/parslet_omission.rb +0 -63
- data/lib/walrus/grammar/parslet_repetition.rb +0 -106
- data/lib/walrus/grammar/parslet_repetition_default.rb +0 -64
- data/lib/walrus/grammar/parslet_sequence.rb +0 -214
- data/lib/walrus/grammar/predicate.rb +0 -63
- data/lib/walrus/grammar/proc_parslet.rb +0 -58
- data/lib/walrus/grammar/regexp_parslet.rb +0 -79
- data/lib/walrus/grammar/skipped_substring_exception.rb +0 -42
- data/lib/walrus/grammar/string_enumerator.rb +0 -53
- data/lib/walrus/grammar/string_parslet.rb +0 -81
- data/lib/walrus/grammar/string_result.rb +0 -30
- data/lib/walrus/grammar/symbol_parslet.rb +0 -69
- data/lib/walrus/no_parameter_marker.rb +0 -25
- data/lib/walrus/walrus_grammar/assignment_expression.rb +0 -30
- data/lib/walrus/walrus_grammar/block_directive.rb +0 -34
- data/lib/walrus/walrus_grammar/comment.rb +0 -30
- data/lib/walrus/walrus_grammar/def_directive.rb +0 -72
- data/lib/walrus/walrus_grammar/echo_directive.rb +0 -50
- data/lib/walrus/walrus_grammar/escape_sequence.rb +0 -30
- data/lib/walrus/walrus_grammar/import_directive.rb +0 -50
- data/lib/walrus/walrus_grammar/include_directive.rb +0 -33
- data/lib/walrus/walrus_grammar/instance_variable.rb +0 -30
- data/lib/walrus/walrus_grammar/literal.rb +0 -30
- data/lib/walrus/walrus_grammar/message_expression.rb +0 -31
- data/lib/walrus/walrus_grammar/multiline_comment.rb +0 -60
- data/lib/walrus/walrus_grammar/placeholder.rb +0 -46
- data/lib/walrus/walrus_grammar/raw_directive.rb +0 -48
- data/lib/walrus/walrus_grammar/raw_text.rb +0 -51
- data/lib/walrus/walrus_grammar/ruby_directive.rb +0 -35
- data/lib/walrus/walrus_grammar/ruby_expression.rb +0 -37
- data/lib/walrus/walrus_grammar/set_directive.rb +0 -30
- data/lib/walrus/walrus_grammar/silent_directive.rb +0 -50
- data/lib/walrus/walrus_grammar/slurp_directive.rb +0 -31
- data/lib/walrus/walrus_grammar/super_directive.rb +0 -33
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
|
|
2
|
+
# Redistribution and use in source and binary forms, with or without
|
|
3
|
+
# modification, are permitted provided that the following conditions are met:
|
|
4
|
+
#
|
|
5
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
6
|
+
# this list of conditions and the following disclaimer.
|
|
7
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
9
|
+
# and/or other materials provided with the distribution.
|
|
10
|
+
#
|
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
13
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
14
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
|
15
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
16
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
17
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
18
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
19
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
20
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
21
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
22
|
+
|
|
23
|
+
require 'walrus/grammar/ruby_expression.rb'
|
|
24
|
+
|
|
25
|
+
module Walrus
|
|
26
|
+
class Grammar
|
|
27
|
+
class AssignmentExpression < RubyExpression
|
|
28
|
+
def compile options = {}
|
|
29
|
+
@lvalue.source_text + '=' + @expression.source_text
|
|
30
|
+
end
|
|
31
|
+
end # class AssignmentExpression
|
|
32
|
+
end # class Grammar
|
|
33
|
+
end # Walrus
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
|
|
2
|
+
# Redistribution and use in source and binary forms, with or without
|
|
3
|
+
# modification, are permitted provided that the following conditions are met:
|
|
4
|
+
#
|
|
5
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
6
|
+
# this list of conditions and the following disclaimer.
|
|
7
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
9
|
+
# and/or other materials provided with the distribution.
|
|
10
|
+
#
|
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
13
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
14
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
|
15
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
16
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
17
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
18
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
19
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
20
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
21
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
22
|
+
|
|
23
|
+
require 'walrus/grammar/def_directive.rb'
|
|
24
|
+
|
|
25
|
+
module Walrus
|
|
26
|
+
class Grammar
|
|
27
|
+
class BlockDirective < DefDirective
|
|
28
|
+
# Returns a string containing the compiled (Ruby) version of receiver.
|
|
29
|
+
def compile options = {}
|
|
30
|
+
inner, outer = super
|
|
31
|
+
inner = '' if inner.nil?
|
|
32
|
+
inner << "lookup_and_accumulate_placeholder(#{@identifier.to_s.to_sym.inspect})\n"
|
|
33
|
+
[inner, outer]
|
|
34
|
+
end
|
|
35
|
+
end # class BlockDirective
|
|
36
|
+
end # class Grammar
|
|
37
|
+
end # Walrus
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
|
|
2
|
+
# Redistribution and use in source and binary forms, with or without
|
|
3
|
+
# modification, are permitted provided that the following conditions are met:
|
|
4
|
+
#
|
|
5
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
6
|
+
# this list of conditions and the following disclaimer.
|
|
7
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
9
|
+
# and/or other materials provided with the distribution.
|
|
10
|
+
#
|
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
13
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
14
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
|
15
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
16
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
17
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
18
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
19
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
20
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
21
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
22
|
+
|
|
23
|
+
require 'walrus/grammar.rb'
|
|
24
|
+
|
|
25
|
+
module Walrus
|
|
26
|
+
class Grammar
|
|
27
|
+
class Comment < Walrat::Node
|
|
28
|
+
def compile options = {}
|
|
29
|
+
'# Comment:' + @lexeme.to_s + "\n"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end # class Grammar
|
|
33
|
+
end # Walrus
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
|
|
2
|
+
# Redistribution and use in source and binary forms, with or without
|
|
3
|
+
# modification, are permitted provided that the following conditions are met:
|
|
4
|
+
#
|
|
5
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
6
|
+
# this list of conditions and the following disclaimer.
|
|
7
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
9
|
+
# and/or other materials provided with the distribution.
|
|
10
|
+
#
|
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
13
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
14
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
|
15
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
16
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
17
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
18
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
19
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
20
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
21
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
22
|
+
|
|
23
|
+
require 'walrus/grammar.rb'
|
|
24
|
+
|
|
25
|
+
module Walrus
|
|
26
|
+
class Grammar
|
|
27
|
+
class DefDirective < Directive
|
|
28
|
+
# Returns a string containing the compiled (Ruby) version of receiver.
|
|
29
|
+
def compile options = {}
|
|
30
|
+
internal = ''
|
|
31
|
+
|
|
32
|
+
if @params == []
|
|
33
|
+
external = "def #{@identifier.to_s}\n"
|
|
34
|
+
else
|
|
35
|
+
# this will work for the simple case where params are plain identifiers
|
|
36
|
+
params = (@params.kind_of? Array) ? @params : [@params]
|
|
37
|
+
param_list = params.map { |param| param.compile }.join(', ')
|
|
38
|
+
external = "def #{@identifier.to_s}(#{param_list})\n"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
nested = nil
|
|
42
|
+
|
|
43
|
+
if @content.respond_to? :each
|
|
44
|
+
content = @content
|
|
45
|
+
else
|
|
46
|
+
content = [@content]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
content.each do |element|
|
|
50
|
+
if element.kind_of? Walrus::Grammar::DefDirective
|
|
51
|
+
# must handle nested def blocks here
|
|
52
|
+
inner, outer = element.compile(options)
|
|
53
|
+
nested = ['', ''] if nested.nil?
|
|
54
|
+
external << inner if inner
|
|
55
|
+
nested[1] << "\n" + outer
|
|
56
|
+
else
|
|
57
|
+
# again, may wish to forget the per-line indenting here if it
|
|
58
|
+
# breaks sensitive directive types
|
|
59
|
+
# (#ruby blocks for example, which might have here documents)
|
|
60
|
+
element.compile(options).each do |lines|
|
|
61
|
+
# may return a single line or an array of lines
|
|
62
|
+
lines.each { |line| external << ' ' + line }
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
external << "end\n\n"
|
|
68
|
+
|
|
69
|
+
if nested
|
|
70
|
+
external << nested[1]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# better to return nil than an empty string here (which would get
|
|
74
|
+
# indented needlessly)
|
|
75
|
+
internal = nil if internal == ''
|
|
76
|
+
[internal, external]
|
|
77
|
+
end
|
|
78
|
+
end # class DefDirective
|
|
79
|
+
end # class Grammar
|
|
80
|
+
end # Walrus
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
|
|
2
|
+
# Redistribution and use in source and binary forms, with or without
|
|
3
|
+
# modification, are permitted provided that the following conditions are met:
|
|
4
|
+
#
|
|
5
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
6
|
+
# this list of conditions and the following disclaimer.
|
|
7
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
9
|
+
# and/or other materials provided with the distribution.
|
|
10
|
+
#
|
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
13
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
14
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
|
15
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
16
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
17
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
18
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
19
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
20
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
21
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
22
|
+
|
|
23
|
+
require 'walrus/grammar.rb'
|
|
24
|
+
|
|
25
|
+
module Walrus
|
|
26
|
+
class Grammar
|
|
27
|
+
class EchoDirective < Directive
|
|
28
|
+
def compile options = {}
|
|
29
|
+
if @expression.respond_to? :each
|
|
30
|
+
expression = @expression
|
|
31
|
+
else
|
|
32
|
+
expression = [@expression]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# TODO: potentially include line, col and file name info in the
|
|
36
|
+
# comments generated by the compiler
|
|
37
|
+
|
|
38
|
+
compiled = ''
|
|
39
|
+
first = true
|
|
40
|
+
expression.each do |expr|
|
|
41
|
+
if first
|
|
42
|
+
compiled <<
|
|
43
|
+
"accumulate(instance_eval { %s }) # Echo directive\n" %
|
|
44
|
+
expr.compile
|
|
45
|
+
first = false
|
|
46
|
+
else
|
|
47
|
+
compiled <<
|
|
48
|
+
"accumulate(instance_eval { %s }) # Echo directive (continued)\n" %
|
|
49
|
+
expr.compile
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
compiled
|
|
53
|
+
end
|
|
54
|
+
end # class EchoDirective
|
|
55
|
+
end # class Grammar
|
|
56
|
+
end # Walrus
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
|
|
2
|
+
# Redistribution and use in source and binary forms, with or without
|
|
3
|
+
# modification, are permitted provided that the following conditions are met:
|
|
4
|
+
#
|
|
5
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
6
|
+
# this list of conditions and the following disclaimer.
|
|
7
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
9
|
+
# and/or other materials provided with the distribution.
|
|
10
|
+
#
|
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
13
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
14
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
|
15
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
16
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
17
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
18
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
19
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
20
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
21
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
22
|
+
|
|
23
|
+
require 'walrus/grammar.rb'
|
|
24
|
+
|
|
25
|
+
module Walrus
|
|
26
|
+
class Grammar
|
|
27
|
+
class EscapeSequence < Walrat::Node
|
|
28
|
+
def compile options = {}
|
|
29
|
+
"accumulate(%s) \# EscapeSequence\n" % @lexeme.to_s.dump
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end # class Grammar
|
|
33
|
+
end # Walrus
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
|
|
2
|
+
# Redistribution and use in source and binary forms, with or without
|
|
3
|
+
# modification, are permitted provided that the following conditions are met:
|
|
4
|
+
#
|
|
5
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
6
|
+
# this list of conditions and the following disclaimer.
|
|
7
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
9
|
+
# and/or other materials provided with the distribution.
|
|
10
|
+
#
|
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
13
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
14
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
|
15
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
16
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
17
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
18
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
19
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
20
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
21
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
22
|
+
|
|
23
|
+
require 'walrus/grammar.rb'
|
|
24
|
+
require 'walrat/additions/string.rb'
|
|
25
|
+
require 'ostruct'
|
|
26
|
+
|
|
27
|
+
module Walrus
|
|
28
|
+
class Grammar
|
|
29
|
+
class ImportDirective < Directive
|
|
30
|
+
# Returns an OpenStruct encapsulating information about the receiver for use by the compiler
|
|
31
|
+
def compile options = {}
|
|
32
|
+
info = OpenStruct.new
|
|
33
|
+
path = Pathname.new @class_name.lexeme.to_s
|
|
34
|
+
|
|
35
|
+
if path.absolute?
|
|
36
|
+
# it will work just fine as it is
|
|
37
|
+
info.class_name = path.basename.to_s.to_class_name
|
|
38
|
+
info.require_line = "require '#{path.to_s}'"
|
|
39
|
+
else
|
|
40
|
+
dir, base = path.split
|
|
41
|
+
info.class_name = base.to_s.to_class_name
|
|
42
|
+
if dir.to_s == '.'
|
|
43
|
+
# desired template is in the same directory
|
|
44
|
+
info.require_line = "require File.join(File.dirname(__FILE__), '#{base.to_s}').to_s"
|
|
45
|
+
else
|
|
46
|
+
# desired template is in a relative directory
|
|
47
|
+
info.require_line = "require File.join(File.dirname(__FILE__), '#{dir.to_s}', '#{base.to_s}').to_s"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
info
|
|
51
|
+
end
|
|
52
|
+
end # class ImportDirective
|
|
53
|
+
end # class Grammar
|
|
54
|
+
end # Walrus
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
|
|
2
|
+
# Redistribution and use in source and binary forms, with or without
|
|
3
|
+
# modification, are permitted provided that the following conditions are met:
|
|
4
|
+
#
|
|
5
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
6
|
+
# this list of conditions and the following disclaimer.
|
|
7
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
9
|
+
# and/or other materials provided with the distribution.
|
|
10
|
+
#
|
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
13
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
14
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
|
15
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
16
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
17
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
18
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
19
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
20
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
21
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
22
|
+
|
|
23
|
+
require 'walrus/grammar.rb'
|
|
24
|
+
|
|
25
|
+
module Walrus
|
|
26
|
+
class Grammar
|
|
27
|
+
class IncludeDirective < Directive
|
|
28
|
+
def compile options = {}
|
|
29
|
+
inner, outer = options[:compiler_instance].compile_subtree(subtree)
|
|
30
|
+
inner = [] if inner.nil?
|
|
31
|
+
inner.unshift "\# Include (start): #{file_name.to_s}:\n"
|
|
32
|
+
[inner, outer]
|
|
33
|
+
end
|
|
34
|
+
end # class IncludeDirective
|
|
35
|
+
end # class Grammar
|
|
36
|
+
end # Walrus
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
|
|
2
|
+
# Redistribution and use in source and binary forms, with or without
|
|
3
|
+
# modification, are permitted provided that the following conditions are met:
|
|
4
|
+
#
|
|
5
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
6
|
+
# this list of conditions and the following disclaimer.
|
|
7
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
9
|
+
# and/or other materials provided with the distribution.
|
|
10
|
+
#
|
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
13
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
14
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
|
15
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
16
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
17
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
18
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
19
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
20
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
21
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
22
|
+
|
|
23
|
+
require 'walrus/grammar/ruby_expression.rb'
|
|
24
|
+
|
|
25
|
+
module Walrus
|
|
26
|
+
class Grammar
|
|
27
|
+
class InstanceVariable < RubyExpression
|
|
28
|
+
def compile options = {}
|
|
29
|
+
@lexeme.source_text
|
|
30
|
+
end
|
|
31
|
+
end # class InstanceVariable
|
|
32
|
+
end # class Grammar
|
|
33
|
+
end # Walrus
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
|
|
2
|
+
# Redistribution and use in source and binary forms, with or without
|
|
3
|
+
# modification, are permitted provided that the following conditions are met:
|
|
4
|
+
#
|
|
5
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
6
|
+
# this list of conditions and the following disclaimer.
|
|
7
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
9
|
+
# and/or other materials provided with the distribution.
|
|
10
|
+
#
|
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
13
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
14
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
|
15
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
16
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
17
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
18
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
19
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
20
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
21
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
22
|
+
|
|
23
|
+
require 'walrus/grammar.rb'
|
|
24
|
+
|
|
25
|
+
module Walrus
|
|
26
|
+
class Grammar
|
|
27
|
+
class Literal < Walrat::Node
|
|
28
|
+
def compile options = {}
|
|
29
|
+
@lexeme.source_text
|
|
30
|
+
end
|
|
31
|
+
end # class Literal
|
|
32
|
+
end # class Grammar
|
|
33
|
+
end # Walrus
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
|
|
2
|
+
# Redistribution and use in source and binary forms, with or without
|
|
3
|
+
# modification, are permitted provided that the following conditions are met:
|
|
4
|
+
#
|
|
5
|
+
# 1. Redistributions of source code must retain the above copyright notice,
|
|
6
|
+
# this list of conditions and the following disclaimer.
|
|
7
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
8
|
+
# this list of conditions and the following disclaimer in the documentation
|
|
9
|
+
# and/or other materials provided with the distribution.
|
|
10
|
+
#
|
|
11
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
12
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
13
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
14
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
|
|
15
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
16
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
17
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
18
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
19
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
20
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
21
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
|
22
|
+
|
|
23
|
+
require 'walrus/grammar/ruby_expression.rb'
|
|
24
|
+
|
|
25
|
+
module Walrus
|
|
26
|
+
class Grammar
|
|
27
|
+
class MessageExpression < RubyExpression
|
|
28
|
+
def compile options = {}
|
|
29
|
+
# simple case
|
|
30
|
+
@target.source_text + '.' + @message.source_text
|
|
31
|
+
end
|
|
32
|
+
end # class MessageExpression
|
|
33
|
+
end # class Grammar
|
|
34
|
+
end # Walrus
|