walrus 0.1 → 0.2

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.
Files changed (210) hide show
  1. data/bin/walrus +29 -14
  2. data/ext/extconf.rb +16 -0
  3. data/ext/{jindex/jindex.c → jindex.c} +27 -14
  4. data/lib/walrus/additions/string.rb +11 -5
  5. data/lib/walrus/compile_error.rb +11 -5
  6. data/lib/walrus/compiler.rb +12 -6
  7. data/lib/walrus/contrib/spec/walruscloth_spec.rb +11 -5
  8. data/lib/walrus/contrib/walruscloth.rb +11 -5
  9. data/lib/walrus/diff.rb +11 -5
  10. data/lib/walrus/document.rb +11 -5
  11. data/lib/walrus/grammar/additions/proc.rb +11 -5
  12. data/lib/walrus/grammar/additions/regexp.rb +11 -5
  13. data/lib/walrus/grammar/additions/string.rb +11 -5
  14. data/lib/walrus/grammar/additions/symbol.rb +12 -5
  15. data/lib/walrus/grammar/and_predicate.rb +11 -5
  16. data/lib/walrus/grammar/array_result.rb +11 -5
  17. data/lib/walrus/grammar/continuation_wrapper_exception.rb +11 -5
  18. data/lib/walrus/grammar/left_recursion_exception.rb +11 -5
  19. data/lib/walrus/grammar/location_tracking.rb +19 -9
  20. data/lib/walrus/grammar/match_data_wrapper.rb +11 -5
  21. data/lib/walrus/grammar/memoizing.rb +11 -5
  22. data/lib/walrus/grammar/memoizing_cache.rb +18 -9
  23. data/lib/walrus/grammar/node.rb +11 -5
  24. data/lib/walrus/grammar/not_predicate.rb +11 -5
  25. data/lib/walrus/grammar/parse_error.rb +11 -5
  26. data/lib/walrus/grammar/parser_state.rb +11 -5
  27. data/lib/walrus/grammar/parslet.rb +11 -5
  28. data/lib/walrus/grammar/parslet_choice.rb +15 -7
  29. data/lib/walrus/grammar/parslet_combination.rb +11 -5
  30. data/lib/walrus/grammar/parslet_combining.rb +11 -5
  31. data/lib/walrus/grammar/parslet_merge.rb +11 -5
  32. data/lib/walrus/grammar/parslet_omission.rb +11 -5
  33. data/lib/walrus/grammar/parslet_repetition.rb +17 -8
  34. data/lib/walrus/grammar/parslet_repetition_default.rb +11 -5
  35. data/lib/walrus/grammar/parslet_sequence.rb +20 -8
  36. data/lib/walrus/grammar/predicate.rb +11 -5
  37. data/lib/walrus/grammar/proc_parslet.rb +11 -5
  38. data/lib/walrus/grammar/regexp_parslet.rb +11 -5
  39. data/lib/walrus/grammar/skipped_substring_exception.rb +11 -5
  40. data/lib/walrus/grammar/string_enumerator.rb +14 -6
  41. data/lib/walrus/grammar/string_parslet.rb +11 -5
  42. data/lib/walrus/grammar/string_result.rb +11 -5
  43. data/lib/walrus/grammar/symbol_parslet.rb +11 -5
  44. data/lib/walrus/grammar.rb +11 -5
  45. data/lib/walrus/no_parameter_marker.rb +11 -5
  46. data/lib/walrus/parser.rb +12 -6
  47. data/lib/walrus/runner.rb +60 -67
  48. data/lib/walrus/template.rb +15 -7
  49. data/lib/walrus/version.rb +3 -0
  50. data/lib/walrus/walrus_grammar/assignment_expression.rb +11 -5
  51. data/lib/walrus/walrus_grammar/block_directive.rb +11 -5
  52. data/lib/walrus/walrus_grammar/comment.rb +11 -5
  53. data/lib/walrus/walrus_grammar/def_directive.rb +16 -8
  54. data/lib/walrus/walrus_grammar/echo_directive.rb +11 -5
  55. data/lib/walrus/walrus_grammar/escape_sequence.rb +11 -5
  56. data/lib/walrus/walrus_grammar/import_directive.rb +11 -5
  57. data/lib/walrus/walrus_grammar/include_directive.rb +11 -5
  58. data/lib/walrus/walrus_grammar/instance_variable.rb +11 -5
  59. data/lib/walrus/walrus_grammar/literal.rb +11 -5
  60. data/lib/walrus/walrus_grammar/message_expression.rb +11 -5
  61. data/lib/walrus/walrus_grammar/multiline_comment.rb +11 -5
  62. data/lib/walrus/walrus_grammar/placeholder.rb +11 -5
  63. data/lib/walrus/walrus_grammar/raw_directive.rb +11 -5
  64. data/lib/walrus/walrus_grammar/raw_text.rb +11 -5
  65. data/lib/walrus/walrus_grammar/ruby_directive.rb +11 -5
  66. data/lib/walrus/walrus_grammar/ruby_expression.rb +11 -5
  67. data/lib/walrus/walrus_grammar/set_directive.rb +11 -5
  68. data/lib/walrus/walrus_grammar/silent_directive.rb +11 -5
  69. data/lib/walrus/walrus_grammar/slurp_directive.rb +11 -5
  70. data/lib/walrus/walrus_grammar/super_directive.rb +11 -5
  71. data/lib/walrus.rb +30 -16
  72. metadata +91 -211
  73. data/ext/jindex/extconf.rb +0 -11
  74. data/ext/mkdtemp/extconf.rb +0 -11
  75. data/ext/mkdtemp/mkdtemp.c +0 -41
  76. data/lib/walrus/additions/module.rb +0 -36
  77. data/lib/walrus/additions/test/unit/error_collector.rb +0 -62
  78. data/spec/acceptance/acceptance_spec.rb +0 -97
  79. data/spec/acceptance/block/basic_block.expected +0 -1
  80. data/spec/acceptance/block/basic_block.tmpl +0 -3
  81. data/spec/acceptance/block/nested_blocks.expected +0 -5
  82. data/spec/acceptance/block/nested_blocks.tmpl +0 -11
  83. data/spec/acceptance/comments/comments_and_text.expected +0 -3
  84. data/spec/acceptance/comments/comments_and_text.tmpl +0 -6
  85. data/spec/acceptance/comments/single_comment.expected +0 -0
  86. data/spec/acceptance/comments/single_comment.tmpl +0 -1
  87. data/spec/acceptance/def/alternative_def_calling_conventions.expected +0 -3
  88. data/spec/acceptance/def/alternative_def_calling_conventions.tmpl +0 -18
  89. data/spec/acceptance/def/basic_def_block_no_output.expected +0 -0
  90. data/spec/acceptance/def/basic_def_block_no_output.tmpl +0 -17
  91. data/spec/acceptance/def/defs_can_be_called_multiple_times.expected +0 -3
  92. data/spec/acceptance/def/defs_can_be_called_multiple_times.tmpl +0 -6
  93. data/spec/acceptance/def/defs_can_be_dynamic.expected +0 -4
  94. data/spec/acceptance/def/defs_can_be_dynamic.tmpl +0 -12
  95. data/spec/acceptance/echo/echo_directive_with_numeric_literal.expected +0 -1
  96. data/spec/acceptance/echo/echo_directive_with_numeric_literal.tmpl +0 -1
  97. data/spec/acceptance/echo/echo_expression_list.expected +0 -1
  98. data/spec/acceptance/echo/echo_expression_list.tmpl +0 -1
  99. data/spec/acceptance/echo/echo_short_notation.expected +0 -1
  100. data/spec/acceptance/echo/echo_short_notation.tmpl +0 -1
  101. data/spec/acceptance/echo/echo_simple_expression.expected +0 -1
  102. data/spec/acceptance/echo/echo_simple_expression.tmpl +0 -1
  103. data/spec/acceptance/echo/echo_single_quoted_string_literal.expected +0 -1
  104. data/spec/acceptance/echo/echo_single_quoted_string_literal.tmpl +0 -1
  105. data/spec/acceptance/echo/multiple_echo_statements.expected +0 -1
  106. data/spec/acceptance/echo/multiple_echo_statements.tmpl +0 -2
  107. data/spec/acceptance/includes/basic_included_file.txt +0 -1
  108. data/spec/acceptance/includes/basic_includer.complex +0 -3
  109. data/spec/acceptance/includes/basic_includer.expected +0 -3
  110. data/spec/acceptance/includes/basic_includer.rb +0 -38
  111. data/spec/acceptance/includes/complicated_included_file.txt +0 -3
  112. data/spec/acceptance/includes/complicated_includer.complex +0 -3
  113. data/spec/acceptance/includes/complicated_includer.expected +0 -3
  114. data/spec/acceptance/includes/complicated_includer.rb +0 -41
  115. data/spec/acceptance/includes/nested_include_1.txt +0 -3
  116. data/spec/acceptance/includes/nested_include_2.txt +0 -1
  117. data/spec/acceptance/includes/nested_includer.complex +0 -3
  118. data/spec/acceptance/includes/nested_includer.expected +0 -4
  119. data/spec/acceptance/includes/nested_includer.rb +0 -41
  120. data/spec/acceptance/inheritance/basic_child.complex +0 -10
  121. data/spec/acceptance/inheritance/basic_child.expected +0 -9
  122. data/spec/acceptance/inheritance/basic_child.rb +0 -54
  123. data/spec/acceptance/inheritance/basic_parent.complex +0 -5
  124. data/spec/acceptance/inheritance/basic_parent.expected +0 -3
  125. data/spec/acceptance/inheritance/basic_parent.rb +0 -41
  126. data/spec/acceptance/inheritance/importing_child.complex +0 -8
  127. data/spec/acceptance/inheritance/importing_child.expected +0 -7
  128. data/spec/acceptance/inheritance/importing_child.rb +0 -46
  129. data/spec/acceptance/inheritance/subdirectory/importing_child_in_subdirectory.complex +0 -8
  130. data/spec/acceptance/inheritance/subdirectory/importing_child_in_subdirectory.expected +0 -7
  131. data/spec/acceptance/inheritance/subdirectory/importing_child_in_subdirectory.rb +0 -44
  132. data/spec/acceptance/multiline_comments/multiline_comment_with_directives_inside.expected +0 -0
  133. data/spec/acceptance/multiline_comments/multiline_comment_with_directives_inside.tmpl +0 -15
  134. data/spec/acceptance/multiline_comments/simple_multiline_comment.expected +0 -2
  135. data/spec/acceptance/multiline_comments/simple_multiline_comment.tmpl +0 -4
  136. data/spec/acceptance/raw/complicated_raw_example.expected +0 -57
  137. data/spec/acceptance/raw/complicated_raw_example.tmpl +0 -79
  138. data/spec/acceptance/raw-text/UTF_8.expected +0 -12
  139. data/spec/acceptance/raw-text/UTF_8.tmpl +0 -12
  140. data/spec/acceptance/raw-text/empty_file.expected +0 -0
  141. data/spec/acceptance/raw-text/empty_file.tmpl +0 -0
  142. data/spec/acceptance/raw-text/multi_line.expected +0 -4
  143. data/spec/acceptance/raw-text/multi_line.tmpl +0 -4
  144. data/spec/acceptance/raw-text/single_line.expected +0 -1
  145. data/spec/acceptance/raw-text/single_line.tmpl +0 -1
  146. data/spec/acceptance/raw-text/single_line_whitespace.expected +0 -1
  147. data/spec/acceptance/raw-text/single_line_whitespace.tmpl +0 -1
  148. data/spec/acceptance/ruby/ruby_directive_is_just_like_silent.expected +0 -1
  149. data/spec/acceptance/ruby/ruby_directive_is_just_like_silent.tmpl +0 -4
  150. data/spec/acceptance/ruby/ruby_directive_using_here_doc.expected +0 -1
  151. data/spec/acceptance/ruby/ruby_directive_using_here_doc.tmpl +0 -4
  152. data/spec/acceptance/ruby/ruby_directive_using_here_doc_alt_syntax.expected +0 -1
  153. data/spec/acceptance/ruby/ruby_directive_using_here_doc_alt_syntax.tmpl +0 -4
  154. data/spec/acceptance/ruby/ruby_directive_with_accumulate.expected +0 -1
  155. data/spec/acceptance/ruby/ruby_directive_with_accumulate.tmpl +0 -4
  156. data/spec/acceptance/ruby/ruby_directive_with_accumulate_and_block.expected +0 -1
  157. data/spec/acceptance/ruby/ruby_directive_with_accumulate_and_block.tmpl +0 -6
  158. data/spec/acceptance/set/unused_set.expected +0 -0
  159. data/spec/acceptance/set/unused_set.tmpl +0 -1
  160. data/spec/acceptance/set/used_set.expected +0 -1
  161. data/spec/acceptance/set/used_set.tmpl +0 -2
  162. data/spec/acceptance/silent/silent_and_echo_combined.expected +0 -1
  163. data/spec/acceptance/silent/silent_and_echo_combined.tmpl +0 -2
  164. data/spec/acceptance/silent/silent_short_notation.expected +0 -1
  165. data/spec/acceptance/silent/silent_short_notation.tmpl +0 -1
  166. data/spec/acceptance/silent/simple_silent_directive.expected +0 -0
  167. data/spec/acceptance/silent/simple_silent_directive.tmpl +0 -1
  168. data/spec/acceptance/slurp/basic_slurp_demo.expected +0 -1
  169. data/spec/acceptance/slurp/basic_slurp_demo.tmpl +0 -4
  170. data/spec/acceptance/super/super_with_no_effect.expected +0 -4
  171. data/spec/acceptance/super/super_with_no_effect.tmpl +0 -5
  172. data/spec/additions/module_spec.rb +0 -126
  173. data/spec/additions/string_spec.rb +0 -99
  174. data/spec/compiler_spec.rb +0 -55
  175. data/spec/grammar/additions/proc_spec.rb +0 -25
  176. data/spec/grammar/additions/regexp_spec.rb +0 -37
  177. data/spec/grammar/additions/string_spec.rb +0 -106
  178. data/spec/grammar/and_predicate_spec.rb +0 -29
  179. data/spec/grammar/continuation_wrapper_exception_spec.rb +0 -23
  180. data/spec/grammar/match_data_wrapper_spec.rb +0 -41
  181. data/spec/grammar/memoizing_cache_spec.rb +0 -112
  182. data/spec/grammar/node_spec.rb +0 -126
  183. data/spec/grammar/not_predicate_spec.rb +0 -29
  184. data/spec/grammar/parser_state_spec.rb +0 -172
  185. data/spec/grammar/parslet_choice_spec.rb +0 -49
  186. data/spec/grammar/parslet_combining_spec.rb +0 -287
  187. data/spec/grammar/parslet_merge_spec.rb +0 -33
  188. data/spec/grammar/parslet_omission_spec.rb +0 -58
  189. data/spec/grammar/parslet_repetition_spec.rb +0 -77
  190. data/spec/grammar/parslet_sequence_spec.rb +0 -49
  191. data/spec/grammar/parslet_spec.rb +0 -23
  192. data/spec/grammar/predicate_spec.rb +0 -53
  193. data/spec/grammar/proc_parslet_spec.rb +0 -52
  194. data/spec/grammar/regexp_parslet_spec.rb +0 -347
  195. data/spec/grammar/string_enumerator_spec.rb +0 -94
  196. data/spec/grammar/string_parslet_spec.rb +0 -143
  197. data/spec/grammar/symbol_parslet_spec.rb +0 -30
  198. data/spec/grammar_spec.rb +0 -545
  199. data/spec/parser_spec.rb +0 -1418
  200. data/spec/spec_helper.rb +0 -34
  201. data/spec/walrus_grammar/comment_spec.rb +0 -39
  202. data/spec/walrus_grammar/echo_directive_spec.rb +0 -63
  203. data/spec/walrus_grammar/escape_sequence_spec.rb +0 -85
  204. data/spec/walrus_grammar/literal_spec.rb +0 -41
  205. data/spec/walrus_grammar/message_expression_spec.rb +0 -37
  206. data/spec/walrus_grammar/multiline_comment_spec.rb +0 -58
  207. data/spec/walrus_grammar/placeholder_spec.rb +0 -48
  208. data/spec/walrus_grammar/raw_directive_spec.rb +0 -81
  209. data/spec/walrus_grammar/raw_text_spec.rb +0 -65
  210. data/spec/walrus_grammar/silent_directive_spec.rb +0 -34
