code / bp

Lines4.3K C3.3K Markdown541 YAML273 make110 Shell77 Lua54
(22 lines)
1 # Syntax definitions for some Lua-specific patterns
2 #
3 # NOTE: this is *NOT* intended to be a complete definition of the language's
4 # syntax! Providing a full language grammar is overkill, because the intended
5 # use case is finding/replacing string patterns. This task does not require a
6 # full parse tree, and having one makes the task considerably more complicated.
7 # See the accompanying README.md for more info.
9 comment: "--" (`[ @eqs:*`= `[ ..%\n (`]eqs`]) / ..$)
10 string: `"..%string-escape `" / `' ..%string-escape `' / `[ @eqs:*`= `[ ..%\n (`]eqs`])
11 table: `{ ..%(table/string/comment/\n) `}
12 keyword: ("and" / "break" / "do" / "else" / "elseif" / "end" / "false" / "for" /
13 "function" / "goto" / "if" / "in" / "local" / "nil" / "not" / "or" /
14 "repeat" / "return" / "then" / "true" / "until" / "while")
15 function-def: |"function"|[_id (*(`.id)[`:id])]_ parens
16 block: function / if-block / while-block / for-block / repeat-block / do-block
17 repeat-block: |"repeat"| ..%(comment/string/\n) (|"until"|)
18 do-block: |"do"| ..%(comment/string/block/\n) (|"end"|)
19 for-block: |"for"| ..%\n >(|"do"|) do-block
20 while-block: |"while"| ..%\n >(|"do"|) do-block
21 if-block: |"if"| ..%\n |"then"| ..%(comment/string/\n) (|"end"|)
22 function: function-def ..%(comment/string/block/\n) (|"end"|)