handle embedded script payload
This commit is contained in:
25
corpus/payload.txt
Normal file
25
corpus/payload.txt
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
==================
|
||||||
|
nix-shell with a bash payload
|
||||||
|
==================
|
||||||
|
|
||||||
|
#!/usr/bin/env nix-shell
|
||||||
|
#!nix-shell -i bash
|
||||||
|
echo "hello, world!"
|
||||||
|
---
|
||||||
|
|
||||||
|
(source_file
|
||||||
|
(first_line
|
||||||
|
(shebang_open)
|
||||||
|
(opt_ws)
|
||||||
|
(env)
|
||||||
|
(ws)
|
||||||
|
(nix_shell))
|
||||||
|
(next_line
|
||||||
|
(newline)
|
||||||
|
(annotation_line
|
||||||
|
(shebang_open)
|
||||||
|
(opt_ws)
|
||||||
|
(nix_shell)
|
||||||
|
(nix_shell_args)))
|
||||||
|
(next_line
|
||||||
|
(newline)))
|
@@ -13,7 +13,7 @@ Minimal nix-shell invocation
|
|||||||
(env)
|
(env)
|
||||||
(ws)
|
(ws)
|
||||||
(nix_shell))
|
(nix_shell))
|
||||||
(non_first_line
|
(next_line
|
||||||
(newline)
|
(newline)
|
||||||
(annotation_line
|
(annotation_line
|
||||||
(shebang_open)
|
(shebang_open)
|
||||||
|
20
grammar.js
20
grammar.js
@@ -2,18 +2,28 @@ module.exports = grammar({
|
|||||||
name: 'nixshell',
|
name: 'nixshell',
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
source_file: $ => seq($.first_line, repeat($.non_first_line)),
|
source_file: $ => seq($.first_line, repeat($.next_line)),
|
||||||
|
|
||||||
first_line: $ => seq($.shebang_open, $.opt_ws, optional(seq($.env, $.ws)), $.nix_shell),
|
first_line: $ => seq($.shebang_open, $.opt_ws, optional(seq($.env, $.ws)), $.nix_shell),
|
||||||
non_first_line: $ => seq($.newline, $.annotation_line),
|
next_line: $ => seq($.newline, choice(
|
||||||
|
$.annotation_line,
|
||||||
|
// TODO: capture this
|
||||||
|
repeat(/./),
|
||||||
|
)),
|
||||||
annotation_line: $ => seq($.shebang_open, $.opt_ws, $.nix_shell, $.nix_shell_args),
|
annotation_line: $ => seq($.shebang_open, $.opt_ws, $.nix_shell, $.nix_shell_args),
|
||||||
embedded_script_line: $ => /.*/,
|
// payload_next_line: $ => /\n.*/,
|
||||||
|
// payload_line: $ => /.*/,
|
||||||
|
// payload_line: $ => repeat(/./),
|
||||||
|
|
||||||
shebang_open: $ => /#!/,
|
// nix_shell_directive_open: $ => '#!nix-shell',
|
||||||
|
// TODO: actually parse nix-shell arguments
|
||||||
|
nix_shell_args: $ => ' -i bash',
|
||||||
|
|
||||||
|
// TODO: hide these (prefix with underscore)
|
||||||
|
shebang_open: $ => '#!',
|
||||||
// TODO: allow `usr/bin/env`, `env`
|
// TODO: allow `usr/bin/env`, `env`
|
||||||
env: $ => '/usr/bin/env',
|
env: $ => '/usr/bin/env',
|
||||||
nix_shell: $ => 'nix-shell',
|
nix_shell: $ => 'nix-shell',
|
||||||
nix_shell_args: $ => ' -i bash',
|
|
||||||
ws: $ => / +/,
|
ws: $ => / +/,
|
||||||
opt_ws: $ => / */,
|
opt_ws: $ => / */,
|
||||||
newline: $ => '\n',
|
newline: $ => '\n',
|
||||||
|
Reference in New Issue
Block a user