Fix parser termination condition; add --ast flag. Now, methods...
Cat's Eye Technologies
12 years ago
47 | 47 |
|
48 | 48 |
def expr
|
49 | 49 |
debug "parsing Expr production"
|
50 | |
if @scanner.type == 'EOF'
|
|
50 |
if (['EOL', 'EOF'].include? @scanner.type or [')', ','].include? @scanner.text)
|
51 | 51 |
return nil
|
52 | 52 |
end
|
53 | 53 |
receiver = base # could be Expr, StringLit, Arg
|
54 | |
if @scanner.type == 'EOF'
|
|
54 |
if (['EOL', 'EOF'].include? @scanner.type or [')', ','].include? @scanner.text)
|
55 | 55 |
return receiver
|
56 | 56 |
end
|
57 | 57 |
while @scanner.consume '.'
|
|
67 | 67 |
# lookup(a, b).set(c, foo)
|
68 | 68 |
debug "unlookuping"
|
69 | 69 |
ident = nil
|
70 | |
if receiver.instance_of? Lookup
|
|
70 |
if receiver.is_a? Lookup
|
71 | 71 |
ident = receiver.ident
|
72 | 72 |
receiver = receiver.receiver
|
73 | 73 |
else
|
6 | 6 |
|
7 | 7 |
############ Main ############
|
8 | 8 |
|
|
9 |
ast = false
|
9 | 10 |
ARGV.each do |arg|
|
10 | 11 |
if arg == '--debug'
|
11 | 12 |
$debug = true
|
|
13 |
next
|
|
14 |
end
|
|
15 |
if arg == '--ast'
|
|
16 |
ast = true
|
12 | 17 |
next
|
13 | 18 |
end
|
14 | 19 |
File.open(arg, 'r') do |f|
|
|
18 | 23 |
end
|
19 | 24 |
p = Parser.new(text)
|
20 | 25 |
s = p.script
|
21 | |
o = VeloObject.new 'main-script'
|
22 | |
s.eval o, [] # XXX could pass command-line arguments here...
|
|
26 |
if ast
|
|
27 |
puts s
|
|
28 |
else
|
|
29 |
o = VeloObject.new 'main-script'
|
|
30 |
s.eval o, [] # XXX could pass command-line arguments here...
|
|
31 |
end
|
23 | 32 |
end
|
24 | 33 |
end
|