push
travis-ci
7204 of 7992 relevant lines covered (90.14%)
151042.75 hits per line
1 |
# encoding: UTF-8
|
|
2 |
|
|
3 |
# Copyright 2012 Twitter, Inc
|
|
4 |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
5 |
|
|
6 |
module TwitterCldr |
7✔ |
7 |
module Parsers |
7✔ |
8 |
|
|
9 |
class UnexpectedTokenError < StandardError; end |
7✔ |
10 |
|
|
11 |
# base class, not meant to be instantiated
|
|
12 |
class Parser |
7✔ |
13 |
|
|
14 |
def parse(tokens, options = {}) |
7✔ |
15 |
@tokens = tokens
|
28,553✔ |
16 |
reset |
28,553✔ |
17 |
do_parse(options) |
28,553✔ |
18 |
end
|
|
19 |
|
|
20 |
def reset |
7✔ |
21 |
@token_index = 0 |
28,553✔ |
22 |
end
|
|
23 |
|
|
24 |
private |
7✔ |
25 |
|
|
26 |
def next_token(type) |
7✔ |
27 |
unless current_token.type == type
|
91,938✔ |
28 |
raise UnexpectedTokenError.new("Unexpected token #{current_token.type} \"#{current_token.value}\"") |
× |
29 |
end
|
|
30 |
|
|
31 |
@token_index += 1 |
91,938✔ |
32 |
|
|
33 |
while current_token && empty?(current_token)
|
91,938✔ |
34 |
@token_index += 1 |
× |
35 |
end
|
|
36 |
|
|
37 |
current_token |
91,938✔ |
38 |
end
|
|
39 |
|
|
40 |
def empty?(token) |
7✔ |
41 |
token.type == :plaintext && token.value == "" |
91,938✔ |
42 |
end
|
|
43 |
|
|
44 |
def current_token |
7✔ |
45 |
@tokens[@token_index] |
631,673✔ |
46 |
end
|
|
47 |
end
|
|
48 |
|
|
49 |
end
|
|
50 |
end
|