@@ -1,10 +1,16 @@
1
1
  # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id: /mirrors/Walrus/trunk/walrus/lib/walrus/grammar.rb 6704 2007-04-09T18:30:00.421185Z wincent $
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus'
10
16
 
@@ -1,10 +1,16 @@
1
1
  # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id$
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus'
10
16
 
data/lib/walrus/parser.rb CHANGED
@@ -1,10 +1,16 @@
1
1
  # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id: /mirrors/Walrus/trunk/walrus/lib/walrus/parser.rb 6755 2007-04-13T14:13:42.727911Z wincent $
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus'
10
16
  require 'pathname'
@@ -188,7 +194,7 @@ module Walrus
188
194
  sub_result = Parser.new.parse(content, sub_options)
189
195
  end
190
196
 
191
- # want to insert a bunch of nodes (a subtree) into the parse tree without advance the location counters
197
+ # want to insert a bunch of nodes (a subtree) into the parse tree without advancing the location counters
192
198
  sub_tree = Grammar::ArrayResult.new [ file_name, sub_result ? sub_result : [] ]
193
199
  sub_tree.start = file_name.start
194
200
  sub_tree.end = file_name.end
data/lib/walrus/runner.rb CHANGED
@@ -1,10 +1,16 @@
1
- # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
1
+ # Copyright 2007-2009 Wincent Colaiuta
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id: /mirrors/Walrus/trunk/walrus/lib/walrus/runner.rb 6751 2007-04-12T16:56:29.067618Z wincent $
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus'
10
16
  require 'fileutils'
