23 lines
1.3 KiB
Plaintext
23 lines
1.3 KiB
Plaintext
# Syntax definitions for some Lua-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: "--" (`[ @eqs:*`= `[ ..%\n (`]eqs`]) / ..$)
|
|
string: `"..%string-escape `" / `' ..%string-escape `' / `[ @eqs:*`= `[ ..%\n (`]eqs`])
|
|
table: `{ ..%(table/string/comment/\n) `}
|
|
keyword: ("and" / "break" / "do" / "else" / "elseif" / "end" / "false" / "for" /
|
|
"function" / "goto" / "if" / "in" / "local" / "nil" / "not" / "or" /
|
|
"repeat" / "return" / "then" / "true" / "until" / "while")
|
|
function-def: |"function"|[_id (*(`.id)[`:id])]_ parens
|
|
block: function / if-block / while-block / for-block / repeat-block / do-block
|
|
repeat-block: |"repeat"| ..%(comment/string/\n) (|"until"|)
|
|
do-block: |"do"| ..%(comment/string/block/\n) (|"end"|)
|
|
for-block: |"for"| ..%\n >(|"do"|) do-block
|
|
while-block: |"while"| ..%\n >(|"do"|) do-block
|
|
if-block: |"if"| ..%\n |"then"| ..%(comment/string/\n) (|"end"|)
|
|
function: function-def ..%(comment/string/block/\n) (|"end"|)
|