less 1.1.13 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/Rakefile +13 -41
  2. data/VERSION +1 -1
  3. data/bin/lessc +8 -2
  4. data/less.gemspec +13 -92
  5. data/lib/ext.rb +15 -19
  6. data/lib/less.rb +2 -2
  7. data/lib/less/command.rb +14 -15
  8. data/lib/less/engine.rb +3 -2
  9. data/lib/less/engine/grammar/common.tt +1 -1
  10. data/lib/less/engine/grammar/entity.tt +5 -5
  11. data/lib/less/engine/grammar/less.tt +107 -77
  12. data/lib/less/engine/nodes/element.rb +103 -24
  13. data/lib/less/engine/nodes/entity.rb +3 -3
  14. data/lib/less/engine/nodes/function.rb +11 -6
  15. data/lib/less/engine/nodes/literal.rb +8 -4
  16. data/lib/less/engine/nodes/property.rb +98 -38
  17. data/lib/less/engine/nodes/selector.rb +1 -1
  18. data/spec/css/css-3.css +14 -0
  19. data/spec/css/mixins-args.css +31 -0
  20. data/spec/css/variables.css +1 -0
  21. data/spec/css/whitespace.css +1 -0
  22. data/spec/engine_spec.rb +4 -3
  23. data/spec/less/css-3.less +30 -0
  24. data/spec/less/hidden.less +25 -0
  25. data/spec/less/import.less +1 -0
  26. data/spec/less/literal-css.less +11 -0
  27. data/spec/less/mixins-args.less +50 -0
  28. data/spec/less/variables.less +7 -1
  29. data/spec/less/whitespace.less +1 -0
  30. data/spec/spec_helper.rb +2 -2
  31. metadata +25 -94
  32. data/lib/vendor/treetop/.gitignore +0 -7
  33. data/lib/vendor/treetop/LICENSE +0 -19
  34. data/lib/vendor/treetop/README +0 -164
  35. data/lib/vendor/treetop/Rakefile +0 -19
  36. data/lib/vendor/treetop/benchmark/seqpar.gnuplot +0 -15
  37. data/lib/vendor/treetop/benchmark/seqpar.treetop +0 -16
  38. data/lib/vendor/treetop/benchmark/seqpar_benchmark.rb +0 -107
  39. data/lib/vendor/treetop/bin/tt +0 -28
  40. data/lib/vendor/treetop/lib/treetop.rb +0 -8
  41. data/lib/vendor/treetop/lib/treetop/bootstrap_gen_1_metagrammar.rb +0 -45
  42. data/lib/vendor/treetop/lib/treetop/compiler.rb +0 -6
  43. data/lib/vendor/treetop/lib/treetop/compiler/grammar_compiler.rb +0 -42
  44. data/lib/vendor/treetop/lib/treetop/compiler/lexical_address_space.rb +0 -17
  45. data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.rb +0 -3097
  46. data/lib/vendor/treetop/lib/treetop/compiler/metagrammar.treetop +0 -408
  47. data/lib/vendor/treetop/lib/treetop/compiler/node_classes.rb +0 -19
  48. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/anything_symbol.rb +0 -18
  49. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/atomic_expression.rb +0 -14
  50. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb +0 -24
  51. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/choice.rb +0 -31
  52. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/declaration_sequence.rb +0 -24
  53. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/grammar.rb +0 -28
  54. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/inline_module.rb +0 -27
  55. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/nonterminal.rb +0 -13
  56. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/optional.rb +0 -19
  57. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parenthesized_expression.rb +0 -9
  58. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_expression.rb +0 -138
  59. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_rule.rb +0 -55
  60. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/predicate.rb +0 -45
  61. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/repetition.rb +0 -55
  62. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/sequence.rb +0 -68
  63. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/terminal.rb +0 -20
  64. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/transient_prefix.rb +0 -9
  65. data/lib/vendor/treetop/lib/treetop/compiler/node_classes/treetop_file.rb +0 -9
  66. data/lib/vendor/treetop/lib/treetop/compiler/ruby_builder.rb +0 -113
  67. data/lib/vendor/treetop/lib/treetop/ruby_extensions.rb +0 -2
  68. data/lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb +0 -42
  69. data/lib/vendor/treetop/lib/treetop/runtime.rb +0 -5
  70. data/lib/vendor/treetop/lib/treetop/runtime/compiled_parser.rb +0 -105
  71. data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list.rb +0 -4
  72. data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/head_node.rb +0 -15
  73. data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb +0 -200
  74. data/lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/node.rb +0 -164
  75. data/lib/vendor/treetop/lib/treetop/runtime/syntax_node.rb +0 -72
  76. data/lib/vendor/treetop/lib/treetop/runtime/terminal_parse_failure.rb +0 -16
  77. data/lib/vendor/treetop/lib/treetop/runtime/terminal_syntax_node.rb +0 -17
  78. data/lib/vendor/treetop/lib/treetop/version.rb +0 -9
  79. data/lib/vendor/treetop/spec/compiler/and_predicate_spec.rb +0 -36
  80. data/lib/vendor/treetop/spec/compiler/anything_symbol_spec.rb +0 -44
  81. data/lib/vendor/treetop/spec/compiler/character_class_spec.rb +0 -182
  82. data/lib/vendor/treetop/spec/compiler/choice_spec.rb +0 -80
  83. data/lib/vendor/treetop/spec/compiler/circular_compilation_spec.rb +0 -28
  84. data/lib/vendor/treetop/spec/compiler/failure_propagation_functional_spec.rb +0 -21
  85. data/lib/vendor/treetop/spec/compiler/grammar_compiler_spec.rb +0 -84
  86. data/lib/vendor/treetop/spec/compiler/grammar_spec.rb +0 -41
  87. data/lib/vendor/treetop/spec/compiler/nonterminal_symbol_spec.rb +0 -40
  88. data/lib/vendor/treetop/spec/compiler/not_predicate_spec.rb +0 -38
  89. data/lib/vendor/treetop/spec/compiler/one_or_more_spec.rb +0 -35
  90. data/lib/vendor/treetop/spec/compiler/optional_spec.rb +0 -37
  91. data/lib/vendor/treetop/spec/compiler/parenthesized_expression_spec.rb +0 -19
  92. data/lib/vendor/treetop/spec/compiler/parsing_rule_spec.rb +0 -32
  93. data/lib/vendor/treetop/spec/compiler/sequence_spec.rb +0 -115
  94. data/lib/vendor/treetop/spec/compiler/terminal_spec.rb +0 -81
  95. data/lib/vendor/treetop/spec/compiler/terminal_symbol_spec.rb +0 -37
  96. data/lib/vendor/treetop/spec/compiler/test_grammar.treetop +0 -7
  97. data/lib/vendor/treetop/spec/compiler/test_grammar.tt +0 -7
  98. data/lib/vendor/treetop/spec/compiler/test_grammar_do.treetop +0 -7
  99. data/lib/vendor/treetop/spec/compiler/zero_or_more_spec.rb +0 -56
  100. data/lib/vendor/treetop/spec/composition/a.treetop +0 -11
  101. data/lib/vendor/treetop/spec/composition/b.treetop +0 -11
  102. data/lib/vendor/treetop/spec/composition/c.treetop +0 -10
  103. data/lib/vendor/treetop/spec/composition/d.treetop +0 -10
  104. data/lib/vendor/treetop/spec/composition/f.treetop +0 -17
  105. data/lib/vendor/treetop/spec/composition/grammar_composition_spec.rb +0 -40
  106. data/lib/vendor/treetop/spec/composition/subfolder/e_includes_c.treetop +0 -15
  107. data/lib/vendor/treetop/spec/ruby_extensions/string_spec.rb +0 -32
  108. data/lib/vendor/treetop/spec/runtime/compiled_parser_spec.rb +0 -101
  109. data/lib/vendor/treetop/spec/runtime/interval_skip_list/delete_spec.rb +0 -147
  110. data/lib/vendor/treetop/spec/runtime/interval_skip_list/expire_range_spec.rb +0 -349
  111. data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_and_delete_node.rb +0 -385
  112. data/lib/vendor/treetop/spec/runtime/interval_skip_list/insert_spec.rb +0 -660
  113. data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +0 -6175
  114. data/lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +0 -58
  115. data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture.rb +0 -23
  116. data/lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +0 -164
  117. data/lib/vendor/treetop/spec/runtime/interval_skip_list/spec_helper.rb +0 -84
  118. data/lib/vendor/treetop/spec/runtime/syntax_node_spec.rb +0 -53
  119. data/lib/vendor/treetop/spec/spec_helper.rb +0 -106
  120. data/lib/vendor/treetop/spec/spec_suite.rb +0 -4
  121. data/lib/vendor/treetop/treetop.gemspec +0 -17
