mail 2.1.5.2 → 2.1.5.3
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/CHANGELOG.rdoc +6 -0
- data/Rakefile +2 -1
- data/lib/mail.rb +0 -1
- data/lib/mail/elements.rb +0 -1
- data/lib/mail/utilities.rb +1 -1
- data/lib/mail/version.rb +1 -1
- data/lib/tasks/treetop.rake +4 -4
- metadata +17 -129
- data/lib/mail/vendor/treetop-1.4.4/History.txt +0 -18
- data/lib/mail/vendor/treetop-1.4.4/LICENSE +0 -19
- data/lib/mail/vendor/treetop-1.4.4/README.md +0 -164
- data/lib/mail/vendor/treetop-1.4.4/Rakefile +0 -28
- data/lib/mail/vendor/treetop-1.4.4/Treetop.tmbundle/Preferences/Comments.tmPreferences +0 -22
- data/lib/mail/vendor/treetop-1.4.4/Treetop.tmbundle/Snippets/grammar ___ end.tmSnippet +0 -20
- data/lib/mail/vendor/treetop-1.4.4/Treetop.tmbundle/Snippets/rule ___ end.tmSnippet +0 -18
- data/lib/mail/vendor/treetop-1.4.4/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/designable.nib +0 -1524
- data/lib/mail/vendor/treetop-1.4.4/Treetop.tmbundle/Support/nibs/SyntaxTreeViewer.nib/keyedobjects.nib +0 -0
- data/lib/mail/vendor/treetop-1.4.4/Treetop.tmbundle/Support/syntax_tree_viewer.rb +0 -117
- data/lib/mail/vendor/treetop-1.4.4/Treetop.tmbundle/Syntaxes/Treetop Grammar.tmLanguage +0 -278
- data/lib/mail/vendor/treetop-1.4.4/Treetop.tmbundle/info.plist +0 -10
- data/lib/mail/vendor/treetop-1.4.4/benchmark/seqpar.gnuplot +0 -15
- data/lib/mail/vendor/treetop-1.4.4/benchmark/seqpar.treetop +0 -16
- data/lib/mail/vendor/treetop-1.4.4/benchmark/seqpar_benchmark.rb +0 -107
- data/lib/mail/vendor/treetop-1.4.4/bin/tt +0 -112
- data/lib/mail/vendor/treetop-1.4.4/doc/contributing_and_planned_features.markdown +0 -103
- data/lib/mail/vendor/treetop-1.4.4/doc/grammar_composition.markdown +0 -65
- data/lib/mail/vendor/treetop-1.4.4/doc/index.markdown +0 -90
- data/lib/mail/vendor/treetop-1.4.4/doc/pitfalls_and_advanced_techniques.markdown +0 -51
- data/lib/mail/vendor/treetop-1.4.4/doc/semantic_interpretation.markdown +0 -189
- data/lib/mail/vendor/treetop-1.4.4/doc/site.rb +0 -112
- data/lib/mail/vendor/treetop-1.4.4/doc/sitegen.rb +0 -65
- data/lib/mail/vendor/treetop-1.4.4/doc/syntactic_recognition.markdown +0 -100
- data/lib/mail/vendor/treetop-1.4.4/doc/using_in_ruby.markdown +0 -28
- data/lib/mail/vendor/treetop-1.4.4/examples/lambda_calculus/arithmetic.rb +0 -551
- data/lib/mail/vendor/treetop-1.4.4/examples/lambda_calculus/arithmetic.treetop +0 -97
- data/lib/mail/vendor/treetop-1.4.4/examples/lambda_calculus/arithmetic_node_classes.rb +0 -7
- data/lib/mail/vendor/treetop-1.4.4/examples/lambda_calculus/arithmetic_test.rb +0 -54
- data/lib/mail/vendor/treetop-1.4.4/examples/lambda_calculus/lambda_calculus +0 -0
- data/lib/mail/vendor/treetop-1.4.4/examples/lambda_calculus/lambda_calculus.rb +0 -718
- data/lib/mail/vendor/treetop-1.4.4/examples/lambda_calculus/lambda_calculus.treetop +0 -132
- data/lib/mail/vendor/treetop-1.4.4/examples/lambda_calculus/lambda_calculus_node_classes.rb +0 -5
- data/lib/mail/vendor/treetop-1.4.4/examples/lambda_calculus/lambda_calculus_test.rb +0 -89
- data/lib/mail/vendor/treetop-1.4.4/examples/lambda_calculus/test_helper.rb +0 -18
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop.rb +0 -3
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/bootstrap_gen_1_metagrammar.rb +0 -42
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler.rb +0 -7
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/grammar_compiler.rb +0 -44
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/lexical_address_space.rb +0 -17
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/metagrammar.rb +0 -3366
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/metagrammar.treetop +0 -436
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes.rb +0 -19
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/anything_symbol.rb +0 -18
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/atomic_expression.rb +0 -14
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/character_class.rb +0 -28
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/choice.rb +0 -31
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/declaration_sequence.rb +0 -24
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/grammar.rb +0 -28
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/inline_module.rb +0 -27
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/nonterminal.rb +0 -13
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/optional.rb +0 -19
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/parenthesized_expression.rb +0 -9
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/parsing_expression.rb +0 -146
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/parsing_rule.rb +0 -58
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/predicate.rb +0 -45
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/predicate_block.rb +0 -16
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/repetition.rb +0 -55
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/sequence.rb +0 -71
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/terminal.rb +0 -20
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/transient_prefix.rb +0 -9
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/node_classes/treetop_file.rb +0 -9
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/compiler/ruby_builder.rb +0 -113
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/polyglot.rb +0 -9
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/ruby_extensions.rb +0 -1
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/ruby_extensions/string.rb +0 -42
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/runtime.rb +0 -6
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/runtime/compiled_parser.rb +0 -110
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/runtime/interval_skip_list.rb +0 -3
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/runtime/interval_skip_list/head_node.rb +0 -15
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +0 -200
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/runtime/interval_skip_list/node.rb +0 -164
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/runtime/syntax_node.rb +0 -114
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/runtime/terminal_parse_failure.rb +0 -16
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/runtime/terminal_syntax_node.rb +0 -17
- data/lib/mail/vendor/treetop-1.4.4/lib/treetop/version.rb +0 -9
- data/lib/mail/vendor/treetop-1.4.4/script/generate_metagrammar.rb +0 -13
- data/lib/mail/vendor/treetop-1.4.4/script/svnadd +0 -11
- data/lib/mail/vendor/treetop-1.4.4/script/svnrm +0 -11
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/and_predicate_spec.rb +0 -36
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/anything_symbol_spec.rb +0 -44
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/character_class_spec.rb +0 -276
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/choice_spec.rb +0 -80
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/circular_compilation_spec.rb +0 -30
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/failure_propagation_functional_spec.rb +0 -21
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/grammar_compiler_spec.rb +0 -84
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/grammar_spec.rb +0 -41
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/multibyte_chars_spec.rb +0 -38
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/nonterminal_symbol_spec.rb +0 -40
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/not_predicate_spec.rb +0 -38
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/one_or_more_spec.rb +0 -35
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/optional_spec.rb +0 -37
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/parenthesized_expression_spec.rb +0 -19
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/parsing_rule_spec.rb +0 -61
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/repeated_subrule_spec.rb +0 -29
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/semantic_predicate_spec.rb +0 -175
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/sequence_spec.rb +0 -115
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/terminal_spec.rb +0 -81
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/terminal_symbol_spec.rb +0 -37
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/test_grammar.treetop +0 -7
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/test_grammar.tt +0 -7
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/test_grammar_do.treetop +0 -7
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/tt_compiler_spec.rb +0 -216
- data/lib/mail/vendor/treetop-1.4.4/spec/compiler/zero_or_more_spec.rb +0 -56
- data/lib/mail/vendor/treetop-1.4.4/spec/composition/a.treetop +0 -11
- data/lib/mail/vendor/treetop-1.4.4/spec/composition/b.treetop +0 -11
- data/lib/mail/vendor/treetop-1.4.4/spec/composition/c.treetop +0 -10
- data/lib/mail/vendor/treetop-1.4.4/spec/composition/d.treetop +0 -10
- data/lib/mail/vendor/treetop-1.4.4/spec/composition/f.treetop +0 -17
- data/lib/mail/vendor/treetop-1.4.4/spec/composition/grammar_composition_spec.rb +0 -40
- data/lib/mail/vendor/treetop-1.4.4/spec/composition/subfolder/e_includes_c.treetop +0 -15
- data/lib/mail/vendor/treetop-1.4.4/spec/ruby_extensions/string_spec.rb +0 -32
- data/lib/mail/vendor/treetop-1.4.4/spec/runtime/compiled_parser_spec.rb +0 -101
- data/lib/mail/vendor/treetop-1.4.4/spec/runtime/interval_skip_list/delete_spec.rb +0 -147
- data/lib/mail/vendor/treetop-1.4.4/spec/runtime/interval_skip_list/expire_range_spec.rb +0 -349
- data/lib/mail/vendor/treetop-1.4.4/spec/runtime/interval_skip_list/insert_and_delete_node.rb +0 -385
- data/lib/mail/vendor/treetop-1.4.4/spec/runtime/interval_skip_list/insert_spec.rb +0 -660
- data/lib/mail/vendor/treetop-1.4.4/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +0 -6175
- data/lib/mail/vendor/treetop-1.4.4/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +0 -58
- data/lib/mail/vendor/treetop-1.4.4/spec/runtime/interval_skip_list/palindromic_fixture.rb +0 -23
- data/lib/mail/vendor/treetop-1.4.4/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +0 -163
- data/lib/mail/vendor/treetop-1.4.4/spec/runtime/interval_skip_list/spec_helper.rb +0 -84
- data/lib/mail/vendor/treetop-1.4.4/spec/runtime/syntax_node_spec.rb +0 -77
- data/lib/mail/vendor/treetop-1.4.4/spec/spec_helper.rb +0 -110
- data/lib/mail/vendor/treetop-1.4.4/treetop.gemspec +0 -18
- data/lib/mail/vendor/treetop.rb +0 -2
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'erector'
|
3
|
-
require "#{File.dirname(__FILE__)}/sitegen"
|
4
|
-
require 'fileutils'
|
5
|
-
require 'bluecloth'
|
6
|
-
|
7
|
-
class Layout < Erector::Widget
|
8
|
-
def render
|
9
|
-
html do
|
10
|
-
head do
|
11
|
-
link :rel => "stylesheet",
|
12
|
-
:type => "text/css",
|
13
|
-
:href => "./screen.css"
|
14
|
-
|
15
|
-
rawtext %(
|
16
|
-
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
17
|
-
</script>
|
18
|
-
<script type="text/javascript">
|
19
|
-
_uacct = "UA-3418876-1";
|
20
|
-
urchinTracker();
|
21
|
-
</script>
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
body do
|
26
|
-
div :id => 'top' do
|
27
|
-
div :id => 'main_navigation' do
|
28
|
-
main_navigation
|
29
|
-
end
|
30
|
-
end
|
31
|
-
div :id => 'middle' do
|
32
|
-
div :id => 'content' do
|
33
|
-
content
|
34
|
-
end
|
35
|
-
end
|
36
|
-
div :id => 'bottom' do
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def main_navigation
|
44
|
-
ul do
|
45
|
-
li { link_to "Documentation", SyntacticRecognition, Documentation }
|
46
|
-
li { link_to "Contribute", Contribute }
|
47
|
-
li { link_to "Home", Index }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def content
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class Index < Layout
|
56
|
-
def content
|
57
|
-
bluecloth "index.markdown"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class Documentation < Layout
|
62
|
-
abstract
|
63
|
-
|
64
|
-
def content
|
65
|
-
div :id => 'secondary_navigation' do
|
66
|
-
ul do
|
67
|
-
li { link_to 'Syntax', SyntacticRecognition }
|
68
|
-
li { link_to 'Semantics', SemanticInterpretation }
|
69
|
-
li { link_to 'Using In Ruby', UsingInRuby }
|
70
|
-
li { link_to 'Advanced Techniques', PitfallsAndAdvancedTechniques }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
div :id => 'documentation_content' do
|
75
|
-
documentation_content
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class SyntacticRecognition < Documentation
|
81
|
-
def documentation_content
|
82
|
-
bluecloth "syntactic_recognition.markdown"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
class SemanticInterpretation < Documentation
|
87
|
-
def documentation_content
|
88
|
-
bluecloth "semantic_interpretation.markdown"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class UsingInRuby < Documentation
|
93
|
-
def documentation_content
|
94
|
-
bluecloth "using_in_ruby.markdown"
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class PitfallsAndAdvancedTechniques < Documentation
|
99
|
-
def documentation_content
|
100
|
-
bluecloth "pitfalls_and_advanced_techniques.markdown"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
class Contribute < Layout
|
106
|
-
def content
|
107
|
-
bluecloth "contributing_and_planned_features.markdown"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
Layout.generate_site
|
@@ -1,65 +0,0 @@
|
|
1
|
-
class Layout < Erector::Widget
|
2
|
-
|
3
|
-
class << self
|
4
|
-
def inherited(page_class)
|
5
|
-
puts page_class
|
6
|
-
(@@page_classes ||= []) << page_class
|
7
|
-
end
|
8
|
-
|
9
|
-
def generate_site
|
10
|
-
FileUtils.mkdir_p(site_dir)
|
11
|
-
@@page_classes.each do |page_class|
|
12
|
-
page_class.generate_html unless page_class.abstract?
|
13
|
-
puts page_class
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def generate_html
|
18
|
-
File.open(absolute_path, 'w') do |file|
|
19
|
-
file.write(new.render)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def absolute_path
|
24
|
-
absolutize(relative_path)
|
25
|
-
end
|
26
|
-
|
27
|
-
def relative_path
|
28
|
-
"#{name.gsub('::', '_').underscore}.html"
|
29
|
-
end
|
30
|
-
|
31
|
-
def absolutize(relative_path)
|
32
|
-
File.join(site_dir, relative_path)
|
33
|
-
end
|
34
|
-
|
35
|
-
def abstract
|
36
|
-
@abstract = true
|
37
|
-
end
|
38
|
-
|
39
|
-
def abstract?
|
40
|
-
@abstract
|
41
|
-
end
|
42
|
-
|
43
|
-
def site_dir
|
44
|
-
File.join(File.dirname(__FILE__), "site")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def bluecloth(relative_path)
|
49
|
-
File.open(File.join(File.dirname(__FILE__), relative_path)) do |file|
|
50
|
-
rawtext BlueCloth.new(file.read).to_html
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def absolutize(relative_path)
|
55
|
-
self.class.absolutize(relative_path)
|
56
|
-
end
|
57
|
-
|
58
|
-
def link_to(link_text, page_class, section_class=nil)
|
59
|
-
if instance_of?(page_class) || section_class && is_a?(section_class)
|
60
|
-
text link_text
|
61
|
-
else
|
62
|
-
a link_text, :href => page_class.relative_path
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
#Syntactic Recognition
|
2
|
-
Treetop grammars are written in a custom language based on parsing expression grammars. Literature on the subject of <a href="http://en.wikipedia.org/wiki/Parsing_expression_grammar">parsing expression grammars</a> is useful in writing Treetop grammars.
|
3
|
-
|
4
|
-
#Grammar Structure
|
5
|
-
Treetop grammars look like this:
|
6
|
-
|
7
|
-
grammar GrammarName
|
8
|
-
rule rule_name
|
9
|
-
...
|
10
|
-
end
|
11
|
-
|
12
|
-
rule rule_name
|
13
|
-
...
|
14
|
-
end
|
15
|
-
|
16
|
-
...
|
17
|
-
end
|
18
|
-
|
19
|
-
The main keywords are:
|
20
|
-
|
21
|
-
* `grammar` : This introduces a new grammar. It is followed by a constant name to which the grammar will be bound when it is loaded.
|
22
|
-
|
23
|
-
* `rule` : This defines a parsing rule within the grammar. It is followed by a name by which this rule can be referenced within other rules. It is then followed by a parsing expression defining the rule.
|
24
|
-
|
25
|
-
#Parsing Expressions
|
26
|
-
Each rule associates a name with a _parsing expression_. Parsing expressions are a generalization of vanilla regular expressions. Their key feature is the ability to reference other expressions in the grammar by name.
|
27
|
-
|
28
|
-
##Terminal Symbols
|
29
|
-
###Strings
|
30
|
-
Strings are surrounded in double or single quotes and must be matched exactly.
|
31
|
-
|
32
|
-
* `"foo"`
|
33
|
-
* `'foo'`
|
34
|
-
|
35
|
-
###Character Classes
|
36
|
-
Character classes are surrounded by brackets. Their semantics are identical to those used in Ruby's regular expressions.
|
37
|
-
|
38
|
-
* `[a-zA-Z]`
|
39
|
-
* `[0-9]`
|
40
|
-
|
41
|
-
###The Anything Symbol
|
42
|
-
The anything symbol is represented by a dot (`.`) and matches any single character.
|
43
|
-
|
44
|
-
##Nonterminal Symbols
|
45
|
-
Nonterminal symbols are unquoted references to other named rules. They are equivalent to an inline substitution of the named expression.
|
46
|
-
|
47
|
-
rule foo
|
48
|
-
"the dog " bar
|
49
|
-
end
|
50
|
-
|
51
|
-
rule bar
|
52
|
-
"jumped"
|
53
|
-
end
|
54
|
-
|
55
|
-
The above grammar is equivalent to:
|
56
|
-
|
57
|
-
rule foo
|
58
|
-
"the dog jumped"
|
59
|
-
end
|
60
|
-
|
61
|
-
##Ordered Choice
|
62
|
-
Parsers attempt to match ordered choices in left-to-right order, and stop after the first successful match.
|
63
|
-
|
64
|
-
"foobar" / "foo" / "bar"
|
65
|
-
|
66
|
-
Note that if `"foo"` in the above expression came first, `"foobar"` would never be matched.
|
67
|
-
|
68
|
-
##Sequences
|
69
|
-
|
70
|
-
Sequences are a space-separated list of parsing expressions. They have higher precedence than choices, so choices must be parenthesized to be used as the elements of a sequence.
|
71
|
-
|
72
|
-
"foo" "bar" ("baz" / "bop")
|
73
|
-
|
74
|
-
##Zero or More
|
75
|
-
Parsers will greedily match an expression zero or more times if it is followed by the star (`*`) symbol.
|
76
|
-
|
77
|
-
* `'foo'*` matches the empty string, `"foo"`, `"foofoo"`, etc.
|
78
|
-
|
79
|
-
##One or More
|
80
|
-
Parsers will greedily match an expression one or more times if it is followed by the star (`+`) symbol.
|
81
|
-
|
82
|
-
* `'foo'+` does not match the empty string, but matches `"foo"`, `"foofoo"`, etc.
|
83
|
-
|
84
|
-
##Optional Expressions
|
85
|
-
An expression can be declared optional by following it with a question mark (`?`).
|
86
|
-
|
87
|
-
* `'foo'?` matches `"foo"` or the empty string.
|
88
|
-
|
89
|
-
##Lookahead Assertions
|
90
|
-
Lookahead assertions can be used to give parsing expressions a limited degree of context-sensitivity. The parser will look ahead into the buffer and attempt to match an expression without consuming input.
|
91
|
-
|
92
|
-
###Positive Lookahead Assertion
|
93
|
-
Preceding an expression with an ampersand `(&)` indicates that it must match, but no input will be consumed in the process of determining whether this is true.
|
94
|
-
|
95
|
-
* `"foo" &"bar"` matches `"foobar"` but only consumes up to the end `"foo"`. It will not match `"foobaz"`.
|
96
|
-
|
97
|
-
###Negative Lookahead Assertion
|
98
|
-
Preceding an expression with a bang `(!)` indicates that the expression must not match, but no input will be consumed in the process of determining whether this is true.
|
99
|
-
|
100
|
-
* `"foo" !"bar"` matches `"foobaz"` but only consumes up to the end `"foo"`. It will not match `"foobar"`.
|
@@ -1,28 +0,0 @@
|
|
1
|
-
#Using Treetop Grammars in Ruby
|
2
|
-
##Using the Command Line Compiler
|
3
|
-
You can `.treetop` files into Ruby source code with the `tt` command line script. `tt` takes an list of files with a `.treetop` extension and compiles them into `.rb` files of the same name. You can then `require` these files like any other Ruby script. Alternately, you can supply just one `.treetop` file and a `-o` flag to name specify the name of the output file. Improvements to this compilation script are welcome.
|
4
|
-
|
5
|
-
tt foo.treetop bar.treetop
|
6
|
-
tt foo.treetop -o foogrammar.rb
|
7
|
-
|
8
|
-
##Loading A Grammar Directly
|
9
|
-
The Polyglot gem makes it possible to load `.treetop` or `.tt` files directly with `require`. This will invoke `Treetop.load`, which automatically compiles the grammar to Ruby and then evaluates the Ruby source. If you are getting errors in methods you define on the syntax tree, try using the command line compiler for better stack trace feedback. A better solution to this issue is in the works.
|
10
|
-
|
11
|
-
In order to use Polyglot dynamic loading of `.treetop` or `.tt` files though, you need to require the Polyglot gem before you require the Treetop gem as Treetop will only create hooks into Polyglot for the treetop files if Polyglot is already loaded. So you need to use:
|
12
|
-
|
13
|
-
require 'polyglot'
|
14
|
-
require 'treetop'
|
15
|
-
|
16
|
-
in order to use Polyglot auto loading with Treetop in Ruby.
|
17
|
-
|
18
|
-
##Instantiating and Using Parsers
|
19
|
-
If a grammar by the name of `Foo` is defined, the compiled Ruby source will define a `FooParser` class. To parse input, create an instance and call its `parse` method with a string. The parser will return the syntax tree of the match or `nil` if there is a failure.
|
20
|
-
|
21
|
-
Treetop.load "arithmetic"
|
22
|
-
|
23
|
-
parser = ArithmeticParser.new
|
24
|
-
if parser.parse('1+1')
|
25
|
-
puts 'success'
|
26
|
-
else
|
27
|
-
puts 'failure'
|
28
|
-
end
|
@@ -1,551 +0,0 @@
|
|
1
|
-
module Arithmetic
|
2
|
-
include Treetop::Runtime
|
3
|
-
|
4
|
-
def root
|
5
|
-
@root || :expression
|
6
|
-
end
|
7
|
-
|
8
|
-
def _nt_expression
|
9
|
-
start_index = index
|
10
|
-
cached = node_cache[:expression][index]
|
11
|
-
if cached
|
12
|
-
@index = cached.interval.end
|
13
|
-
return cached
|
14
|
-
end
|
15
|
-
|
16
|
-
i0 = index
|
17
|
-
r1 = _nt_comparative
|
18
|
-
if r1.success?
|
19
|
-
r0 = r1
|
20
|
-
else
|
21
|
-
r2 = _nt_additive
|
22
|
-
if r2.success?
|
23
|
-
r0 = r2
|
24
|
-
else
|
25
|
-
self.index = i0
|
26
|
-
r0 = ParseFailure.new(input, i0)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
node_cache[:expression][start_index] = r0
|
31
|
-
|
32
|
-
return r0
|
33
|
-
end
|
34
|
-
|
35
|
-
module Comparative0
|
36
|
-
def operand_1
|
37
|
-
elements[0]
|
38
|
-
end
|
39
|
-
|
40
|
-
def space
|
41
|
-
elements[1]
|
42
|
-
end
|
43
|
-
|
44
|
-
def operator
|
45
|
-
elements[2]
|
46
|
-
end
|
47
|
-
|
48
|
-
def space
|
49
|
-
elements[3]
|
50
|
-
end
|
51
|
-
|
52
|
-
def operand_2
|
53
|
-
elements[4]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def _nt_comparative
|
58
|
-
start_index = index
|
59
|
-
cached = node_cache[:comparative][index]
|
60
|
-
if cached
|
61
|
-
@index = cached.interval.end
|
62
|
-
return cached
|
63
|
-
end
|
64
|
-
|
65
|
-
i0, s0 = index, []
|
66
|
-
r1 = _nt_additive
|
67
|
-
s0 << r1
|
68
|
-
if r1.success?
|
69
|
-
r2 = _nt_space
|
70
|
-
s0 << r2
|
71
|
-
if r2.success?
|
72
|
-
r3 = _nt_equality_op
|
73
|
-
s0 << r3
|
74
|
-
if r3.success?
|
75
|
-
r4 = _nt_space
|
76
|
-
s0 << r4
|
77
|
-
if r4.success?
|
78
|
-
r5 = _nt_additive
|
79
|
-
s0 << r5
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
if s0.last.success?
|
85
|
-
r0 = (BinaryOperation).new(input, i0...index, s0)
|
86
|
-
r0.extend(Comparative0)
|
87
|
-
else
|
88
|
-
self.index = i0
|
89
|
-
r0 = ParseFailure.new(input, i0)
|
90
|
-
end
|
91
|
-
|
92
|
-
node_cache[:comparative][start_index] = r0
|
93
|
-
|
94
|
-
return r0
|
95
|
-
end
|
96
|
-
|
97
|
-
module EqualityOp0
|
98
|
-
def apply(a, b)
|
99
|
-
a == b
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def _nt_equality_op
|
104
|
-
start_index = index
|
105
|
-
cached = node_cache[:equality_op][index]
|
106
|
-
if cached
|
107
|
-
@index = cached.interval.end
|
108
|
-
return cached
|
109
|
-
end
|
110
|
-
|
111
|
-
r0 = parse_terminal('==', SyntaxNode, EqualityOp0)
|
112
|
-
|
113
|
-
node_cache[:equality_op][start_index] = r0
|
114
|
-
|
115
|
-
return r0
|
116
|
-
end
|
117
|
-
|
118
|
-
module Additive0
|
119
|
-
def operand_1
|
120
|
-
elements[0]
|
121
|
-
end
|
122
|
-
|
123
|
-
def space
|
124
|
-
elements[1]
|
125
|
-
end
|
126
|
-
|
127
|
-
def operator
|
128
|
-
elements[2]
|
129
|
-
end
|
130
|
-
|
131
|
-
def space
|
132
|
-
elements[3]
|
133
|
-
end
|
134
|
-
|
135
|
-
def operand_2
|
136
|
-
elements[4]
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def _nt_additive
|
141
|
-
start_index = index
|
142
|
-
cached = node_cache[:additive][index]
|
143
|
-
if cached
|
144
|
-
@index = cached.interval.end
|
145
|
-
return cached
|
146
|
-
end
|
147
|
-
|
148
|
-
i0 = index
|
149
|
-
i1, s1 = index, []
|
150
|
-
r2 = _nt_multitive
|
151
|
-
s1 << r2
|
152
|
-
if r2.success?
|
153
|
-
r3 = _nt_space
|
154
|
-
s1 << r3
|
155
|
-
if r3.success?
|
156
|
-
r4 = _nt_additive_op
|
157
|
-
s1 << r4
|
158
|
-
if r4.success?
|
159
|
-
r5 = _nt_space
|
160
|
-
s1 << r5
|
161
|
-
if r5.success?
|
162
|
-
r6 = _nt_additive
|
163
|
-
s1 << r6
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
if s1.last.success?
|
169
|
-
r1 = (BinaryOperation).new(input, i1...index, s1)
|
170
|
-
r1.extend(Additive0)
|
171
|
-
else
|
172
|
-
self.index = i1
|
173
|
-
r1 = ParseFailure.new(input, i1)
|
174
|
-
end
|
175
|
-
if r1.success?
|
176
|
-
r0 = r1
|
177
|
-
else
|
178
|
-
r7 = _nt_multitive
|
179
|
-
if r7.success?
|
180
|
-
r0 = r7
|
181
|
-
else
|
182
|
-
self.index = i0
|
183
|
-
r0 = ParseFailure.new(input, i0)
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
node_cache[:additive][start_index] = r0
|
188
|
-
|
189
|
-
return r0
|
190
|
-
end
|
191
|
-
|
192
|
-
module AdditiveOp0
|
193
|
-
def apply(a, b)
|
194
|
-
a + b
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
module AdditiveOp1
|
199
|
-
def apply(a, b)
|
200
|
-
a - b
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def _nt_additive_op
|
205
|
-
start_index = index
|
206
|
-
cached = node_cache[:additive_op][index]
|
207
|
-
if cached
|
208
|
-
@index = cached.interval.end
|
209
|
-
return cached
|
210
|
-
end
|
211
|
-
|
212
|
-
i0 = index
|
213
|
-
r1 = parse_terminal('+', SyntaxNode, AdditiveOp0)
|
214
|
-
if r1.success?
|
215
|
-
r0 = r1
|
216
|
-
else
|
217
|
-
r2 = parse_terminal('-', SyntaxNode, AdditiveOp1)
|
218
|
-
if r2.success?
|
219
|
-
r0 = r2
|
220
|
-
else
|
221
|
-
self.index = i0
|
222
|
-
r0 = ParseFailure.new(input, i0)
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
node_cache[:additive_op][start_index] = r0
|
227
|
-
|
228
|
-
return r0
|
229
|
-
end
|
230
|
-
|
231
|
-
module Multitive0
|
232
|
-
def operand_1
|
233
|
-
elements[0]
|
234
|
-
end
|
235
|
-
|
236
|
-
def space
|
237
|
-
elements[1]
|
238
|
-
end
|
239
|
-
|
240
|
-
def operator
|
241
|
-
elements[2]
|
242
|
-
end
|
243
|
-
|
244
|
-
def space
|
245
|
-
elements[3]
|
246
|
-
end
|
247
|
-
|
248
|
-
def operand_2
|
249
|
-
elements[4]
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
def _nt_multitive
|
254
|
-
start_index = index
|
255
|
-
cached = node_cache[:multitive][index]
|
256
|
-
if cached
|
257
|
-
@index = cached.interval.end
|
258
|
-
return cached
|
259
|
-
end
|
260
|
-
|
261
|
-
i0 = index
|
262
|
-
i1, s1 = index, []
|
263
|
-
r2 = _nt_primary
|
264
|
-
s1 << r2
|
265
|
-
if r2.success?
|
266
|
-
r3 = _nt_space
|
267
|
-
s1 << r3
|
268
|
-
if r3.success?
|
269
|
-
r4 = _nt_multitive_op
|
270
|
-
s1 << r4
|
271
|
-
if r4.success?
|
272
|
-
r5 = _nt_space
|
273
|
-
s1 << r5
|
274
|
-
if r5.success?
|
275
|
-
r6 = _nt_multitive
|
276
|
-
s1 << r6
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
if s1.last.success?
|
282
|
-
r1 = (BinaryOperation).new(input, i1...index, s1)
|
283
|
-
r1.extend(Multitive0)
|
284
|
-
else
|
285
|
-
self.index = i1
|
286
|
-
r1 = ParseFailure.new(input, i1)
|
287
|
-
end
|
288
|
-
if r1.success?
|
289
|
-
r0 = r1
|
290
|
-
else
|
291
|
-
r7 = _nt_primary
|
292
|
-
if r7.success?
|
293
|
-
r0 = r7
|
294
|
-
else
|
295
|
-
self.index = i0
|
296
|
-
r0 = ParseFailure.new(input, i0)
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
node_cache[:multitive][start_index] = r0
|
301
|
-
|
302
|
-
return r0
|
303
|
-
end
|
304
|
-
|
305
|
-
module MultitiveOp0
|
306
|
-
def apply(a, b)
|
307
|
-
a * b
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
module MultitiveOp1
|
312
|
-
def apply(a, b)
|
313
|
-
a / b
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
def _nt_multitive_op
|
318
|
-
start_index = index
|
319
|
-
cached = node_cache[:multitive_op][index]
|
320
|
-
if cached
|
321
|
-
@index = cached.interval.end
|
322
|
-
return cached
|
323
|
-
end
|
324
|
-
|
325
|
-
i0 = index
|
326
|
-
r1 = parse_terminal('*', SyntaxNode, MultitiveOp0)
|
327
|
-
if r1.success?
|
328
|
-
r0 = r1
|
329
|
-
else
|
330
|
-
r2 = parse_terminal('/', SyntaxNode, MultitiveOp1)
|
331
|
-
if r2.success?
|
332
|
-
r0 = r2
|
333
|
-
else
|
334
|
-
self.index = i0
|
335
|
-
r0 = ParseFailure.new(input, i0)
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
node_cache[:multitive_op][start_index] = r0
|
340
|
-
|
341
|
-
return r0
|
342
|
-
end
|
343
|
-
|
344
|
-
module Primary0
|
345
|
-
def space
|
346
|
-
elements[1]
|
347
|
-
end
|
348
|
-
|
349
|
-
def expression
|
350
|
-
elements[2]
|
351
|
-
end
|
352
|
-
|
353
|
-
def space
|
354
|
-
elements[3]
|
355
|
-
end
|
356
|
-
|
357
|
-
end
|
358
|
-
|
359
|
-
module Primary1
|
360
|
-
def eval(env={})
|
361
|
-
expression.eval(env)
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
def _nt_primary
|
366
|
-
start_index = index
|
367
|
-
cached = node_cache[:primary][index]
|
368
|
-
if cached
|
369
|
-
@index = cached.interval.end
|
370
|
-
return cached
|
371
|
-
end
|
372
|
-
|
373
|
-
i0 = index
|
374
|
-
r1 = _nt_variable
|
375
|
-
if r1.success?
|
376
|
-
r0 = r1
|
377
|
-
else
|
378
|
-
r2 = _nt_number
|
379
|
-
if r2.success?
|
380
|
-
r0 = r2
|
381
|
-
else
|
382
|
-
i3, s3 = index, []
|
383
|
-
r4 = parse_terminal('(', SyntaxNode)
|
384
|
-
s3 << r4
|
385
|
-
if r4.success?
|
386
|
-
r5 = _nt_space
|
387
|
-
s3 << r5
|
388
|
-
if r5.success?
|
389
|
-
r6 = _nt_expression
|
390
|
-
s3 << r6
|
391
|
-
if r6.success?
|
392
|
-
r7 = _nt_space
|
393
|
-
s3 << r7
|
394
|
-
if r7.success?
|
395
|
-
r8 = parse_terminal(')', SyntaxNode)
|
396
|
-
s3 << r8
|
397
|
-
end
|
398
|
-
end
|
399
|
-
end
|
400
|
-
end
|
401
|
-
if s3.last.success?
|
402
|
-
r3 = (SyntaxNode).new(input, i3...index, s3)
|
403
|
-
r3.extend(Primary0)
|
404
|
-
r3.extend(Primary1)
|
405
|
-
else
|
406
|
-
self.index = i3
|
407
|
-
r3 = ParseFailure.new(input, i3)
|
408
|
-
end
|
409
|
-
if r3.success?
|
410
|
-
r0 = r3
|
411
|
-
else
|
412
|
-
self.index = i0
|
413
|
-
r0 = ParseFailure.new(input, i0)
|
414
|
-
end
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
node_cache[:primary][start_index] = r0
|
419
|
-
|
420
|
-
return r0
|
421
|
-
end
|
422
|
-
|
423
|
-
module Variable0
|
424
|
-
def eval(env={})
|
425
|
-
env[name]
|
426
|
-
end
|
427
|
-
|
428
|
-
def name
|
429
|
-
text_value
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
def _nt_variable
|
434
|
-
start_index = index
|
435
|
-
cached = node_cache[:variable][index]
|
436
|
-
if cached
|
437
|
-
@index = cached.interval.end
|
438
|
-
return cached
|
439
|
-
end
|
440
|
-
|
441
|
-
s0, i0 = [], index
|
442
|
-
loop do
|
443
|
-
r1 = parse_char_class(/[a-z]/, 'a-z', SyntaxNode)
|
444
|
-
if r1.success?
|
445
|
-
s0 << r1
|
446
|
-
else
|
447
|
-
break
|
448
|
-
end
|
449
|
-
end
|
450
|
-
if s0.empty?
|
451
|
-
self.index = i0
|
452
|
-
r0 = ParseFailure.new(input, i0)
|
453
|
-
else
|
454
|
-
r0 = SyntaxNode.new(input, i0...index, s0)
|
455
|
-
r0.extend(Variable0)
|
456
|
-
end
|
457
|
-
|
458
|
-
node_cache[:variable][start_index] = r0
|
459
|
-
|
460
|
-
return r0
|
461
|
-
end
|
462
|
-
|
463
|
-
module Number0
|
464
|
-
end
|
465
|
-
|
466
|
-
module Number1
|
467
|
-
def eval(env={})
|
468
|
-
text_value.to_i
|
469
|
-
end
|
470
|
-
end
|
471
|
-
|
472
|
-
def _nt_number
|
473
|
-
start_index = index
|
474
|
-
cached = node_cache[:number][index]
|
475
|
-
if cached
|
476
|
-
@index = cached.interval.end
|
477
|
-
return cached
|
478
|
-
end
|
479
|
-
|
480
|
-
i0 = index
|
481
|
-
i1, s1 = index, []
|
482
|
-
r2 = parse_char_class(/[1-9]/, '1-9', SyntaxNode)
|
483
|
-
s1 << r2
|
484
|
-
if r2.success?
|
485
|
-
s3, i3 = [], index
|
486
|
-
loop do
|
487
|
-
r4 = parse_char_class(/[0-9]/, '0-9', SyntaxNode)
|
488
|
-
if r4.success?
|
489
|
-
s3 << r4
|
490
|
-
else
|
491
|
-
break
|
492
|
-
end
|
493
|
-
end
|
494
|
-
r3 = SyntaxNode.new(input, i3...index, s3)
|
495
|
-
s1 << r3
|
496
|
-
end
|
497
|
-
if s1.last.success?
|
498
|
-
r1 = (SyntaxNode).new(input, i1...index, s1)
|
499
|
-
r1.extend(Number0)
|
500
|
-
else
|
501
|
-
self.index = i1
|
502
|
-
r1 = ParseFailure.new(input, i1)
|
503
|
-
end
|
504
|
-
if r1.success?
|
505
|
-
r0 = r1
|
506
|
-
r0.extend(Number1)
|
507
|
-
else
|
508
|
-
r5 = parse_terminal('0', SyntaxNode)
|
509
|
-
if r5.success?
|
510
|
-
r0 = r5
|
511
|
-
r0.extend(Number1)
|
512
|
-
else
|
513
|
-
self.index = i0
|
514
|
-
r0 = ParseFailure.new(input, i0)
|
515
|
-
end
|
516
|
-
end
|
517
|
-
|
518
|
-
node_cache[:number][start_index] = r0
|
519
|
-
|
520
|
-
return r0
|
521
|
-
end
|
522
|
-
|
523
|
-
def _nt_space
|
524
|
-
start_index = index
|
525
|
-
cached = node_cache[:space][index]
|
526
|
-
if cached
|
527
|
-
@index = cached.interval.end
|
528
|
-
return cached
|
529
|
-
end
|
530
|
-
|
531
|
-
s0, i0 = [], index
|
532
|
-
loop do
|
533
|
-
r1 = parse_terminal(' ', SyntaxNode)
|
534
|
-
if r1.success?
|
535
|
-
s0 << r1
|
536
|
-
else
|
537
|
-
break
|
538
|
-
end
|
539
|
-
end
|
540
|
-
r0 = SyntaxNode.new(input, i0...index, s0)
|
541
|
-
|
542
|
-
node_cache[:space][start_index] = r0
|
543
|
-
|
544
|
-
return r0
|
545
|
-
end
|
546
|
-
|
547
|
-
end
|
548
|
-
|
549
|
-
class ArithmeticParser < Treetop::Runtime::CompiledParser
|
550
|
-
include Arithmetic
|
551
|
-
end
|