diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-01-17 20:13:34 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-01-17 20:13:34 -0800 |
| commit | 54b5dfba4df6ddbfdafe7d93e0aa265b67591b2e (patch) | |
| tree | e48ae7a6ab5998b4343deab8c8bf312ba0135851 | |
| parent | 008db802298d688067ed9615079be28978e60e28 (diff) | |
Added shell grammar
| -rw-r--r-- | grammars/builtins.bp | 1 | ||||
| -rw-r--r-- | grammars/shell.bp | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/grammars/builtins.bp b/grammars/builtins.bp index 544faea..a8d0a8b 100644 --- a/grammars/builtins.bp +++ b/grammars/builtins.bp @@ -42,6 +42,7 @@ parens: `(..`) % (\n/parens/string) string: `"..`" % (`\.) / `'..`' % (`\.) id: !<`a-z,A-Z,_,0-9 (`a-z,A-Z,_ *`a-z,A-Z,_,0-9)!=(keyword$) id-char: `a-z,A-Z,_,0-9 +var: id keyword: !"" # No keywords defined by default word: !<`a-z,A-Z,_,0-9 +`a-z,A-Z !>`0-9,_ |: !<`a-z,A-Z,_,0-9 / !>`a-z,A-Z,_,0-9 diff --git a/grammars/shell.bp b/grammars/shell.bp new file mode 100644 index 0000000..2e2b60a --- /dev/null +++ b/grammars/shell.bp @@ -0,0 +1,19 @@ +# Syntax definition for some Shell-specific patterns +# +# NOTE: this is *NOT* intended to be a complete definition of the language's +# syntax! Providing a full language grammar is overkill, because the intended +# use case is finding/replacing string patterns. This task does not require a +# full parse tree, and having one makes the task considerably more complicated. +# See the accompanying README.md for more info. + +comment: `#..$ +string: `"..`" % (`\./subcommand/\n) / `'..`' % \n / "<<" _ @delim=id _$ ..(^delim$)%\n +subcommand: `` .. `` % \n / "$" parens +keyword: |( + "echo" / "read" / "set" / "unset" / "readonly" / "shift" / "export" / "if" / "fi" / + "else" / "while" / "do" / "done" / "for" / "until" / "case" / "esac" / "break" / + "continue" / "exit" / "return" / "trap" / "wait" / "eval" / "exec" / "ulimit" / "umask" +)| +function-def: ^_ ["function"_] id _ `(_`) >(__`{) +function: function-def __ braces +var: `$ (id / braces) |