@@ -15,15 +21,12 @@ require 'rubygems'
15
21
  require 'wopen3'
16
22
 
17
23
  module Walrus
18
-
19
24
  class Runner
20
-
21
25
  class Error < Exception ; end
22
26
 
23
27
  class ArgumentError < Error ; end
24
-
28
+
25
29
  def initialize
26
-
27
30
  @options = OpenStruct.new
28
31
  @options.output_dir = nil
29
32
  @options.input_extension = 'tmpl'
@@ -35,11 +38,10 @@ module Walrus
35
38
  @options.halt = false
36
39
  @options.dry = false
37
40
  @options.verbose = false
38
-
41
+
39
42
  @command = nil # "compile", "fill" (saves to disk), "run" (prints to standard out)
40
43
  @inputs = [] # list of input files and/or directories
41
44
  parser = OptionParser.new do |o|
42
-
43
45
  o.banner = "Usage: #{o.program_name} command input-file(s)-or-directory/ies [options]"
44
46
  o.separator ''
45
47
  o.separator ' _____________'
@@ -55,82 +57,83 @@ module Walrus
55
57
  o.separator ' fill -- runs compiled templates, writing output to disk'
56
58
  o.separator ' run -- runs compiled templates, printing output to standard output'
57
59
  o.separator ''
