syntax 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,202 +0,0 @@
1
- $:.unshift File.dirname(__FILE__) +"/../../lib"
2
-
3
- require 'test/unit'
4
- require 'syntax/lang/xml'
5
-
6
- class TC_Syntax_XML < Test::Unit::TestCase
7
-
8
- def setup
9
- @xml = Syntax::XML.new
10
- end
11
-
12
- def test_empty
13
- called = false
14
- @xml.tokenize( "" ) { |tok| called = true }
15
- assert !called
16
- end
17
-
18
- def test_no_tag
19
- tok = []
20
- @xml.tokenize( "foo bar baz" ) { |t| tok << t }
21
- assert_equal [ :normal, "foo bar baz" ], [ tok.first.group, tok.shift ]
22
- end
23
-
24
- def test_entity_outside_tag
25
- tok = []
26
- @xml.tokenize( "&amp; &#10; &x157; &nosemi & foo;" ) { |t| tok << t }
27
- assert_equal [ :entity, "&amp;" ], [ tok.first.group, tok.shift ]
28
- tok.shift
29
- assert_equal [ :entity, "&#10;" ], [ tok.first.group, tok.shift ]
30
- tok.shift
31
- assert_equal [ :entity, "&x157;" ], [ tok.first.group, tok.shift ]
32
- assert_equal [ :normal, " &nosemi & foo;" ], [ tok.first.group, tok.shift ]
33
- end
34
-
35
- def test_start_tag
36
- tok = []
37
- @xml.tokenize( "<name" ) { |t| tok << t }
38
- assert_equal [ :punct, "<" ], [ tok.first.group, tok.shift ]
39
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
40
- end
41
-
42
- def test_start_xml_decl
43
- tok = []
44
- @xml.tokenize( "<?xml" ) { |t| tok << t }
45
- assert_equal [ :punct, "<?" ], [ tok.first.group, tok.shift ]
46
- assert_equal [ :tag, "xml" ], [ tok.first.group, tok.shift ]
47
- end
48
-
49
- def test_start_end_tag
50
- tok = []
51
- @xml.tokenize( "</name" ) { |t| tok << t }
52
- assert_equal [ :punct, "</" ], [ tok.first.group, tok.shift ]
53
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
54
- end
55
-
56
- def test_start_decl_tag
57
- tok = []
58
- @xml.tokenize( "<!name" ) { |t| tok << t }
59
- assert_equal [ :punct, "<!" ], [ tok.first.group, tok.shift ]
60
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
61
- end
62
-
63
- def test_start_confused
64
- tok = []
65
- @xml.tokenize( "<%name" ) { |t| tok << t }
66
- assert_equal [ :punct, "<%" ], [ tok.first.group, tok.shift ]
67
- assert_equal [ :attribute, "name" ], [ tok.first.group, tok.shift ]
68
- end
69
-
70
- def test_end_tag_out_of_context
71
- tok = []
72
- @xml.tokenize( "/>" ) { |t| tok << t }
73
- assert_equal [ :normal, "/>" ], [ tok.first.group, tok.shift ]
74
- end
75
-
76
- def test_start_namespaced_tag
77
- tok = []
78
- @xml.tokenize( "<foo:name" ) { |t| tok << t }
79
- assert_equal [ :punct, "<" ], [ tok.first.group, tok.shift ]
80
- assert_equal [ :namespace, "foo" ], [ tok.first.group, tok.shift ]
81
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
82
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
83
- end
84
-
85
- def test_attribute
86
- tok = []
87
- @xml.tokenize( "<name attr1 attr2" ) { |t| tok << t }
88
- assert_equal [ :punct, "<" ], [ tok.first.group, tok.shift ]
89
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
90
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
91
- assert_equal [ :attribute, "attr1" ], [ tok.first.group, tok.shift ]
92
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
93
- assert_equal [ :attribute, "attr2" ], [ tok.first.group, tok.shift ]
94
- end
95
-
96
- def test_namespaced_attribute
97
- tok = []
98
- @xml.tokenize( "<name foo:attr1 bar:attr2" ) { |t| tok << t }
99
- assert_equal [ :punct, "<" ], [ tok.first.group, tok.shift ]
100
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
101
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
102
- assert_equal [ :namespace, "foo" ], [ tok.first.group, tok.shift ]
103
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
104
- assert_equal [ :attribute, "attr1" ], [ tok.first.group, tok.shift ]
105
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
106
- assert_equal [ :namespace, "bar" ], [ tok.first.group, tok.shift ]
107
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
108
- assert_equal [ :attribute, "attr2" ], [ tok.first.group, tok.shift ]
109
- end
110
-
111
- def test_attribute_with_squote_value
112
- tok = []
113
- @xml.tokenize( "<name attr1='a value < > \\' here'" ) { |t| tok << t }
114
- assert_equal [ :punct, "<" ], [ tok.first.group, tok.shift ]
115
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
116
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
117
- assert_equal [ :attribute, "attr1" ], [ tok.first.group, tok.shift ]
118
- assert_equal [ :punct, "='" ], [ tok.first.group, tok.shift ]
119
- assert_equal [ :string, "a value < > \\' here" ], [ tok.first.group, tok.shift ]
120
- assert_equal [ :punct, "'" ], [ tok.first.group, tok.shift ]
121
- end
122
-
123
- def test_attribute_with_dquote_value
124
- tok = []
125
- @xml.tokenize( '<name attr1="a value < > \" here"' ) { |t| tok << t }
126
- assert_equal [ :punct, "<" ], [ tok.first.group, tok.shift ]
127
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
128
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
129
- assert_equal [ :attribute, "attr1" ], [ tok.first.group, tok.shift ]
130
- assert_equal [ :punct, '="' ], [ tok.first.group, tok.shift ]
131
- assert_equal [ :string, 'a value < > \" here' ], [ tok.first.group, tok.shift ]
132
- assert_equal [ :punct, '"' ], [ tok.first.group, tok.shift ]
133
- end
134
-
135
- def test_entity_in_string
136
- tok = []
137
- @xml.tokenize( '<name "a &lt; value &gt;"' ) { |t| tok << t }
138
- assert_equal [ :punct, "<" ], [ tok.first.group, tok.shift ]
139
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
140
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
141
- assert_equal [ :punct, '"' ], [ tok.first.group, tok.shift ]
142
- assert_equal [ :string, "a " ], [ tok.first.group, tok.shift ]
143
- assert_equal [ :entity, "&lt;" ], [ tok.first.group, tok.shift ]
144
- assert_equal [ :string, " value " ], [ tok.first.group, tok.shift ]
145
- assert_equal [ :entity, "&gt;" ], [ tok.first.group, tok.shift ]
146
- assert_equal [ :punct, '"' ], [ tok.first.group, tok.shift ]
147
- end
148
-
149
- def test_number
150
- tok = []
151
- @xml.tokenize( '<name 5' ) { |t| tok << t }
152
- assert_equal [ :punct, "<" ], [ tok.first.group, tok.shift ]
153
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
154
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
155
- assert_equal [ :number, "5" ], [ tok.first.group, tok.shift ]
156
- end
157
-
158
- def test_close_tag
159
- tok = []
160
- @xml.tokenize( '<name> foo' ) { |t| tok << t }
161
- assert_equal [ :punct, "<" ], [ tok.first.group, tok.shift ]
162
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
163
- assert_equal [ :punct, ">" ], [ tok.first.group, tok.shift ]
164
- assert_equal [ :normal, " foo" ], [ tok.first.group, tok.shift ]
165
- end
166
-
167
- def test_close_self_tag
168
- tok = []
169
- @xml.tokenize( '<name /> foo' ) { |t| tok << t }
170
- assert_equal [ :punct, "<" ], [ tok.first.group, tok.shift ]
171
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
172
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
173
- assert_equal [ :punct, "/>" ], [ tok.first.group, tok.shift ]
174
- assert_equal [ :normal, " foo" ], [ tok.first.group, tok.shift ]
175
- end
176
-
177
- def test_close_decl_tag
178
- tok = []
179
- @xml.tokenize( '<?name ?> foo' ) { |t| tok << t }
180
- assert_equal [ :punct, "<?" ], [ tok.first.group, tok.shift ]
181
- assert_equal [ :tag, "name" ], [ tok.first.group, tok.shift ]
182
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
183
- assert_equal [ :punct, "?>" ], [ tok.first.group, tok.shift ]
184
- assert_equal [ :normal, " foo" ], [ tok.first.group, tok.shift ]
185
- end
186
-
187
- def test_comment
188
- tok = []
189
- @xml.tokenize( "foo <!-- a comment\nspanning multiple\nlines --> bar" ) { |t| tok << t }
190
- assert_equal [ :normal, "foo " ], [ tok.first.group, tok.shift ]
191
- assert_equal [ :comment, "<!-- a comment\nspanning multiple\nlines -->" ], [ tok.first.group, tok.shift ]
192
- assert_equal [ :normal, " bar" ], [ tok.first.group, tok.shift ]
193
- end
194
-
195
- def test_comment_unterminated
196
- tok = []
197
- @xml.tokenize( "foo <!-- a comment\nspanning multiple\nlines -- bar" ) { |t| tok << t }
198
- assert_equal [ :normal, "foo " ], [ tok.first.group, tok.shift ]
199
- assert_equal [ :comment, "<!-- a comment\nspanning multiple\nlines -- bar" ], [ tok.first.group, tok.shift ]
200
- end
201
-
202
- end
@@ -1,228 +0,0 @@
1
- $:.unshift File.dirname(__FILE__) +"/../../lib"
2
-
3
- require 'test/unit'
4
- require 'syntax/lang/yaml'
5
-
6
- class TC_Syntax_YAML < Test::Unit::TestCase
7
-
8
- def setup
9
- @yaml = Syntax::YAML.new
10
- end
11
-
12
- def test_empty
13
- called = false
14
- @yaml.tokenize( "" ) { |tok| called = true }
15
- assert !called
16
- end
17
-
18
- def test_doc_notype
19
- tok = []
20
- @yaml.tokenize( "---\n" ) { |t| tok << t }
21
- assert_equal [ :document, "---" ], [ tok.first.group, tok.shift ]
22
- end
23
-
24
- def test_doc_type
25
- tok = []
26
- @yaml.tokenize( "--- !foo/bar/^type \n" ) { |t| tok << t }
27
- assert_equal [ :document, "--- !foo/bar/^type " ], [ tok.first.group, tok.shift ]
28
- end
29
-
30
- def test_key_no_indent
31
- tok = []
32
- @yaml.tokenize( "foo : bar" ) { |t| tok << t }
33
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
34
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
35
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
36
- assert_equal [ :normal, " bar" ], [ tok.first.group, tok.shift ]
37
- end
38
-
39
- def test_key_indent
40
- tok = []
41
- @yaml.tokenize( " foo : bar" ) { |t| tok << t }
42
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
43
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
44
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
45
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
46
- assert_equal [ :normal, " bar" ], [ tok.first.group, tok.shift ]
47
- end
48
-
49
- def test_key_quoted
50
- tok = []
51
- @yaml.tokenize( " 'foo' : bar" ) { |t| tok << t }
52
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
53
- assert_equal [ :punct, "'" ], [ tok.first.group, tok.shift ]
54
- assert_equal [ :string, "foo" ], [ tok.first.group, tok.shift ]
55
- assert_equal [ :punct, "'" ], [ tok.first.group, tok.shift ]
56
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
57
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
58
- assert_equal [ :normal, " bar" ], [ tok.first.group, tok.shift ]
59
- end
60
-
61
- def test_key_no_value
62
- tok = []
63
- @yaml.tokenize( " foo: \n bar:\n" ) { |t| tok << t }
64
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
65
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
66
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
67
- assert_equal [ :normal, " \n " ], [ tok.first.group, tok.shift ]
68
- assert_equal [ :key, "bar" ], [ tok.first.group, tok.shift ]
69
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
70
- assert_equal [ :normal, "\n" ], [ tok.first.group, tok.shift ]
71
- end
72
-
73
- def test_list_no_indent
74
- tok = []
75
- @yaml.tokenize( "- bar" ) { |t| tok << t }
76
- assert_equal [ :punct, "-" ], [ tok.first.group, tok.shift ]
77
- assert_equal [ :normal, " bar" ], [ tok.first.group, tok.shift ]
78
- end
79
-
80
- def test_list_indent
81
- tok = []
82
- @yaml.tokenize( " - bar" ) { |t| tok << t }
83
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
84
- assert_equal [ :punct, "-" ], [ tok.first.group, tok.shift ]
85
- assert_equal [ :normal, " bar" ], [ tok.first.group, tok.shift ]
86
- end
87
-
88
- def test_blank_lines
89
- tok = []
90
- @yaml.tokenize( "foo: bar\n\n\nbaz: bang" ) { |t| tok << t }
91
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
92
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
93
- assert_equal [ :normal, " bar\n\n\n" ], [ tok.first.group, tok.shift ]
94
- assert_equal [ :key, "baz" ], [ tok.first.group, tok.shift ]
95
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
96
- assert_equal [ :normal, " bang" ], [ tok.first.group, tok.shift ]
97
- end
98
-
99
- def test_type
100
- tok = []
101
- @yaml.tokenize( " - !name/space^type\n - foo" ) { |t| tok << t }
102
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
103
- assert_equal [ :punct, "-" ], [ tok.first.group, tok.shift ]
104
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
105
- assert_equal [ :type, "!name/space^type" ], [ tok.first.group, tok.shift ]
106
- assert_equal [ :normal, "\n " ], [ tok.first.group, tok.shift ]
107
- assert_equal [ :punct, "-" ], [ tok.first.group, tok.shift ]
108
- assert_equal [ :normal, " foo" ], [ tok.first.group, tok.shift ]
109
- end
110
-
111
- def test_anchor_ref
112
- tok = []
113
- @yaml.tokenize( "foo: &blah\nbar: *blah" ) { |t| tok << t }
114
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
115
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
116
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
117
- assert_equal [ :anchor, "&blah" ], [ tok.first.group, tok.shift ]
118
- assert_equal [ :normal, "\n" ], [ tok.first.group, tok.shift ]
119
- assert_equal [ :key, "bar" ], [ tok.first.group, tok.shift ]
120
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
121
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
122
- assert_equal [ :ref, "*blah" ], [ tok.first.group, tok.shift ]
123
- end
124
-
125
- def test_time
126
- tok = []
127
- @yaml.tokenize( "foo: 01:23:45\n" ) { |t| tok << t }
128
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
129
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
130
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
131
- assert_equal [ :time, "01:23:45" ], [ tok.first.group, tok.shift ]
132
- assert_equal [ :normal, "\n" ], [ tok.first.group, tok.shift ]
133
- end
134
-
135
- def test_date
136
- tok = []
137
- @yaml.tokenize( "foo: 1234-56-78 01:23:45.123456 +01:23\n" ) { |t| tok << t }
138
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
139
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
140
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
141
- assert_equal [ :date, "1234-56-78 01:23:45.123456 +01:23" ], [ tok.first.group, tok.shift ]
142
- assert_equal [ :normal, "\n" ], [ tok.first.group, tok.shift ]
143
- end
144
-
145
- def test_string_dquote
146
- tok = []
147
- @yaml.tokenize( 'foo: "this is a \"string\""' ) { |t| tok << t }
148
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
149
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
150
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
151
- assert_equal [ :punct, '"' ], [ tok.first.group, tok.shift ]
152
- assert_equal [ :string, 'this is a ' ], [ tok.first.group, tok.shift ]
153
- assert_equal [ :expr, '\"' ], [ tok.first.group, tok.shift ]
154
- assert_equal [ :string, 'string' ], [ tok.first.group, tok.shift ]
155
- assert_equal [ :expr, '\"' ], [ tok.first.group, tok.shift ]
156
- assert_equal [ :punct, '"' ], [ tok.first.group, tok.shift ]
157
- end
158
-
159
- def test_string_squote
160
- tok = []
161
- @yaml.tokenize( "foo: 'this is a \\\"string\\\"'" ) { |t| tok << t }
162
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
163
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
164
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
165
- assert_equal [ :punct, "'" ], [ tok.first.group, tok.shift ]
166
- assert_equal [ :string, 'this is a \"string\"' ], [ tok.first.group, tok.shift ]
167
- assert_equal [ :punct, "'" ], [ tok.first.group, tok.shift ]
168
- end
169
-
170
- def test_symbol
171
- tok = []
172
- @yaml.tokenize( " :foo: 'this is a \\\"string\\\"'" ) { |t| tok << t }
173
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
174
- assert_equal [ :symbol, ":foo" ], [ tok.first.group, tok.shift ]
175
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
176
- end
177
-
178
- def test_comment
179
- tok = []
180
- @yaml.tokenize( "foo: a value # comment\n# another comment: foo\n" ) { |t| tok << t }
181
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
182
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
183
- assert_equal [ :normal, " a value " ], [ tok.first.group, tok.shift ]
184
- assert_equal [ :comment, "# comment" ], [ tok.first.group, tok.shift ]
185
- assert_equal [ :normal, "\n" ], [ tok.first.group, tok.shift ]
186
- assert_equal [ :comment, "# another comment: foo" ], [ tok.first.group, tok.shift ]
187
- assert_equal [ :normal, "\n" ], [ tok.first.group, tok.shift ]
188
- end
189
-
190
- def test_long_text
191
- tok = []
192
- text = <<EOF
193
- foo: >-
194
- a b c d
195
- e f g
196
-
197
- h i
198
-
199
-
200
- j k l
201
- m n
202
-
203
- bar: baz
204
- EOF
205
- @yaml.tokenize( text ) { |t| tok << t }
206
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
207
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
208
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
209
- assert_equal [ :punct, ">-" ], [ tok.first.group, tok.shift ]
210
- assert_equal [ :normal, "\n" ], [ tok.first.group, tok.shift ]
211
- assert_equal [ :string, " a b c d\n e f g\n\n h i\n\n\n j k l\n m n\n\n" ], [ tok.first.group, tok.shift ]
212
- assert_equal [ :key, "bar" ], [ tok.first.group, tok.shift ]
213
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
214
- assert_equal [ :normal, " baz\n" ], [ tok.first.group, tok.shift ]
215
- end
216
-
217
- def test_long_test_at_eof
218
- tok = []
219
- @yaml.tokenize( "foo: >\n one two\n three four" ) { |t| tok << t }
220
- assert_equal [ :key, "foo" ], [ tok.first.group, tok.shift ]
221
- assert_equal [ :punct, ":" ], [ tok.first.group, tok.shift ]
222
- assert_equal [ :normal, " " ], [ tok.first.group, tok.shift ]
223
- assert_equal [ :punct, ">" ], [ tok.first.group, tok.shift ]
224
- assert_equal [ :normal, "\n" ], [ tok.first.group, tok.shift ]
225
- assert_equal [ :string, " one two\n three four" ], [ tok.first.group, tok.shift ]
226
- end
227
-
228
- end
@@ -1,40 +0,0 @@
1
- $:.unshift File.dirname(__FILE__) + "/../../lib"
2
-
3
- require 'test/unit'
4
- require 'syntax'
5
-
6
- class TokenizerTestCase < Test::Unit::TestCase
7
- def self.syntax( type )
8
- class_eval <<-EOF
9
- def setup
10
- @tokenizer = Syntax.load(#{type.inspect})
11
- end
12
- EOF
13
- end
14
-
15
- def default_test
16
- end
17
-
18
- private
19
-
20
- attr_reader :tokenizer
21
-
22
- def tokenize( string )
23
- @tokens = []
24
- @tokenizer.tokenize( string ) { |tok| @tokens << tok }
25
- end
26
-
27
- def assert_next_token(group, lexeme, instruction=:none)
28
- assert false, "no tokens in stack" if @tokens.nil? or @tokens.empty?
29
- assert_equal [group, lexeme, instruction],
30
- [@tokens.first.group, @tokens.first, @tokens.shift.instruction]
31
- end
32
-
33
- def assert_no_next_token
34
- assert @tokens.empty?
35
- end
36
-
37
- def skip_token( n=1 )
38
- n.times { @tokens.shift } unless @tokens.nil? || @tokens.empty?
39
- end
40
- end