walrus 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/bin/walrus +19 -12
  2. data/lib/walrus.rb +27 -70
  3. data/lib/walrus/additions/string.rb +21 -35
  4. data/lib/walrus/compile_error.rb +19 -16
  5. data/lib/walrus/compiler.rb +66 -55
  6. data/lib/walrus/contrib/spec/walruscloth_spec.rb +21 -17
  7. data/lib/walrus/contrib/walruscloth.rb +19 -11
  8. data/lib/walrus/document.rb +41 -33
  9. data/lib/walrus/grammar.rb +474 -162
  10. data/lib/walrus/grammar/assignment_expression.rb +33 -0
  11. data/lib/walrus/grammar/block_directive.rb +37 -0
  12. data/lib/walrus/grammar/comment.rb +33 -0
  13. data/lib/walrus/grammar/def_directive.rb +80 -0
  14. data/lib/walrus/grammar/echo_directive.rb +56 -0
  15. data/lib/walrus/grammar/escape_sequence.rb +33 -0
  16. data/lib/walrus/grammar/import_directive.rb +54 -0
  17. data/lib/walrus/grammar/include_directive.rb +36 -0
  18. data/lib/walrus/grammar/instance_variable.rb +33 -0
  19. data/lib/walrus/grammar/literal.rb +33 -0
  20. data/lib/walrus/grammar/message_expression.rb +34 -0
  21. data/lib/walrus/grammar/multiline_comment.rb +70 -0
  22. data/lib/walrus/grammar/placeholder.rb +47 -0
  23. data/lib/walrus/grammar/raw_directive.rb +50 -0
  24. data/lib/walrus/grammar/raw_text.rb +56 -0
  25. data/lib/walrus/grammar/ruby_directive.rb +41 -0
  26. data/lib/walrus/grammar/ruby_expression.rb +42 -0
  27. data/lib/walrus/grammar/set_directive.rb +34 -0
  28. data/lib/walrus/grammar/silent_directive.rb +51 -0
  29. data/lib/walrus/grammar/slurp_directive.rb +36 -0
  30. data/lib/walrus/grammar/super_directive.rb +34 -0
  31. data/lib/walrus/parser.rb +26 -408
  32. data/lib/walrus/runner.rb +37 -20
  33. data/lib/walrus/template.rb +34 -25
  34. data/lib/walrus/version.rb +24 -1
  35. metadata +57 -71
  36. data/ext/extconf.rb +0 -16
  37. data/ext/jindex.c +0 -92
  38. data/lib/walrus/diff.rb +0 -95
  39. data/lib/walrus/grammar/additions/proc.rb +0 -26
  40. data/lib/walrus/grammar/additions/regexp.rb +0 -27
  41. data/lib/walrus/grammar/additions/string.rb +0 -58
  42. data/lib/walrus/grammar/additions/symbol.rb +0 -49
  43. data/lib/walrus/grammar/and_predicate.rb +0 -46
  44. data/lib/walrus/grammar/array_result.rb +0 -25
  45. data/lib/walrus/grammar/continuation_wrapper_exception.rb +0 -34
  46. data/lib/walrus/grammar/left_recursion_exception.rb +0 -33
  47. data/lib/walrus/grammar/location_tracking.rb +0 -115
  48. data/lib/walrus/grammar/match_data_wrapper.rb +0 -71
  49. data/lib/walrus/grammar/memoizing.rb +0 -47
  50. data/lib/walrus/grammar/memoizing_cache.rb +0 -103
  51. data/lib/walrus/grammar/node.rb +0 -66
  52. data/lib/walrus/grammar/not_predicate.rb +0 -46
  53. data/lib/walrus/grammar/parse_error.rb +0 -45
  54. data/lib/walrus/grammar/parser_state.rb +0 -187
  55. data/lib/walrus/grammar/parslet.rb +0 -34
  56. data/lib/walrus/grammar/parslet_choice.rb +0 -128
  57. data/lib/walrus/grammar/parslet_combination.rb +0 -32
  58. data/lib/walrus/grammar/parslet_combining.rb +0 -160
  59. data/lib/walrus/grammar/parslet_merge.rb +0 -94
  60. data/lib/walrus/grammar/parslet_omission.rb +0 -63
  61. data/lib/walrus/grammar/parslet_repetition.rb +0 -106
  62. data/lib/walrus/grammar/parslet_repetition_default.rb +0 -64
  63. data/lib/walrus/grammar/parslet_sequence.rb +0 -214
  64. data/lib/walrus/grammar/predicate.rb +0 -63
  65. data/lib/walrus/grammar/proc_parslet.rb +0 -58
  66. data/lib/walrus/grammar/regexp_parslet.rb +0 -79
  67. data/lib/walrus/grammar/skipped_substring_exception.rb +0 -42
  68. data/lib/walrus/grammar/string_enumerator.rb +0 -53
  69. data/lib/walrus/grammar/string_parslet.rb +0 -81
  70. data/lib/walrus/grammar/string_result.rb +0 -30
  71. data/lib/walrus/grammar/symbol_parslet.rb +0 -69
  72. data/lib/walrus/no_parameter_marker.rb +0 -25
  73. data/lib/walrus/walrus_grammar/assignment_expression.rb +0 -30
  74. data/lib/walrus/walrus_grammar/block_directive.rb +0 -34
  75. data/lib/walrus/walrus_grammar/comment.rb +0 -30
  76. data/lib/walrus/walrus_grammar/def_directive.rb +0 -72
  77. data/lib/walrus/walrus_grammar/echo_directive.rb +0 -50
  78. data/lib/walrus/walrus_grammar/escape_sequence.rb +0 -30
  79. data/lib/walrus/walrus_grammar/import_directive.rb +0 -50
  80. data/lib/walrus/walrus_grammar/include_directive.rb +0 -33
  81. data/lib/walrus/walrus_grammar/instance_variable.rb +0 -30
  82. data/lib/walrus/walrus_grammar/literal.rb +0 -30
  83. data/lib/walrus/walrus_grammar/message_expression.rb +0 -31
  84. data/lib/walrus/walrus_grammar/multiline_comment.rb +0 -60
  85. data/lib/walrus/walrus_grammar/placeholder.rb +0 -46
  86. data/lib/walrus/walrus_grammar/raw_directive.rb +0 -48
  87. data/lib/walrus/walrus_grammar/raw_text.rb +0 -51
  88. data/lib/walrus/walrus_grammar/ruby_directive.rb +0 -35
  89. data/lib/walrus/walrus_grammar/ruby_expression.rb +0 -37
  90. data/lib/walrus/walrus_grammar/set_directive.rb +0 -30
  91. data/lib/walrus/walrus_grammar/silent_directive.rb +0 -50
  92. data/lib/walrus/walrus_grammar/slurp_directive.rb +0 -31
  93. data/lib/walrus/walrus_grammar/super_directive.rb +0 -33