58
-
60
+
59
61
  o.on('-o', '--output-dir DIR', 'Output directory (when filling)', 'defaults to same directory as input file') do |opt|
60
62
  @options.output_dir = Pathname.new(opt)
61
63
  end
62
-
64
+
63
65
  o.on('-i', '--input-extension EXT', 'Extension for input file(s)', 'default: tmpl') do |opt|
64
66
  @options.input_extension = opt
65
67
  end
66
-
68
+
67
69
  o.on('-e', '--output-extension EXT', 'Extension for output file(s) (when filling)', 'default: html') do |opt|
68
70
  @options.output_extension = opt
69
71
  end
70
-
72
+
71
73
  o.on('-R', 'Search subdirectories recursively for input files', 'default: on') do |opt|
72
74
  @options.recurse = opts
73
75
  end
74
-
76
+
75
77
  o.on('-b', '--[no-]backup', 'Make backups before overwriting', 'default: on') do |opt|
76
78
  @options.backup = opt
77
79
  end
78
-
80
+
79
81
  o.on('-f', '--force', 'Force a recompile (when filling)', 'default: off (files only recompiled if source newer than output)') do |opt|
80
82
  @options.force = opt
81
83
  end
82
-
84
+
83
85
  o.on('--halt', 'Halts on encountering an error (even a non-fatal error)', 'default: off') do |opt|