@@ -0,0 +1,25 @@
1
+ .hidden {
2
+ color: transparent;
3
+ .inside {
4
+ width: 0%;
5
+ }
6
+ };
7
+
8
+ .fully-hidden {
9
+ color: none;
10
+ };
11
+
12
+ .visible {
13
+ width: 100%;
14
+ .hidden {
15
+ color: black;
16
+ };
17
+ }
18
+
19
+ .mix {
20
+ .hidden;
21
+ }
22
+
23
+ .mix2 {
24
+ .visible;
25
+ }
@@ -1,4 +1,5 @@
1
1
  @import url("import/import-test-a.less");
2
+ @import url("import/import-test-a.less");
2
3
 
3
4
  #import-test {
4
5
  .mixin;
@@ -0,0 +1,11 @@
1
+ % {
2
+ @var: 2px;
3
+ #literal {
4
+ width: 2px * 2;
5
+ }
6
+ @media {
7
+ #nested {
8
+ color: red;
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,50 @@
1
+ .mixin (@a: 1px, @b: 50%) {
2
+ width: @a * 5;
3
+ height: @b - 1%;
4
+ }
5
+
6
+ .mixiny
7
+ (@a: 0, @b: 0) {
8
+ margin: @a;
9
+ padding: @b;
10
+ }
11
+
12
+ .hidden() {
13
+ color: transparent;
14
+ }
15
+
16
+ .two-args {
17
+ color: blue;
18
+ .mixin(2px, 100%);
19
+ }
20
+
21
+ .one-arg {
22
+ .mixin(3px);
23
+ }
24
+
25
+ .no-parens {
26
+ .mixin;
27
+ }
28
+
29
+ .no-args {
30
+ .mixin();
31
+ }
32
+
33
+ .var-args {
34
+ @var: 9;
35
+ .mixin(@var, @var * 2);
36
+ }
37
+
38
+ .multi-mix {
39
+ .mixin(2px, 30%);
40
+ .mixiny(4, 5);
41
+ }
42
+
43
+ .maxa(@arg1: 10, @arg2: #f00) {
44
+ padding: @arg1 * 2px;
45
+ color: @arg2;
46
+ }
47
+
48
+ body {
49
+ .maxa(15);
50
+ }
@@ -9,10 +9,16 @@
9
9
 
10
10
  @b: @a * 10;
11
11
  @c: #888;
12
+
12
13
  @fonts: "Trebuchet MS", Verdana, sans-serif;
14
+ @f: @fonts;
15
+
16
+ @quotes: "~" "~";
17
+ @q: @quotes;
13
18
 
14
19
  .variables {
15
20
  height: @b + @x + 0px; // 24px
16
21
  color: @c;
17
- font-family: @fonts;
22
+ font-family: @f;
23
+ quotes: @q;
18
24
  }
@@ -23,6 +23,7 @@
23
23
  color: white;
24
24
  white-space: pre
25
25
  }
