]> git.lizzy.rs Git - metalua.git/commitdiff
handle initial shebang comments in chunks
authorfabien <fabien@fabien-ubuntu.(none)>
Wed, 10 Sep 2008 18:18:54 +0000 (20:18 +0200)
committerfabien <fabien@fabien-ubuntu.(none)>
Wed, 10 Sep 2008 18:18:54 +0000 (20:18 +0200)
src/compiler/mlp_misc.lua

index 25939ac18442153f00fb5b6b94158c200210e92c..aa50aca13ab4650b23edaf6f6846000dd252ab89 100644 (file)
@@ -163,11 +163,19 @@ end
 --------------------------------------------------------------------------------
 -- Chunk reader: block + Eof
 --------------------------------------------------------------------------------
+function skip_initial_sharp_comment (lx)
+   -- Dirty hack: I'm happily fondling lexer's private parts
+   lx :sync()
+   local i = lx.src:match ("^#.-\n()", lx.i)
+   if i then lx.i, lx.column_offset, lx.line = i, i, lx.line+1 end
+end
+
 function chunk (lx)
-   if lx:peek().tag == 'Eof' then return { }
+   if lx:peek().tag == 'Eof' then return { } -- handle empty files
    else 
+      skip_initial_sharp_comment (lx)
       local chunk = block (lx)
       if lx:peek().tag ~= "Eof" then error "End-of-file expected" end
       return chunk
    end
-end
+end
\ No newline at end of file