84
86
  @options.halt = opt
85
87
  end
86
-
88
+
87
89
  o.on('-t', '--test', 'Performs a "dry" (test) run', 'default: off') do |opt|
88
90
  @options.dry = opt
89
91
  end
90
-
92
+
91
93
  o.on('-d', '--debug', 'Print debugging information to standard error', 'default: off') do |opt|
92
94
  @options.debug = opt
93
95
  end
94
-
96
+
95
97
  o.on('-v', '--verbose', 'Run verbosely', 'default: off') do |opt|
96
98
  @options.verbose = opt
97
99
  end
98
-
100
+
99
101
  o.separator ''
100
-
102
+
101
103
  o.on_tail('-h', '--help', 'Show this message') do
102
104
  $stderr.puts o
103
105
  exit
104
106
  end
105
-
107
+
106
108
  o.on_tail('--version', 'Show version') do
107
109
  $stderr.puts 'Walrus ' + Walrus::VERSION
108
110
  exit
109
111
  end
110
-
111
112
  end
112
-
113
+
113
114
  begin
114
115
  parser.parse!
115
116
  rescue OptionParser::InvalidOption => e
116
117
  raise ArgumentError.new(e)
117
118
  end
118
-
119
+
119
120
  parser.order! do |item|
120
- if @command.nil? : @command = item # get command first ("compile", "fill" or "run")
121
- else @inputs << Pathname.new(item) # all others (and there must be at least one) are file or directory names
121
+ if @command.nil?
122
+ @command = item # get command first ("compile", "fill" or "run")
123
+ else
124
+ @inputs << Pathname.new(item) # all others (and there must be at least one) are file or directory names
122
125
  end
