(22 lines)
1 # Syntax definitions for some Lua-specific patterns2 #3 # NOTE: this is *NOT* intended to be a complete definition of the language's4 # syntax! Providing a full language grammar is overkill, because the intended5 # use case is finding/replacing string patterns. This task does not require a6 # 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])]_ parens16 block: function / if-block / while-block / for-block / repeat-block / do-block17 repeat-block: |"repeat"| ..%(comment/string/\n) (|"until"|)18 do-block: |"do"| ..%(comment/string/block/\n) (|"end"|)19 for-block: |"for"| ..%\n >(|"do"|) do-block20 while-block: |"while"| ..%\n >(|"do"|) do-block21 if-block: |"if"| ..%\n |"then"| ..%(comment/string/\n) (|"end"|)22 function: function-def ..%(comment/string/block/\n) (|"end"|)