Commits

Anonymous committed 9d56b24 Draft

Fix parser termination condition; add --ast flag. Now, methods...

Comments (0)

Files changed (2)

 
 ############ Main ############
 
+ast = false
 ARGV.each do |arg|
   if arg == '--debug'
     $debug = true
     next
   end
+  if arg == '--ast'
+    ast = true
+    next
+  end
   File.open(arg, 'r') do |f|
     text = ''
     while line = f.gets
     end
     p = Parser.new(text)
     s = p.script
-    o = VeloObject.new 'main-script'
-    s.eval o, []   # XXX could pass command-line arguments here...
+    if ast
+      puts s
+    else
+      o = VeloObject.new 'main-script'
+      s.eval o, []   # XXX could pass command-line arguments here...
+    end
   end
 end

src/velo/parser.rb

 
   def expr
     debug "parsing Expr production"
-    if @scanner.type == 'EOF'
+    if (['EOL', 'EOF'].include? @scanner.type or [')', ','].include? @scanner.text)
       return nil
     end
     receiver = base  # could be Expr, StringLit, Arg
-    if @scanner.type == 'EOF'
+    if (['EOL', 'EOF'].include? @scanner.type or [')', ','].include? @scanner.text)
       return receiver
     end
     while @scanner.consume '.'
       # lookup(a, b).set(c, foo)
       debug "unlookuping"
       ident = nil
-      if receiver.instance_of? Lookup
+      if receiver.is_a? Lookup
         ident = receiver.ident
         receiver = receiver.receiver
       else
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.