123
126
  end
124
-
127
+
125
128
  raise ArgumentError.new('no command specified') if @command.nil?
126
129
  raise ArgumentError.new('no inputs specified') unless @inputs.length > 0
127
130
  end
128
-
131
+
129
132
  def run
130
133
  log "Beginning processing: #{Time.new.to_s}."
131
-
134
+
132
135
  # TODO: flush memoizing cache after each file
133
-
136
+
134
137
  expand(@inputs).each do |input|
135
138
  case @command
136
139
  when 'compile'
@@ -159,7 +162,7 @@ module Walrus
159
162
  end
160
163
  log "Processing complete: #{Time.new.to_s}."
161
164
  end
162
-
165
+
163
166
  # Expects an array of Pathname objects.
164
167
  # Directory inputs are themselves recursively expanded if the "recurse" option is set to true; otherwise only their top-level entries are expanded.
165
168
  # Returns an expanded array of Pathname objects.
@@ -182,11 +185,11 @@ module Walrus
182
185
  end
183
186
  expanded
184
187
  end
185
-
188
+
186
189
  def compile_if_needed(input)
187
190
  compile(input, false)
188
191
  end
189
-
192
+
190
193
  def compiled_path_older_than_source_path(compiled_path, source_path)
191
194
  begin
192
195
  compiled = File.mtime(compiled_path)
@@ -196,7 +199,7 @@ module Walrus
196
199
  end
197
200
  compiled < source
198
201
  end
199
-
202
+
200
203
  def compile(input, force = true)
