feat: ignore shebang lines starting with #! on first line of source

Add special handling in the lexer's nextToken function to detect a '#' character followed by '!' on the first line (currentLine == 1) and skip the entire line as a comment. If the shebang appears on any other line, or if a '#' is not followed by '!', emit a lex error for invalid character. Include test cases for valid shebang execution, shebang at EOF, shebang on a non-first line (expected error), and an invalid shebang pattern (expected error).
This commit is contained in:
Bob Nystrom
2015-01-04 21:02:42 +00:00
5 changed files with 20 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
#!/bin/wren
IO.print("ok") // expect: ok
+1
View File
@@ -0,0 +1 @@
#!/bin/wren
+3
View File
@@ -0,0 +1,3 @@
// expect error line 3
IO.print("nope")
#!/bin/wren
+3
View File
@@ -0,0 +1,3 @@
#/invalid/shebang
// expect error line 1
IO.print("nope")