@@ -1,25 +0,0 @@
1
- # Copyright 2007 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
- #
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/>.
14
-
15
- require 'walrus'
16
-
17
- module Walrus
18
-
19
- class NoParameterMarker
20
- require 'singleton'
21
- include Singleton
22
- end
23
-
24
- end # module Walrus
25
-
@@ -1,30 +0,0 @@
1
- # Copyright 2007 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
- #
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/>.
14
-
15
- require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
16
-
17
- module Walrus
18
- class WalrusGrammar
19
-
20
- class AssignmentExpression
21
-
22
- def compile(options = {})
23
- @lvalue.source_text + '=' + @expression.source_text
24
- end
25
-
26
- end # class AssignmentExpression
27
-
28
- end # class WalrusGrammar
29
- end # Walrus
30
-
@@ -1,34 +0,0 @@
1
- # Copyright 2007 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
- #
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/>.
14
-
15
- require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
16
-
17
- module Walrus
18
- class WalrusGrammar
19
-
20
- class BlockDirective
21
-
22
- # Returns a string containing the compiled (Ruby) version of receiver.
23
- def compile(options = {})
24
- inner, outer = super
25
- inner = '' if inner.nil?
26
- inner << "lookup_and_accumulate_placeholder(#{@identifier.to_s.to_sym.inspect})\n"
27
- [inner, outer]
28
- end
29
-
30
- end # class BlockDirective
31
-
32
- end # class WalrusGrammar
33
- end # Walrus
34
-
@@ -1,30 +0,0 @@
1
- # Copyright 2007 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
- #
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/>.
14
-
15
- require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
16
-
17
- module Walrus
18
- class WalrusGrammar
19
-
20
- class Comment
21
-
22
- def compile(options = {})
23
- '# Comment:' + @lexeme.to_s + "\n"
24
- end
25
-
26
- end
27
-
28
- end # class WalrusGrammar
29
- end # Walrus
30
-
@@ -1,72 +0,0 @@
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
- #
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/>.
14
-
15
- require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
16
-
17
- module Walrus
18
- class WalrusGrammar
19
-
20
- class DefDirective
21
-
22
- # Returns a string containing the compiled (Ruby) version of receiver.
23
- def compile(options = {})
24
- internal = ''
25
-
26
- if @params == []
27
- external = "def #{@identifier.to_s}\n"
28
- else
29
- # this will work for the simple case where params are plain identifiers
30
- params = (@params.kind_of? Array) ? @params : [@params]
31
- param_list = params.collect { |param| param.compile }.join(', ')
32
- external = "def #{@identifier.to_s}(#{param_list})\n"
33
- end
34
-
35
- nested = nil
36
-
37
- if @content.respond_to? :each
38
- content = @content
39
- else
40
- content = [@content]
41
- end
42
-
43
- content.each do |element|
44
- if element.kind_of? WalrusGrammar::DefDirective # must handle nested def blocks here
45
- inner, outer = element.compile(options)
46
- nested = ['', ''] if nested.nil?
47
- external << inner if inner
48
- nested[1] << "\n" + outer
49
- else
50
- # again, may wish to forget the per-line indenting here if it breaks sensitive directive types
51
- # (#ruby blocks for example, which might have here documents)
52
- element.compile(options).each do |lines| # may return a single line or an array of lines
53
- lines.each { |line| external << ' ' + line }
54
- end
55
- end
56
- end
57
-
58
- external << "end\n\n"
59
-
60
- if nested
61
- external << nested[1]
62
- end
63
-
64
- internal = nil if internal == '' # better to return nil than an empty string here (which would get indented needlessly)
65
- [internal, external]
66
- end
67
-
68
- end # class DefDirective
69
-
70
- end # class WalrusGrammar
71
- end # Walrus
72
-
@@ -1,50 +0,0 @@
1
- # Copyright 2007 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
- #
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/>.
14
-
15
- require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
16
-
17
- module Walrus
18
- class WalrusGrammar
19
-
20
- class EchoDirective
21
-
22
- def compile(options = {})
23
-
24
- if @expression.respond_to? :each
25
- expression = @expression
26
- else
27
- expression = [@expression]
28
- end
29
-
30
- # TODO: potentially include line, col and file name info in the comments generated by the compiler
31
-
32
- compiled = ''
33
- first = true
34
- expression.each do |expr|
35
- if first
36
- compiled << "accumulate(instance_eval { %s }) # Echo directive\n" % expr.compile
37
- first = false
38
- else
39
- compiled << "accumulate(instance_eval { %s }) # Echo directive (continued)\n" % expr.compile
40
- end
41
- end
42
- compiled
43
-
44
- end
45
-
46
- end # class EchoDirective
47
-
48
- end # class WalrusGrammar
49
- end # Walrus
50
-
@@ -1,30 +0,0 @@
1
- # Copyright 2007 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
- #
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/>.
14
-
15
- require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
16
-
17
- module Walrus
18
- class WalrusGrammar
19
-
20
- class EscapeSequence
21
-
22
- def compile(options = {})
23
- "accumulate(%s) \# EscapeSequence\n" % @lexeme.to_s.dump
24
- end
25
-
26
- end
27
-
28
- end # class WalrusGrammar
29
- end # Walrus
30
-
@@ -1,50 +0,0 @@
1
- # Copyright 2007 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
- #
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/>.
14
-
15
- require 'walrus/parser.rb' # make sure that the class has been defined prior to extending it
16
- require 'ostruct'
17
-
18
- module Walrus
19
- class WalrusGrammar
20
-
21
- class ImportDirective
22
-
23
- # Returns an OpenStruct encapsulating information about the receiver for use by the compiler
24
- def compile(options = {})
25
- info = OpenStruct.new
26
- path = Pathname.new @class_name.lexeme.to_s
27
-
28
- if path.absolute?
29
- # it will work just fine as it is
30
- info.class_name = path.basename.to_s.to_class_name
31
- info.require_line = "require '#{path.to_s}'"
32
- else
33
- dir, base = path.split
34
- info.class_name = base.to_s.to_class_name
35
- if dir.to_s == '.'
36
- # desired template is in the same directory
37
- info.require_line = "require File.join(File.dirname(__FILE__), '#{base.to_s}').to_s"
38
- else
39
- # desired template is in a relative directory
40
- info.require_line = "require File.join(File.dirname(__FILE__), '#{dir.to_s}', '#{base.to_s}').to_s"
41
- end
42
- end
43
- info
44
- end
45
-
46
- end # class ImportDirective
47
-
48
- end # class WalrusGrammar
49
- end # Walrus
50
-
@@ -1,33 +0,0 @@
1
- # Copyright 2007 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
- #
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/>.
14
-
15
- require 'walrus/parser.rb' # make sure that the class has been defined prior to extending it
16
-
17
- module Walrus
18
- class WalrusGrammar
19
-
20
- class IncludeDirective
21
-
22
- def compile(options = {})
23
- inner, outer = options[:compiler_instance].compile_subtree(subtree)
24
- inner = [] if inner.nil?
25
- inner.unshift "\# Include (start): #{file_name.to_s}:\n"
26
- [inner, outer]
27
- end
28
-
29
- end # class IncludeDirective
30
-
31
- end # class WalrusGrammar
32
- end # Walrus
33
-
@@ -1,30 +0,0 @@
1
- # Copyright 2007 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
- #
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/>.
14
-
15
- require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
16
-
17
- module Walrus
18
- class WalrusGrammar
19
-
20
- class InstanceVariable
21
-
22
- def compile(options = {})
23
- @lexeme.source_text
24
- end
25
-
26
- end # class InstanceVariable
27
-
28
- end # class WalrusGrammar
29
- end # Walrus
30
-
@@ -1,30 +0,0 @@
1
- # Copyright 2007 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
- #
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/>.
14
-
15
- require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
16
-
17
- module Walrus
18
- class WalrusGrammar
19
-
20
- class Literal
21
-
22
- def compile(options = {})
23
- @lexeme.source_text
24
- end
25
-
26
- end # class Literal
27
-
28
- end # class WalrusGrammar
29
- end # Walrus
30
-
@@ -1,31 +0,0 @@
1
- # Copyright 2007 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
- #
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/>.
14
-
15
- require 'walrus/parser.rb' # make sure that RawText class has been defined prior to extending it
16
-
17
- module Walrus
18
- class WalrusGrammar
19
-
20
- class MessageExpression
21
-
22
- def compile(options = {})
23
- # simple case
24
- @target.source_text + '.' + @message.source_text
25
- end
26
-
27
- end # class AssignmentExpression
28
-
29
- end # class WalrusGrammar
30
- end # Walrus
31
-