201
204
  template_source_path = template_source_path_for_input(input)
202
205
  compiled_path = compiled_source_path_for_input(input)
@@ -207,20 +210,18 @@ module Walrus
207
210
  handle_error("failed to read input template '#{template_source_path}' (#{e.to_s})")
208
211
  return
209
212
  end
210
-
213
+
211
214
  begin
212
215
  compiled = template.compile
213
216
  rescue Grammar::ParseError => e
214
217
  handle_error("failed to compile input template '#{template_source_path}' (#{e.to_s})")
215
218
  return
216
219
  end
217
-
220
+
218
221
  write_string_to_path(compiled, compiled_path, true)
219
-
220
222
  end
221
-
222
223
  end
223
-
224
+
224
225
  def get_output(input)
225
226
  if @options.dry
226
227
  "(no output: dry run)\n"
@@ -235,20 +236,18 @@ module Walrus
235
236
  threads << Thread.new(stderr) do |err|
236
237
  err.each { |line| STDERR.puts line }
237
238
  end
238
- threads.each { |thread| thread.join }
239
+ threads.each { |thread| thread.join }
239
240
  end
240
241
  status = $?.exitstatus
241
242
  raise SystemCallError.new("non-zero exit status (#{status})") if status != 0
242
243
  output
243
244
  end
244
245
  end
245
-
246
+
246
247
  def write_string_to_path(string, path, executable = false)
247
-
248
248
  if @options.dry
249
249
  log "Would write '#{path}' (dry run)."
250
250
  else
251
-
252
251
  unless path.dirname.exist?
253
252
  begin
254
253
  log "Creating directory '#{path.dirname}'."
@@ -258,7 +257,7 @@ module Walrus
258
257
  return
259
258
  end
260
259
  end
261
-
260
+
262
261
  log "Writing '#{path}'."
263
262
  begin
264
263
  File.open(path, "a+") do |f|
@@ -277,7 +276,7 @@ module Walrus
277
276
  end
278
277
  end
279
278
  end
280
-
279
+
281
280
  def adjusted_output_path(path)
282
281
  if @options.output_dir
283
282
  if path.absolute?
@@ -289,38 +288,36 @@ module Walrus
289
288
  path
290
289
  end
291
290
  end
292
-
291
+
293
292
  # If "input" already has the right extension it is returned unchanged.
294
293
  # If the "input extension" is zero-length then "input" is returned unchanged.
295
294
  # Otherwise the "input extension" is added to "input" and returned.
296
295
  def template_source_path_for_input(input)
297
296
  return input if input.extname == ".#{@options.input_extension}" # input already has the right extension
298
297
  return input if @options.input_extension.length == 0 # zero-length extension, nothing to add
299
- dir, base = input.split
298
+ dir, base = input.split
300
299
  dir + "#{base.to_s}.#{@options.input_extension}" # otherwise, add extension and return
301
300
  end
302
-
301
+
303
302
  def compiled_source_path_for_input(input)
304
-
305
303
  # remove input extension if present
306
304
  if input.extname == ".#{@options.input_extension}" and @options.input_extension.length > 0
307
305
  dir, base = input.split
308
306
  input = dir + base.basename(base.extname)
309
307
  end
310
-
308
+
311
309
  # add rb as an extension
312
310
  dir, base = input.split
313
311
  dir + "#{base.to_s}.rb"
314
312
  end
315
-
313
+
316
314
  def filled_output_path_for_input(input)
317
-
318
315
  # remove input extension if present
319
316
  if input.extname == ".#{@options.input_extension}" and @options.input_extension.length > 0
320
317
  dir, base = input.split
321
318
  input = dir + base.basename(base.extname)
322
319
  end
323
-
320
+
324
321
  # add output extension if appropriate
325
322
  if @options.output_extension.length > 0
326
323
  dir, base = input.split
@@ -328,29 +325,25 @@ module Walrus
328
325
  else
329
326
  adjusted_output_path(input)
330
327
  end
331
-
332
328
  end
333
-
329
+
334
330
  private
