mail 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mail might be problematic. Click here for more details.
- data/Rakefile +1 -1
- data/lib/mail.rb +2 -1
- data/lib/mail/version.rb +1 -1
- data/lib/vendor/treetop-1.4.3/History.txt +18 -0
- data/lib/vendor/treetop-1.4.3/LICENSE +19 -0
- data/lib/vendor/treetop-1.4.3/README.md +164 -0
- data/lib/vendor/treetop-1.4.3/Rakefile +23 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet +20 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Snippets/rule ___ end.tmSnippet +18 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib +1524 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib +0 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/syntax_tree_viewer.rb +117 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage +251 -0
- data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/info.plist +10 -0
- data/lib/vendor/treetop-1.4.3/benchmark/seqpar.gnuplot +15 -0
- data/lib/vendor/treetop-1.4.3/benchmark/seqpar.treetop +16 -0
- data/lib/vendor/treetop-1.4.3/benchmark/seqpar_benchmark.rb +107 -0
- data/lib/vendor/treetop-1.4.3/bin/tt +112 -0
- data/lib/vendor/treetop-1.4.3/doc/contributing_and_planned_features.markdown +103 -0
- data/lib/vendor/treetop-1.4.3/doc/grammar_composition.markdown +65 -0
- data/lib/vendor/treetop-1.4.3/doc/index.markdown +90 -0
- data/lib/vendor/treetop-1.4.3/doc/pitfalls_and_advanced_techniques.markdown +51 -0
- data/lib/vendor/treetop-1.4.3/doc/semantic_interpretation.markdown +189 -0
- data/lib/vendor/treetop-1.4.3/doc/site.rb +112 -0
- data/lib/vendor/treetop-1.4.3/doc/sitegen.rb +65 -0
- data/lib/vendor/treetop-1.4.3/doc/syntactic_recognition.markdown +100 -0
- data/lib/vendor/treetop-1.4.3/doc/using_in_ruby.markdown +21 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic.rb +551 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic.treetop +97 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_node_classes.rb +7 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/arithmetic_test.rb +54 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus +0 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus.rb +718 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus.treetop +132 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus_node_classes.rb +5 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/lambda_calculus_test.rb +89 -0
- data/lib/vendor/treetop-1.4.3/examples/lambda_calculus/test_helper.rb +18 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop.rb +17 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/bootstrap_gen_1_metagrammar.rb +45 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler.rb +6 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/grammar_compiler.rb +44 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/lexical_address_space.rb +17 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/metagrammar.rb +3366 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/metagrammar.treetop +436 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes.rb +20 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/anything_symbol.rb +18 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/atomic_expression.rb +14 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/character_class.rb +28 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/choice.rb +31 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/declaration_sequence.rb +24 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/grammar.rb +28 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/inline_module.rb +27 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/nonterminal.rb +13 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/optional.rb +19 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parenthesized_expression.rb +9 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parsing_expression.rb +146 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/parsing_rule.rb +58 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/predicate.rb +45 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/predicate_block.rb +16 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/repetition.rb +55 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/sequence.rb +71 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/terminal.rb +20 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/transient_prefix.rb +9 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/node_classes/treetop_file.rb +9 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/compiler/ruby_builder.rb +113 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/ruby_extensions.rb +2 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/ruby_extensions/string.rb +42 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime.rb +5 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/compiled_parser.rb +110 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list.rb +4 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/head_node.rb +15 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +200 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/interval_skip_list/node.rb +164 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/syntax_node.rb +114 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/terminal_parse_failure.rb +16 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/runtime/terminal_syntax_node.rb +17 -0
- data/lib/vendor/treetop-1.4.3/lib/treetop/version.rb +9 -0
- data/lib/vendor/treetop-1.4.3/script/generate_metagrammar.rb +14 -0
- data/lib/vendor/treetop-1.4.3/script/svnadd +11 -0
- data/lib/vendor/treetop-1.4.3/script/svnrm +11 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/and_predicate_spec.rb +36 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/anything_symbol_spec.rb +44 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/character_class_spec.rb +276 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/choice_spec.rb +80 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/circular_compilation_spec.rb +28 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/failure_propagation_functional_spec.rb +21 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/grammar_compiler_spec.rb +84 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/grammar_spec.rb +41 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/multibyte_chars_spec.rb +46 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/nonterminal_symbol_spec.rb +40 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/not_predicate_spec.rb +38 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/one_or_more_spec.rb +35 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/optional_spec.rb +37 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/parenthesized_expression_spec.rb +19 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/parsing_rule_spec.rb +61 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/repeated_subrule_spec.rb +29 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/semantic_predicate_spec.rb +175 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/sequence_spec.rb +115 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/terminal_spec.rb +81 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/terminal_symbol_spec.rb +37 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar.treetop +7 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar.tt +7 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/test_grammar_do.treetop +7 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/tt_compiler_spec.rb +216 -0
- data/lib/vendor/treetop-1.4.3/spec/compiler/zero_or_more_spec.rb +56 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/a.treetop +11 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/b.treetop +11 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/c.treetop +10 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/d.treetop +10 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/f.treetop +17 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/grammar_composition_spec.rb +40 -0
- data/lib/vendor/treetop-1.4.3/spec/composition/subfolder/e_includes_c.treetop +15 -0
- data/lib/vendor/treetop-1.4.3/spec/ruby_extensions/string_spec.rb +32 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/compiled_parser_spec.rb +101 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/delete_spec.rb +147 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/expire_range_spec.rb +349 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/insert_and_delete_node.rb +385 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/insert_spec.rb +660 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +6175 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +58 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/palindromic_fixture.rb +23 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +164 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/interval_skip_list/spec_helper.rb +84 -0
- data/lib/vendor/treetop-1.4.3/spec/runtime/syntax_node_spec.rb +77 -0
- data/lib/vendor/treetop-1.4.3/spec/spec_helper.rb +110 -0
- data/lib/vendor/treetop-1.4.3/spec/spec_suite.rb +4 -0
- data/lib/vendor/treetop-1.4.3/treetop.gemspec +18 -0
- data/lib/vendor/treetop.rb +5 -0
- metadata +126 -11
data/lib/vendor/treetop-1.4.3/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib
ADDED
Binary file
|
@@ -0,0 +1,117 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'treetop'
|
4
|
+
require "#{ENV["TM_SUPPORT_PATH"]}/lib/ui"
|
5
|
+
|
6
|
+
# Monkey-patch SyntaxNode in a gross violation of its privacy.
|
7
|
+
module Treetop
|
8
|
+
module Runtime
|
9
|
+
class SyntaxNode
|
10
|
+
def interesting_methods
|
11
|
+
# Copied from SyntaxNode#inspect
|
12
|
+
methods-[extension_modules.last ? extension_modules.last.methods : nil]-self.class.instance_methods
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_hash
|
16
|
+
{
|
17
|
+
"class_and_modules" => self.class.to_s.sub(/.*:/,'') + extension_modules.map{|m| "+"+m.to_s.sub(/.*:/,'')}*"",
|
18
|
+
"offset" => interval.first,
|
19
|
+
"text_value" => text_value,
|
20
|
+
"methods" => interesting_methods * ", ",
|
21
|
+
"elements" => elements ? elements.map {|e| e.to_hash} : []
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class SyntaxTreeViewer
|
29
|
+
def self.nib_path
|
30
|
+
File.dirname(__FILE__) + "/SyntaxTreeViewer.nib"
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.new_with_unknown_grammar
|
34
|
+
parser = if ENV['TM_SCOPE'] =~ /source\.ruby/ && ENV['TM_SELECTED_TEXT']
|
35
|
+
eval(ENV['TM_SELECTED_TEXT'])
|
36
|
+
else
|
37
|
+
parser_file = if ENV['TM_SCOPE'] =~ /source\.treetop/
|
38
|
+
ENV['TM_FILEPATH']
|
39
|
+
else
|
40
|
+
ask_for_grammar
|
41
|
+
end
|
42
|
+
return unless parser_file
|
43
|
+
Treetop.load(parser_file)
|
44
|
+
end
|
45
|
+
new(parser.new)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.ask_for_grammar
|
49
|
+
files = TextMate::UI.request_file("title" => "Select a Grammar File")
|
50
|
+
if files.nil? || files.empty?
|
51
|
+
nil
|
52
|
+
else
|
53
|
+
files[0]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.nib_path
|
58
|
+
File.dirname(__FILE__) + "/nibs/SyntaxTreeViewer.nib"
|
59
|
+
end
|
60
|
+
|
61
|
+
def initialize(_parser)
|
62
|
+
@parser = _parser
|
63
|
+
run_parser!
|
64
|
+
end
|
65
|
+
|
66
|
+
def dialog
|
67
|
+
TextMate::UI.dialog(
|
68
|
+
:nib => self.class.nib_path,
|
69
|
+
:parameters => parameters
|
70
|
+
) do |d|
|
71
|
+
d.wait_for_input do |params|
|
72
|
+
if params["returnArgument"]
|
73
|
+
self.input = params["returnArgument"]
|
74
|
+
run_parser!
|
75
|
+
d.parameters = parameters
|
76
|
+
true
|
77
|
+
else
|
78
|
+
false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def input
|
85
|
+
ENV['TM_TREETOP_SYNTAX_VIEWER_INPUT'] ||= ""
|
86
|
+
end
|
87
|
+
|
88
|
+
def input=(new_input)
|
89
|
+
ENV['TM_TREETOP_SYNTAX_VIEWER_INPUT'] = new_input
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def run_parser!
|
94
|
+
if input && !input.empty?
|
95
|
+
@syntax_tree = @parser.parse(input)
|
96
|
+
TextMate::UI.alert(:warning, "Parse error", @parser.failure_reason) unless @syntax_tree
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def parameters
|
101
|
+
p = {
|
102
|
+
"input" => input,
|
103
|
+
"syntax_tree" => @syntax_tree ? @syntax_tree.to_hash : {},
|
104
|
+
"selected_tab" => !input.empty? && @syntax_tree ? "Syntax Tree" : "Input"
|
105
|
+
}
|
106
|
+
puts p
|
107
|
+
p
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
if __FILE__ == $0
|
112
|
+
Dir.chdir("/Users/aobrien/Work/canopy/play/sparql/")
|
113
|
+
require "/Users/aobrien/Work/canopy/play/sparql/lib/sparql"
|
114
|
+
v = SyntaxTreeViewer.new(SparqlParser.new)
|
115
|
+
v.input = %{PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?foo WHERE { ?x foaf:knows ?y . ?z foaf:knows ?x .}}
|
116
|
+
v.dialog
|
117
|
+
end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>fileTypes</key>
|
6
|
+
<array>
|
7
|
+
<string>treetop</string>
|
8
|
+
</array>
|
9
|
+
<key>foldingStartMarker</key>
|
10
|
+
<string>(grammer|rule).*$</string>
|
11
|
+
<key>foldingStopMarker</key>
|
12
|
+
<string>^\s*end</string>
|
13
|
+
<key>keyEquivalent</key>
|
14
|
+
<string>^~T</string>
|
15
|
+
<key>name</key>
|
16
|
+
<string>Treetop Grammar</string>
|
17
|
+
<key>patterns</key>
|
18
|
+
<array>
|
19
|
+
<dict>
|
20
|
+
<key>begin</key>
|
21
|
+
<string>^(grammar) ([A-Z]\w+)</string>
|
22
|
+
<key>beginCaptures</key>
|
23
|
+
<dict>
|
24
|
+
<key>1</key>
|
25
|
+
<dict>
|
26
|
+
<key>name</key>
|
27
|
+
<string>keyword.begin.grammar.treetop</string>
|
28
|
+
</dict>
|
29
|
+
<key>2</key>
|
30
|
+
<dict>
|
31
|
+
<key>name</key>
|
32
|
+
<string>entity.name.grammar.treetop</string>
|
33
|
+
</dict>
|
34
|
+
</dict>
|
35
|
+
<key>end</key>
|
36
|
+
<string>^end$</string>
|
37
|
+
<key>endCaptures</key>
|
38
|
+
<dict>
|
39
|
+
<key>0</key>
|
40
|
+
<dict>
|
41
|
+
<key>name</key>
|
42
|
+
<string>keyword.end.grammar.treetop</string>
|
43
|
+
</dict>
|
44
|
+
</dict>
|
45
|
+
<key>name</key>
|
46
|
+
<string>meta.grammar.treetop</string>
|
47
|
+
<key>patterns</key>
|
48
|
+
<array>
|
49
|
+
<dict>
|
50
|
+
<key>begin</key>
|
51
|
+
<string>\b(rule)\b (.+)$</string>
|
52
|
+
<key>beginCaptures</key>
|
53
|
+
<dict>
|
54
|
+
<key>1</key>
|
55
|
+
<dict>
|
56
|
+
<key>name</key>
|
57
|
+
<string>keyword.begin.rule.treetop</string>
|
58
|
+
</dict>
|
59
|
+
<key>2</key>
|
60
|
+
<dict>
|
61
|
+
<key>name</key>
|
62
|
+
<string>entity.name.rule.treetop</string>
|
63
|
+
</dict>
|
64
|
+
</dict>
|
65
|
+
<key>end</key>
|
66
|
+
<string>^\s+\bend\b\s*$</string>
|
67
|
+
<key>endCaptures</key>
|
68
|
+
<dict>
|
69
|
+
<key>0</key>
|
70
|
+
<dict>
|
71
|
+
<key>name</key>
|
72
|
+
<string>keyword.end.rule.treetop</string>
|
73
|
+
</dict>
|
74
|
+
</dict>
|
75
|
+
<key>name</key>
|
76
|
+
<string>meta.rule.treetop</string>
|
77
|
+
<key>patterns</key>
|
78
|
+
<array>
|
79
|
+
<dict>
|
80
|
+
<key>include</key>
|
81
|
+
<string>#strings</string>
|
82
|
+
</dict>
|
83
|
+
<dict>
|
84
|
+
<key>include</key>
|
85
|
+
<string>#character-class</string>
|
86
|
+
</dict>
|
87
|
+
<dict>
|
88
|
+
<key>match</key>
|
89
|
+
<string>\/</string>
|
90
|
+
<key>name</key>
|
91
|
+
<string>keyword.operator.or.treetop</string>
|
92
|
+
</dict>
|
93
|
+
<dict>
|
94
|
+
<key>match</key>
|
95
|
+
<string><\w+?></string>
|
96
|
+
<key>name</key>
|
97
|
+
<string>variable.class-instance.treetop</string>
|
98
|
+
</dict>
|
99
|
+
<dict>
|
100
|
+
<key>match</key>
|
101
|
+
<string>\w+?:</string>
|
102
|
+
<key>name</key>
|
103
|
+
<string>support.operand.treetop</string>
|
104
|
+
</dict>
|
105
|
+
<dict>
|
106
|
+
<key>begin</key>
|
107
|
+
<string>\{</string>
|
108
|
+
<key>end</key>
|
109
|
+
<string>\}</string>
|
110
|
+
<key>name</key>
|
111
|
+
<string>meta.embedded-ruby.treetop</string>
|
112
|
+
<key>patterns</key>
|
113
|
+
<array>
|
114
|
+
<dict>
|
115
|
+
<key>include</key>
|
116
|
+
<string>source.ruby</string>
|
117
|
+
</dict>
|
118
|
+
</array>
|
119
|
+
</dict>
|
120
|
+
</array>
|
121
|
+
</dict>
|
122
|
+
</array>
|
123
|
+
</dict>
|
124
|
+
</array>
|
125
|
+
<key>repository</key>
|
126
|
+
<dict>
|
127
|
+
<key>character-class</key>
|
128
|
+
<dict>
|
129
|
+
<key>patterns</key>
|
130
|
+
<array>
|
131
|
+
<dict>
|
132
|
+
<key>match</key>
|
133
|
+
<string>\\[wWsSdDhH]|\.</string>
|
134
|
+
<key>name</key>
|
135
|
+
<string>constant.character.character-class.regexp</string>
|
136
|
+
</dict>
|
137
|
+
<dict>
|
138
|
+
<key>match</key>
|
139
|
+
<string>\\.</string>
|
140
|
+
<key>name</key>
|
141
|
+
<string>constant.character.escape.backslash.regexp</string>
|
142
|
+
</dict>
|
143
|
+
<dict>
|
144
|
+
<key>begin</key>
|
145
|
+
<string>(\[)(\^)?</string>
|
146
|
+
<key>beginCaptures</key>
|
147
|
+
<dict>
|
148
|
+
<key>1</key>
|
149
|
+
<dict>
|
150
|
+
<key>name</key>
|
151
|
+
<string>punctuation.definition.character-class.regexp</string>
|
152
|
+
</dict>
|
153
|
+
<key>2</key>
|
154
|
+
<dict>
|
155
|
+
<key>name</key>
|
156
|
+
<string>keyword.operator.negation.regexp</string>
|
157
|
+
</dict>
|
158
|
+
</dict>
|
159
|
+
<key>end</key>
|
160
|
+
<string>(\])</string>
|
161
|
+
<key>endCaptures</key>
|
162
|
+
<dict>
|
163
|
+
<key>1</key>
|
164
|
+
<dict>
|
165
|
+
<key>name</key>
|
166
|
+
<string>punctuation.definition.character-class.regexp</string>
|
167
|
+
</dict>
|
168
|
+
</dict>
|
169
|
+
<key>name</key>
|
170
|
+
<string>constant.other.character-class.set.regexp</string>
|
171
|
+
<key>patterns</key>
|
172
|
+
<array>
|
173
|
+
<dict>
|
174
|
+
<key>include</key>
|
175
|
+
<string>#character-class</string>
|
176
|
+
</dict>
|
177
|
+
<dict>
|
178
|
+
<key>captures</key>
|
179
|
+
<dict>
|
180
|
+
<key>2</key>
|
181
|
+
<dict>
|
182
|
+
<key>name</key>
|
183
|
+
<string>constant.character.escape.backslash.regexp</string>
|
184
|
+
</dict>
|
185
|
+
<key>4</key>
|
186
|
+
<dict>
|
187
|
+
<key>name</key>
|
188
|
+
<string>constant.character.escape.backslash.regexp</string>
|
189
|
+
</dict>
|
190
|
+
</dict>
|
191
|
+
<key>match</key>
|
192
|
+
<string>(.|(\\.))\-([^\]]|(\\.))</string>
|
193
|
+
<key>name</key>
|
194
|
+
<string>constant.other.character-class.range.regexp</string>
|
195
|
+
</dict>
|
196
|
+
<dict>
|
197
|
+
<key>match</key>
|
198
|
+
<string>&&</string>
|
199
|
+
<key>name</key>
|
200
|
+
<string>keyword.operator.intersection.regexp</string>
|
201
|
+
</dict>
|
202
|
+
</array>
|
203
|
+
</dict>
|
204
|
+
</array>
|
205
|
+
</dict>
|
206
|
+
<key>strings</key>
|
207
|
+
<dict>
|
208
|
+
<key>patterns</key>
|
209
|
+
<array>
|
210
|
+
<dict>
|
211
|
+
<key>begin</key>
|
212
|
+
<string>'</string>
|
213
|
+
<key>beginCaptures</key>
|
214
|
+
<dict>
|
215
|
+
<key>0</key>
|
216
|
+
<dict>
|
217
|
+
<key>name</key>
|
218
|
+
<string>punctuation.definition.string.begin.treetop</string>
|
219
|
+
</dict>
|
220
|
+
</dict>
|
221
|
+
<key>end</key>
|
222
|
+
<string>'</string>
|
223
|
+
<key>endCaptures</key>
|
224
|
+
<dict>
|
225
|
+
<key>0</key>
|
226
|
+
<dict>
|
227
|
+
<key>name</key>
|
228
|
+
<string>punctuation.definition.string.end.treetop</string>
|
229
|
+
</dict>
|
230
|
+
</dict>
|
231
|
+
<key>name</key>
|
232
|
+
<string>string.quoted.single.treetop</string>
|
233
|
+
<key>patterns</key>
|
234
|
+
<array>
|
235
|
+
<dict>
|
236
|
+
<key>match</key>
|
237
|
+
<string>\\(u\h{4}|.)</string>
|
238
|
+
<key>name</key>
|
239
|
+
<string>constant.character.escape.antlr</string>
|
240
|
+
</dict>
|
241
|
+
</array>
|
242
|
+
</dict>
|
243
|
+
</array>
|
244
|
+
</dict>
|
245
|
+
</dict>
|
246
|
+
<key>scopeName</key>
|
247
|
+
<string>source.treetop</string>
|
248
|
+
<key>uuid</key>
|
249
|
+
<string>A1604A34-0B73-4D5A-9499-87D881DFA8D5</string>
|
250
|
+
</dict>
|
251
|
+
</plist>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>name</key>
|
6
|
+
<string>Treetop</string>
|
7
|
+
<key>uuid</key>
|
8
|
+
<string>83A8B700-143D-4BD6-B4EA-D73796E8F883</string>
|
9
|
+
</dict>
|
10
|
+
</plist>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
f1(x) = a*x
|
2
|
+
a = 0.5
|
3
|
+
fit f1(x) 'before.dat' using 1:2 via a
|
4
|
+
|
5
|
+
f2(x) = b*x
|
6
|
+
b = 0.5
|
7
|
+
fit f2(x) 'after.dat' using 1:2 via b
|
8
|
+
|
9
|
+
set xlabel "Length of input"
|
10
|
+
set ylabel "CPU time to parse"
|
11
|
+
|
12
|
+
plot a*x title 'a*x (Before)',\
|
13
|
+
b*x title 'b*x (After)',\
|
14
|
+
"before.dat" using 1:2 title 'Before', \
|
15
|
+
"after.dat" using 1:2 title 'After'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
grammar SeqPar
|
2
|
+
|
3
|
+
rule statement
|
4
|
+
'par ' (statement ' ')+ 'end'
|
5
|
+
/ 'sequence' ' ' (statement ' ')+ 'end'
|
6
|
+
/ 'seq' ' ' (statement ' ')+ 'end'
|
7
|
+
/ ('fit' [\s] (statement ' ')+ 'end') {
|
8
|
+
def foo
|
9
|
+
"foo"
|
10
|
+
end
|
11
|
+
}
|
12
|
+
/ 'art'+ [ ] (statement ' ')+ 'end'
|
13
|
+
/ [A-Z] [a-zA-z0-9]*
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# Benchmarking written by Bernard Lambeau, improved by Jason Garber
|
2
|
+
#
|
3
|
+
# To test your optimizations:
|
4
|
+
# 1. Run ruby seqpar_benchmark.rb
|
5
|
+
# 2. cp after.dat before.dat
|
6
|
+
# 3. Make your modifications to the treetop code
|
7
|
+
# 4. Run ruby seqpar_benchmark.rb
|
8
|
+
# 5. Run gnuplot seqpar.gnuplot
|
9
|
+
#
|
10
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
11
|
+
require 'treetop'
|
12
|
+
require 'benchmark'
|
13
|
+
|
14
|
+
srand(47562) # So it runs the same each time
|
15
|
+
|
16
|
+
class Array; def sum; inject( nil ) { |sum,x| sum ? sum+x : x }; end; end
|
17
|
+
class Array; def mean; sum / size; end; end
|
18
|
+
|
19
|
+
class SeqParBenchmark
|
20
|
+
|
21
|
+
OPERATORS = ["seq", "fit", "art"*5, "par", "sequence"]
|
22
|
+
|
23
|
+
# Loads the grammar and returns a parser
|
24
|
+
def initialize
|
25
|
+
compiler = Treetop::Compiler::GrammarCompiler.new
|
26
|
+
@where = File.expand_path(File.dirname(__FILE__))
|
27
|
+
grammar = File.join(@where, 'seqpar.treetop')
|
28
|
+
output = File.join(@where, 'seqpar.rb')
|
29
|
+
compiler.compile(grammar, output)
|
30
|
+
load output
|
31
|
+
File.delete(output)
|
32
|
+
@parser = SeqParParser.new
|
33
|
+
end
|
34
|
+
|
35
|
+
# Checks the grammar
|
36
|
+
def check
|
37
|
+
["Task",
|
38
|
+
"seq Task end",
|
39
|
+
"par Task end",
|
40
|
+
"seq Task Task end",
|
41
|
+
"par Task Task end",
|
42
|
+
"par seq Task end Task end",
|
43
|
+
"par seq seq Task end end Task end",
|
44
|
+
"seq Task par seq Task end Task end Task end"].each do |input|
|
45
|
+
raise ParseError.new(@parser) if @parser.parse(input).nil?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Generates an input text
|
50
|
+
def generate(depth=0)
|
51
|
+
return "Task" if depth>7
|
52
|
+
return "seq #{generate(depth+1)} end" if depth==0
|
53
|
+
which = rand(OPERATORS.length)
|
54
|
+
case which
|
55
|
+
when 0
|
56
|
+
"Task"
|
57
|
+
else
|
58
|
+
raise unless OPERATORS[which]
|
59
|
+
buffer = "#{OPERATORS[which]} "
|
60
|
+
0.upto(rand(4)+1) do
|
61
|
+
buffer << generate(depth+1) << " "
|
62
|
+
end
|
63
|
+
buffer << "end"
|
64
|
+
buffer
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Launches benchmarking
|
69
|
+
def benchmark
|
70
|
+
number_by_size = Hash.new {|h,k| h[k] = 0}
|
71
|
+
time_by_size = Hash.new {|h,k| h[k] = 0}
|
72
|
+
0.upto(250) do |i|
|
73
|
+
input = generate
|
74
|
+
length = input.length
|
75
|
+
puts "Launching #{i}: #{input.length}"
|
76
|
+
# puts input
|
77
|
+
tms = Benchmark.measure { @parser.parse(input) }
|
78
|
+
number_by_size[length] += 1
|
79
|
+
time_by_size[length] += tms.total*1000
|
80
|
+
end
|
81
|
+
# puts number_by_size.inspect
|
82
|
+
# puts time_by_size.inspect
|
83
|
+
|
84
|
+
File.open(File.join(@where, 'after.dat'), 'w') do |dat|
|
85
|
+
number_by_size.keys.sort.each do |size|
|
86
|
+
dat << "#{size} #{(time_by_size[size]/number_by_size[size]).truncate}\n"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
if File.exists?(File.join(@where, 'before.dat'))
|
91
|
+
before = {}
|
92
|
+
performance_increases = []
|
93
|
+
File.foreach(File.join(@where, 'before.dat')) do |line|
|
94
|
+
size, time = line.split(' ')
|
95
|
+
before[size] = time
|
96
|
+
end
|
97
|
+
File.foreach(File.join(@where, 'after.dat')) do |line|
|
98
|
+
size, time = line.split(' ')
|
99
|
+
performance_increases << (before[size].to_f - time.to_f) / before[size].to_f unless time == "0" || before[size] == "0"
|
100
|
+
end
|
101
|
+
puts "Average performance increase: #{performance_increases.mean * 100}%"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
SeqParBenchmark.new.benchmark
|