| 1 |
|
| 2 |
|
| 3 |
module Prism |
| 4 |
module Translation |
| 5 |
class Ripper |
| 6 |
class Filter |
| 7 |
|
| 8 |
def initialize(src, filename = '-', lineno = 1) |
| 9 |
@__lexer = Lexer.new(src, filename, lineno) |
| 10 |
@__line = nil |
| 11 |
@__col = nil |
| 12 |
@__state = nil |
| 13 |
end |
| 14 |
|
| 15 |
def filename |
| 16 |
@__lexer.filename |
| 17 |
end |
| 18 |
|
| 19 |
def lineno |
| 20 |
@__line |
| 21 |
end |
| 22 |
|
| 23 |
def column |
| 24 |
@__col |
| 25 |
end |
| 26 |
|
| 27 |
def state |
| 28 |
@__state |
| 29 |
end |
| 30 |
|
| 31 |
def parse(init = nil) |
| 32 |
data = init |
| 33 |
@__lexer.lex.each do |pos, event, tok, state| |
| 34 |
@__line, @__col = *pos |
| 35 |
@__state = state |
| 36 |
data = if respond_to?(event, true) |
| 37 |
then __send__(event, tok, data) |
| 38 |
else on_default(event, tok, data) |
| 39 |
end |
| 40 |
end |
| 41 |
data |
| 42 |
end |
| 43 |
|
| 44 |
private |
| 45 |
|
| 46 |
def on_default(event, token, data) |
| 47 |
data |
| 48 |
end |
| 49 |
|
| 50 |
end |
| 51 |
end |
| 52 |
end |
| 53 |
end |