335
-
331
+
336
332
  # Writes "message" to standard error if user supplied the "--verbose" switch.
337
333
  def log(message)
338
334
  if @options.verbose
339
335
  $stderr.puts message
340
336
  end
341
337
  end
342
-
343
- # If the user supplied the "--halt" switch raises an Runner::Error exception based on "message". Otherwise merely prints "message" to the standard error.
338
+
339
+ # If the user supplied the "--halt" switch raises an Runner::Error exception based on "message".
340
+ # Otherwise merely prints "message" to the standard error.
344
341
  def handle_error(message)
345
342
  if @options.halt
346
343
  raise Error.new(message)
347
344
  else
348
- $stderr.puts message
345
+ $stderr.puts ":: error: #{message}"
349
346
  end
350
347
  end
351
-
352
-
353
348
  end # class Runner
354
-
355
349
  end # module Walrus
356
-
@@ -1,10 +1,16 @@
1
1
  # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id: /mirrors/Walrus/trunk/walrus/lib/walrus/template.rb 6730 2007-04-11T13:48:51.166868Z wincent $
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus'
10
16
 
@@ -56,8 +62,10 @@ module Walrus
56
62
  if @class_name
57
63
  @class_name
58
64
  else
59
- if @origin.nil? : @class_name = Compiler::DEFAULT_CLASS # "DocumentSubclass"
60
- else @class_name = strip_extensions(@origin).to_class_name
65
+ if @origin.nil?
66
+ @class_name = Compiler::DEFAULT_CLASS # "DocumentSubclass"
67
+ else
68
+ @class_name = strip_extensions(@origin).to_class_name
61
69
  end
62
70
  end
63
71
  end
@@ -0,0 +1,3 @@
1
+ module Walrus
2
+ VERSION = '0.2'
3
+ end # module Walrus
@@ -1,10 +1,16 @@
1
1
  # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id: /mirrors/Walrus/trunk/walrus/lib/walrus/walrus_grammar/assignment_expression.rb 6701 2007-04-09T14:55:55.352472Z wincent $
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
10
16
 
@@ -1,10 +1,16 @@
1
1
  # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id$
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
10
16
 
@@ -1,10 +1,16 @@
1
1
  # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id$
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
10
16
 
@@ -1,10 +1,16 @@
1
- # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
1
+ # Copyright 2007-2009 Wincent Colaiuta
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id: /mirrors/Walrus/trunk/walrus/lib/walrus/walrus_grammar/def_directive.rb 6719 2007-04-10T15:00:33.886928Z wincent $
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
10
16
 
@@ -28,8 +34,10 @@ module Walrus
28
34
 
29
35
  nested = nil
30
36
 
31
- if @content.respond_to? :each : content = @content
32
- else content = [@content]
37
+ if @content.respond_to? :each
38
+ content = @content
39
+ else
40
+ content = [@content]
33
41
  end
34
42
 
35
43
  content.each do |element|
@@ -1,10 +1,16 @@
1
1
  # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id: /mirrors/Walrus/trunk/walrus/lib/walrus/walrus_grammar/echo_directive.rb 6701 2007-04-09T14:55:55.352472Z wincent $
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
10
16
 
@@ -1,10 +1,16 @@
1
1
  # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id$
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
10
16
 
@@ -1,10 +1,16 @@
1
1
  # Copyright 2007 Wincent Colaiuta
2
- # This program is distributed in the hope that it will be useful, but WITHOUT
3
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5
- # in the accompanying file, "LICENSE.txt", for more details.
2
+ # This program is free software: you can redistribute it and/or modify
3
+ # it under the terms of the GNU General Public License as published by
4
+ # the Free Software Foundation, either version 3 of the License, or
5
+ # (at your option) any later version.
6
6
  #
7
- # $Id$
7
+ # This program is distributed in the hope that it will be useful,
8
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ # GNU General Public License for more details.
11
+ #
12
+ # You should have received a copy of the GNU General Public License
13
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
8
14
 
9
15
  require 'walrus/parser.rb' # make sure that the class has been defined prior to extending it
10
16
  require 'ostruct'