public
Description: A Ruby port of the Mozilla Javascript self-parser
Clone URL: git://github.com/nex3/rbnarcissus.git
Search Repo:
Nested function? No way.
nex3 (author)
Sat Jul 19 12:36:12 -0700 2008
commit  732e44d77416e7778a558932debc06e5dc95b014
tree    c6b0658fc06c6fc2f9e0470c9c63e0de9016da84
parent  a8691d1bcbff532e9c5529281c6066c58f8153d6
...
1
2
 
 
3
4
5
...
353
354
355
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
357
358
...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
...
1
2
3
4
5
6
7
...
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
...
396
397
398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
400
401
0
@@ -1,5 +1,7 @@
0
 require 'enumerator'
0
 require 'data'
0
+require 'tokenizer'
0
+require 'node'
0
 
0
 class Narcissus
0
   class SyntaxError
0
@@ -353,6 +355,39 @@ class Narcissus
0
   end
0
 
0
 
0
+ def reduce(operators, operands, t)
0
+ n = operators.pop
0
+ op = n.type
0
+ arity = OP_ARITY[op]
0
+ if arity == -2
0
+ if operands.length >= 2
0
+ # Flatten left-associative trees.
0
+ left = operands[operands.length - 2]
0
+
0
+ if left.type == op
0
+ right = operands.pop
0
+ left.push(right)
0
+ return left
0
+ end
0
+ end
0
+ arity = 2
0
+ end
0
+
0
+ # Always use push to add operands to n, to update start and end.
0
+ a = operands.slice!(operands.length - arity, operands.length)
0
+
0
+ arity.times do |i|
0
+ n.push(a[i])
0
+ end
0
+
0
+ # Include closing bracket or postfix operator in [start,end).
0
+ n.end = t.token.end if n.end < t.token.end
0
+
0
+ operands.push(n)
0
+ return n
0
+ end
0
+
0
+
0
   def expression(t, x, stop = nil)
0
     operators = []
0
     operands = []
0
@@ -361,38 +396,6 @@ class Narcissus
0
     pl = x.paren_level
0
     hl = x.hook_level
0
     
0
- def reduce(operators, operands, t)
0
- n = operators.pop
0
- op = n.type
0
- arity = OP_ARITY[op]
0
- if arity == -2
0
- if operands.length >= 2
0
- # Flatten left-associative trees.
0
- left = operands[operands.length - 2]
0
-
0
- if left.type == op
0
- right = operands.pop
0
- left.push(right)
0
- return left
0
- end
0
- end
0
- arity = 2
0
- end
0
-
0
- # Always use push to add operands to n, to update start and end.
0
- a = operands.slice!(operands.length - arity, operands.length)
0
-
0
- arity.times do |i|
0
- n.push(a[i])
0
- end
0
-
0
- # Include closing bracket or postfix operator in [start,end).
0
- n.end = t.token.end if n.end < t.token.end
0
-
0
- operands.push(n)
0
- return n
0
- end
0
-
0
     gotoloopContinue = false
0
     until gotoloopContinue or (t.token and t.token.type == CONSTS["END"])
0
       gotoloopContinue = catch(:gotoloop) do

Comments

    No one has commented yet.