26
+ .no-semi-column {border: 2px solid white}
26
27
  .newlines {
27
28
  border: 2px
28
29
  solid
@@ -1,8 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'spec'
3
3
 
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
- $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+ $:.unshift File.dirname(__FILE__)
6
6
 
7
7
  require 'less'
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: less
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.13
4
+ version: 1.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - cloudhead
@@ -9,10 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-11 00:00:00 +02:00
12
+ date: 2009-10-12 00:00:00 -04:00
13
13
  default_executable: lessc
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: treetop
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mutter
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.7
34
+ version:
16
35
  description: LESS is leaner CSS
17
36
  email: self@cloudhead.net
18
37
  executables:
@@ -46,96 +65,6 @@ files:
46
65
  - lib/less/engine/nodes/property.rb
47
66
  - lib/less/engine/nodes/ruleset.rb
48
67
  - lib/less/engine/nodes/selector.rb
49
- - lib/vendor/treetop/.gitignore
50
- - lib/vendor/treetop/LICENSE
51
- - lib/vendor/treetop/README
52
- - lib/vendor/treetop/Rakefile
53
- - lib/vendor/treetop/benchmark/seqpar.gnuplot
54
- - lib/vendor/treetop/benchmark/seqpar.treetop
55
- - lib/vendor/treetop/benchmark/seqpar_benchmark.rb
56
- - lib/vendor/treetop/bin/tt
57
- - lib/vendor/treetop/lib/treetop.rb
58
- - lib/vendor/treetop/lib/treetop/bootstrap_gen_1_metagrammar.rb
59
- - lib/vendor/treetop/lib/treetop/compiler.rb
60
- - lib/vendor/treetop/lib/treetop/compiler/grammar_compiler.rb
61
- - lib/vendor/treetop/lib/treetop/compiler/lexical_address_space.rb
62
- - lib/vendor/treetop/lib/treetop/compiler/metagrammar.rb
63
- - lib/vendor/treetop/lib/treetop/compiler/metagrammar.treetop
64
- - lib/vendor/treetop/lib/treetop/compiler/node_classes.rb
65
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/anything_symbol.rb
66
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/atomic_expression.rb
67
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/character_class.rb
68
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/choice.rb
69
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/declaration_sequence.rb
70
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/grammar.rb
71
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/inline_module.rb
72
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/nonterminal.rb
73
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/optional.rb
74
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/parenthesized_expression.rb
75
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_expression.rb
76
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/parsing_rule.rb
77
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/predicate.rb
78
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/repetition.rb
79
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/sequence.rb
80
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/terminal.rb
81
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/transient_prefix.rb
82
- - lib/vendor/treetop/lib/treetop/compiler/node_classes/treetop_file.rb
83
- - lib/vendor/treetop/lib/treetop/compiler/ruby_builder.rb
84
- - lib/vendor/treetop/lib/treetop/ruby_extensions.rb
85
- - lib/vendor/treetop/lib/treetop/ruby_extensions/string.rb
86
- - lib/vendor/treetop/lib/treetop/runtime.rb
87
- - lib/vendor/treetop/lib/treetop/runtime/compiled_parser.rb
88
- - lib/vendor/treetop/lib/treetop/runtime/interval_skip_list.rb
89
- - lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/head_node.rb
90
- - lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/interval_skip_list.rb
91
- - lib/vendor/treetop/lib/treetop/runtime/interval_skip_list/node.rb
92
- - lib/vendor/treetop/lib/treetop/runtime/syntax_node.rb
93
- - lib/vendor/treetop/lib/treetop/runtime/terminal_parse_failure.rb
94
- - lib/vendor/treetop/lib/treetop/runtime/terminal_syntax_node.rb
95
- - lib/vendor/treetop/lib/treetop/version.rb
96
- - lib/vendor/treetop/spec/compiler/and_predicate_spec.rb
97
- - lib/vendor/treetop/spec/compiler/anything_symbol_spec.rb
98
- - lib/vendor/treetop/spec/compiler/character_class_spec.rb
99
- - lib/vendor/treetop/spec/compiler/choice_spec.rb
100
- - lib/vendor/treetop/spec/compiler/circular_compilation_spec.rb
101
- - lib/vendor/treetop/spec/compiler/failure_propagation_functional_spec.rb
102
- - lib/vendor/treetop/spec/compiler/grammar_compiler_spec.rb
103
- - lib/vendor/treetop/spec/compiler/grammar_spec.rb
104
- - lib/vendor/treetop/spec/compiler/nonterminal_symbol_spec.rb
105
- - lib/vendor/treetop/spec/compiler/not_predicate_spec.rb
106
- - lib/vendor/treetop/spec/compiler/one_or_more_spec.rb
107
- - lib/vendor/treetop/spec/compiler/optional_spec.rb
108
- - lib/vendor/treetop/spec/compiler/parenthesized_expression_spec.rb
109
- - lib/vendor/treetop/spec/compiler/parsing_rule_spec.rb
110
- - lib/vendor/treetop/spec/compiler/sequence_spec.rb
111
- - lib/vendor/treetop/spec/compiler/terminal_spec.rb
112
- - lib/vendor/treetop/spec/compiler/terminal_symbol_spec.rb
113
- - lib/vendor/treetop/spec/compiler/test_grammar.treetop
114
- - lib/vendor/treetop/spec/compiler/test_grammar.tt
115
- - lib/vendor/treetop/spec/compiler/test_grammar_do.treetop
116
- - lib/vendor/treetop/spec/compiler/zero_or_more_spec.rb
117
- - lib/vendor/treetop/spec/composition/a.treetop
118
- - lib/vendor/treetop/spec/composition/b.treetop
119
- - lib/vendor/treetop/spec/composition/c.treetop
120
- - lib/vendor/treetop/spec/composition/d.treetop
121
- - lib/vendor/treetop/spec/composition/f.treetop
122
- - lib/vendor/treetop/spec/composition/grammar_composition_spec.rb
123
- - lib/vendor/treetop/spec/composition/subfolder/e_includes_c.treetop
124
- - lib/vendor/treetop/spec/ruby_extensions/string_spec.rb
125
- - lib/vendor/treetop/spec/runtime/compiled_parser_spec.rb
126
- - lib/vendor/treetop/spec/runtime/interval_skip_list/delete_spec.rb
127
- - lib/vendor/treetop/spec/runtime/interval_skip_list/expire_range_spec.rb
128
- - lib/vendor/treetop/spec/runtime/interval_skip_list/insert_and_delete_node.rb
129
- - lib/vendor/treetop/spec/runtime/interval_skip_list/insert_spec.rb
130
- - lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle
131
- - lib/vendor/treetop/spec/runtime/interval_skip_list/interval_skip_list_spec.rb
132
- - lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture.rb
133
- - lib/vendor/treetop/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb
134
- - lib/vendor/treetop/spec/runtime/interval_skip_list/spec_helper.rb
135
- - lib/vendor/treetop/spec/runtime/syntax_node_spec.rb
136
- - lib/vendor/treetop/spec/spec_helper.rb
137
- - lib/vendor/treetop/spec/spec_suite.rb
138
- - lib/vendor/treetop/treetop.gemspec
139
68
  - spec/command_spec.rb
140
69
  - spec/css/accessors.css
141
70
  - spec/css/big.css
@@ -167,12 +96,14 @@ files:
167
96
  - spec/less/exceptions/name-error-1.0.less
168
97
  - spec/less/exceptions/syntax-error-1.0.less
169
98
  - spec/less/functions.less
99
+ - spec/less/hidden.less
170
100
  - spec/less/import.less
171
101
  - spec/less/import/import-test-a.less
172
102
  - spec/less/import/import-test-b.less
173
103
  - spec/less/import/import-test-c.less
174
104
  - spec/less/import/import-test-d.css
175
105
  - spec/less/lazy-eval.less
106
+ - spec/less/literal-css.less
176
107
  - spec/less/mixins-args.less
177
108
  - spec/less/mixins.less
178
109
  - spec/less/operations.less
@@ -1,7 +0,0 @@
1
- *.gem
2
- *.iml
3
- *.iws
4
- *.ipr
5
- doc/site/*.*
6
- benchmark/*.dat
7
- benchmark/*.log
@@ -1,19 +0,0 @@
1
- Copyright (c) 2007 Nathan Sobo.
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
@@ -1,164 +0,0 @@
1
- Tutorial
2
- ========
3
- Languages can be split into two components, their *syntax* and their *semantics*. It's your understanding of English syntax that tells you the stream of words "Sleep furiously green ideas colorless" is not a valid sentence. Semantics is deeper. Even if we rearrange the above sentence to be "Colorless green ideas sleep furiously", which is syntactically correct, it remains nonsensical on a semantic level. With Treetop, you'll be dealing with languages that are much simpler than English, but these basic concepts apply. Your programs will need to address both the syntax and the semantics of the languages they interpret.
4
-
5
- Treetop equips you with powerful tools for each of these two aspects of interpreter writing. You'll describe the syntax of your language with a *parsing expression grammar*. From this description, Treetop will generate a Ruby parser that transforms streams of characters written into your language into *abstract syntax trees* representing their structure. You'll then describe the semantics of your language in Ruby by defining methods on the syntax trees the parser generates.
6
-
7
- Parsing Expression Grammars, The Basics
8
- =======================================
9
- The first step in using Treetop is defining a grammar in a file with the `.treetop` extension. Here's a grammar that's useless because it's empty:
10
-
11
- # my_grammar.treetop
12
- grammar MyGrammar
13
- end
14
-
15
- Next, you start filling your grammar with rules. Each rule associates a name with a parsing expression, like the following:
16
-
17
- # my_grammar.treetop
18
- # You can use a .tt extension instead if you wish
19
- grammar MyGrammar
20
- rule hello
21
- 'hello chomsky'
22
- end
23
- end
24
-
25
- The first rule becomes the *root* of the grammar, causing its expression to be matched when a parser for the grammar is fed a string. The above grammar can now be used in a Ruby program. Notice how a string matching the first rule parses successfully, but a second nonmatching string does not.
26
-
27
- # use_grammar.rb
28
- require 'rubygems'
29
- require 'treetop'
30
- Treetop.load 'my_grammar'
31
- # or just:
32
- # require 'my_grammar' # This works because Polyglot hooks "require" to find and load Treetop files
33
-
34
- parser = MyGrammarParser.new
35
- puts parser.parse('hello chomsky') # => Treetop::Runtime::SyntaxNode
36
- puts parser.parse('silly generativists!') # => nil
37
-
38
- Users of *regular expressions* will find parsing expressions familiar. They share the same basic purpose, matching strings against patterns. However, parsing expressions can recognize a broader category of languages than their less expressive brethren. Before we get into demonstrating that, lets cover some basics. At first parsing expressions won't seem much different. Trust that they are.
39
-
40
- Terminal Symbols
41
- ----------------
42
- The expression in the grammar above is a terminal symbol. It will only match a string that matches it exactly. There are two other kinds of terminal symbols, which we'll revisit later. Terminals are called *atomic expressions* because they aren't composed of smaller expressions.
43
-
44
- Ordered Choices
45
- ---------------
46
- Ordered choices are *composite expressions*, which allow for any of several subexpressions to be matched. These should be familiar from regular expressions, but in parsing expressions, they are delimited by the `/` character. Its important to note that the choices are prioritized in the order they appear. If an earlier expression is matched, no subsequent expressions are tried. Here's an example:
47
-
48
- # my_grammar.treetop
49
- grammar MyGrammar
50
- rule hello
51
- 'hello chomsky' / 'hello lambek'
52
- end
53
- end
54
-
55
- # fragment of use_grammar.rb
56
- puts parser.parse('hello chomsky') # => Treetop::Runtime::SyntaxNode
57
- puts parser.parse('hello lambek') # => Treetop::Runtime::SyntaxNode
58
- puts parser.parse('silly generativists!') # => nil
59
-
60
- Note that once a choice rule has matched the text using a particular alternative at a particular location in the input and hence has succeeded, that choice will never be reconsidered, even if the chosen alternative causes another rule to fail where a later alternative wouldn't have. It's always a later alternative, since the first to succeed is final - why keep looking when you've found what you wanted? This is a feature of PEG parsers that you need to understand if you're going to succeed in using Treetop. In order to memoize success and failures, such decisions cannot be reversed. Luckily Treetop provides a variety of clever ways you can tell it to avoid making the wrong decisions. But more on that later.
61
-
62
- Sequences
63
- ---------
64
- Sequences are composed of other parsing expressions separated by spaces. Using sequences, we can tighten up the above grammar.
65
-
66
- # my_grammar.treetop
67
- grammar MyGrammar
68
- rule hello
69
- 'hello ' ('chomsky' / 'lambek')
70
- end
71
- end
72
-
73
- Note the use of parentheses to override the default precedence rules, which bind sequences more tightly than choices.
74
-
75
- Once the whole sequence has been matched, the result is memoized and the details of the match will not be reconsidered for that location in the input.
76
-
77
- Nonterminal Symbols
78
- -------------------
79
- Here we leave regular expressions behind. Nonterminals allow expressions to refer to other expressions by name. A trivial use of this facility would allow us to make the above grammar more readable should the list of names grow longer.
80
-
81
- # my_grammar.treetop
82
- grammar MyGrammar
83
- rule hello
84
- 'hello ' linguist
85
- end
86
-
87
- rule linguist
88
- 'chomsky' / 'lambek' / 'jacobsen' / 'frege'
89
- end
90
- end
91
-
92
- The true power of this facility, however, is unleashed when writing *recursive expressions*. Here is a self-referential expression that can match any number of open parentheses followed by any number of closed parentheses. This is theoretically impossible with regular expressions due to the *pumping lemma*.
93
-
94
- # parentheses.treetop
95
- grammar Parentheses
96
- rule parens
97
- '(' parens ')' / ''
98
- end
99
- end
100
-
101
-
102
- The `parens` expression simply states that a `parens` is a set of parentheses surrounding another `parens` expression or, if that doesn't match, the empty string. If you are uncomfortable with recursion, its time to get comfortable, because it is the basis of language. Here's a tip: Don't try and imagine the parser circling round and round through the same rule. Instead, imagine the rule is *already* defined while you are defining it. If you imagine that `parens` already matches a string of matching parentheses, then its easy to think of `parens` as an open and closing parentheses around another set of matching parentheses, which conveniently, you happen to be defining. You know that `parens` is supposed to represent a string of matched parentheses, so trust in that meaning, even if you haven't fully implemented it yet.
103
-
104
- Repetition
105
- ----------
106
- Any item in a rule may be followed by a '+' or a '*' character, signifying one-or-more and zero-or-more occurrences of that item. Beware though; the match is greedy, and if it matches too many items and causes subsequent items in the sequence to fail, the number matched will never be reconsidered. Here's a simple example of a rule that will never succeed:
107
-
108
- # toogreedy.treetop
109
- grammar TooGreedy
110
- rule a_s
111
- 'a'* 'a'
112
- end
113
- end
114
-
115
- The 'a'* will always eat up any 'a's that follow, and the subsequent 'a' will find none there, so the whole rule will fail. You might need to use lookahead to avoid matching too much.
116
-
117
- Negative Lookahead
118
- ------------------
119
-
120
- When you need to ensure that the following item *doesn't* match in some case where it might otherwise, you can use negat!ve lookahead, which is an item preceeded by a ! - here's an example:
121
-
122
- # postcondition.treetop
123
- grammar PostCondition
124
- rule conditional_sentence
125
- ( !conditional_keyword word )+ conditional_keyword [ \t]+ word*
126
- end
127
-
128
- rule word
129
- ([a-zA-Z]+ [ \t]+)
130
- end
131
-
132
- rule conditional_keyword
133
- 'if' / 'while' / 'until'
134
- end
135
- end
136
-
137
- Even though the rule `word` would match any of the conditional keywords, the first words of a conditional_sentence must not be conditional_keywords. The negative lookahead prevents that matching, and prevents the repetition from matching too much input. Note that the lookahead may be a grammar rule of any complexity, including one that isn't used elsewhere in your grammar.
138
-
139
- Positive lookahead
140
- ------------------
141
-
142
- Sometimes you want an item to match, but only if the *following* text would match some pattern. You don't want to consume that following text, but if it's not there, you want this rule to fail. You can append a positive lookahead like this to a rule by appending the lookahead rule preceeded by an & character.
143
-
144
-
145
-
146
- Features to cover in the talk
147
- =============================
148
-
149
- * Treetop files
150
- * Grammar definition
151
- * Rules
152
- * Loading a grammar
153
- * Compiling a grammar with the `tt` command
154
- * Accessing a parser for the grammar from Ruby
155
- * Parsing Expressions of all kinds
156
- ? Left recursion and factorization
157
- - Here I can talk about function application, discussing how the operator
158
- could be an arbitrary expression
159
- * Inline node class eval blocks
160
- * Node class declarations
161
- * Labels
162
- * Use of super within within labels
163
- * Grammar composition with include
164
- * Use of super with grammar composition