-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathtokenizeradapter.rb
More file actions
76 lines (60 loc) · 1.46 KB
/
tokenizeradapter.rb
File metadata and controls
76 lines (60 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# The purpose of this class is to serve as an adapter between the
# ShuntingYard component, the Tokenizer, and the Parser.
# The reason for this is that a number of tokens indicate
# a need to call back into the parser, but the ShuntingYard
# class only need to know that what is returned is not an operator
# it should be concerned about
class TokenizerAdapter
def initialize(tokenizer, parser)
@tokenizer = tokenizer
@parser = parser
@escape_tokens = {
:stabby_lambda => :parse_stabby_lambda,
:case => :parse_case
}
end
def each
@tokenizer.each do |token, op, keyword|
if keyword and (m = @escape_tokens[token])
@tokenizer.unget(token)
ss = @parser.send(m)
yield(ss, nil, nil)
else
yield(token,op,keyword)
end
end
end
def get_quoted_exp(unget=:unget)
@tokenizer.get_quoted_exp(unget)
end
def ws
@tokenizer.ws
end
def nolfws
@tokenizer.nolfws
end
def unget token
@tokenizer.unget(token)
end
def lasttoken
@tokenizer.lasttoken
end
def newline_before_current
@tokenizer.newline_before_current
end
def newline_before_current=(value)
@tokenizer.newline_before_current = value
end
def at_newline
@tokenizer.at_newline
end
def last_ws_consumed_newline
@tokenizer.last_ws_consumed_newline
end
def had_ws_before_token
@tokenizer.scanner.had_ws_before_token
end
def scanner
@tokenizer.scanner
end
end