fix impatient not found on bootstrap

This commit is contained in:
nullchilly 2022-08-07 12:31:11 +07:00 committed by Sidhanth Rathod
parent 33c304f627
commit 074b656cbd
55 changed files with 17472 additions and 1 deletions

View file

@ -10,7 +10,7 @@ M.lazy_load = function(tb)
callback = function()
if tb.condition() then
vim.api.nvim_del_augroup_by_name(tb.augroup_name)
require "impatient"
pcall(require, "impatient")
-- dont defer for treesitter as it will show slow highlighting
-- This deferring only happens only when we do "nvim filename"

15
rplugin.vim Normal file
View file

@ -0,0 +1,15 @@
" perl plugins
" node plugins
" python3 plugins
" ruby plugins
" python plugins

@ -0,0 +1 @@
Subproject commit 9b76787e273567c0e3027304bd16ffedc751c04c

@ -0,0 +1 @@
Subproject commit ac27343b52796a0aa1bb3db824d16e66d1def182

@ -0,0 +1 @@
Subproject commit 62fc67a2b0205136bc3e312664624ba2ab4a9323

@ -0,0 +1 @@
Subproject commit affe808a5c56b71630f17aa7c38e15c59fd648a8

@ -0,0 +1 @@
Subproject commit d276254e7198ab7d00f117e88e223b4bd8c02d21

@ -0,0 +1 @@
Subproject commit 447c87cdd6e6d6a1d2488b1d43108bfa217f56e1

@ -0,0 +1 @@
Subproject commit a9de941bcbda508d0a45d28ae366bb3f08db2e36

@ -0,0 +1 @@
Subproject commit e82d9f5e612ade06202591ed76ecb095e946f7f8

@ -0,0 +1 @@
Subproject commit 7339def34e46237eb7c9a893cb7d42dcb90e05e6

@ -0,0 +1 @@
Subproject commit 9c3ca027661136a618c82275427746e481c84a4e

@ -0,0 +1 @@
Subproject commit 4ccbe749ce439fa25d387d459e8c339131cc5d1f

@ -0,0 +1 @@
Subproject commit c15bbe9f23d88b5c0b4ca45a446e01a0a3913707

@ -0,0 +1 @@
Subproject commit cd1af57253b3ac3652765e4d0f83b56802ec2a5f

@ -0,0 +1 @@
Subproject commit ca89ab9e7e42aa9279f1cdad15398d6e18ccee86

@ -0,0 +1 @@
Subproject commit 706371f1300e7c0acb98b346f80dad2dd9b5f679

@ -0,0 +1 @@
Subproject commit 8fe6ec269c6bcd19a7c2d69cb0bdcf8bb86a85fe

@ -0,0 +1 @@
Subproject commit 6e047f11861bfb6ec28a6ad0138a8f0a62bb8806

@ -0,0 +1 @@
Subproject commit ff6e7966f39a897ac4d1358f4d022cfecdc88ff1

@ -0,0 +1 @@
Subproject commit a9a6493b1eeba458757903352e0d3dc4b54fd4f2

@ -0,0 +1 @@
Subproject commit 2d02a56189e2bde11edd4712fea16f08a6656944

@ -0,0 +1 @@
Subproject commit 1317d6238f089e117e3ed98b3cecc37cc4364675

@ -0,0 +1 @@
Subproject commit afab89594f4f702dc3368769c95b782dbdaeaf0a

@ -0,0 +1 @@
Subproject commit 31807eef4ed574854b8a53ae40ea3292033a78ea

@ -0,0 +1 @@
Subproject commit 4725867ec66b9a0f5e5ad95a1fd94c2f97fa2d2c

@ -0,0 +1 @@
Subproject commit bca1182e872db0ea52d86b2f4cf4ee7cb092de45

@ -0,0 +1 @@
Subproject commit dfdcff9c6b2bd1ad3c364973a2497bf62c6f0f20

View file

@ -0,0 +1,22 @@
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2.1.2
with:
node-version: '16.x'
- name: Install dependencies
run: npm install
- name: Test
run: npm run test

11
tree-sitter-lua/.gitignore vendored Normal file
View file

@ -0,0 +1,11 @@
*.log
*.tgz
.DS_Store
Cargo.lock
build
node_modules
package-lock.json
yarn.lock
target
examples/luvit

View file

@ -0,0 +1,2 @@
bindings/
src/

View file

@ -0,0 +1,3 @@
{
"singleQuote": true
}

View file

@ -0,0 +1,29 @@
[package]
name = "tree-sitter-lua"
description = "Lua grammar for the tree-sitter parsing library"
version = "0.0.12"
authors = [
"Munif Tanjim <hello@muniftanjim.dev>",
]
license = "MIT"
keywords = ["incremental", "parsing", "lua"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/MunifTanjim/tree-sitter-lua"
edition = "2018"
build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"grammar.js",
"queries/*",
"src/*",
]
[lib]
path = "bindings/rust/lib.rs"
[dependencies]
tree-sitter = "0.20"
[build-dependencies]
cc = "1.0"

View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2021 Munif Tanjim
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

20
tree-sitter-lua/README.md Normal file
View file

@ -0,0 +1,20 @@
![GitHub Workflow Status: CI](https://img.shields.io/github/workflow/status/MunifTanjim/tree-sitter-lua/CI/main?label=CI&style=for-the-badge)
# tree-sitter-lua
Lua grammar for tree-sitter.
## References
- [Lua Documentation](https://www.lua.org/docs.html)
## Acknowledgement
The [external scanner](/src/scanner.c) was based on these repositories:
- [Azganoth/tree-sitter-lua](https://github.com/Azganoth/tree-sitter-lua)
- [euclidianAce/tree-sitter-teal](https://github.com/euclidianAce/tree-sitter-teal)
## License
Licensed under the MIT License. Check the [LICENSE](/LICENSE.md) file for details.

View file

@ -0,0 +1,19 @@
{
"targets": [
{
"target_name": "tree_sitter_lua_binding",
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
],
"sources": [
"src/parser.c",
"src/scanner.c",
"bindings/node/binding.cc"
],
"cflags_c": [
"-std=c99"
]
}
]
}

View file

@ -0,0 +1,28 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
extern "C" TSLanguage * tree_sitter_lua();
namespace {
NAN_METHOD(New) {}
void Init(Local<Object> exports, Local<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_lua());
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("lua").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}
NODE_MODULE(tree_sitter_lua_binding, Init)
} // namespace

View file

@ -0,0 +1,19 @@
try {
module.exports = require("../../build/Release/tree_sitter_lua_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_lua_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}

View file

@ -0,0 +1,38 @@
fn main() {
let src_dir = std::path::Path::new("src");
let mut c_config = cc::Build::new();
c_config.include(&src_dir);
c_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);
// If your language uses an external scanner written in C,
// then include this block of code:
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
// If your language uses an external scanner written in C++,
// then include this block of code:
/*
let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&src_dir);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir.join("scanner.cc");
cpp_config.file(&scanner_path);
cpp_config.compile("scanner");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
}

View file

@ -0,0 +1,52 @@
//! This crate provides lua language support for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] function to add this language to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//!
//! ```
//! let code = "";
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(tree_sitter_lua::language()).expect("Error loading lua grammar");
//! let tree = parser.parse(code, None).unwrap();
//! ```
//!
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
//! [language func]: fn.language.html
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
//! [tree-sitter]: https://tree-sitter.github.io/
use tree_sitter::Language;
extern "C" {
fn tree_sitter_lua() -> Language;
}
/// Get the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_lua() }
}
/// The content of the [`node-types.json`][] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
// Uncomment these to include any queries that this grammar contains
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
#[cfg(test)]
mod tests {
#[test]
fn test_can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.expect("Error loading lua language");
}
}

View file

@ -0,0 +1,3 @@
#!/usr/bin/env lua
return 42

504
tree-sitter-lua/grammar.js Normal file
View file

@ -0,0 +1,504 @@
const PREC = {
OR: 1, // or
AND: 2, // and
COMPARE: 3, // < > <= >= ~= ==
BIT_OR: 4, // |
BIT_NOT: 5, // ~
BIT_AND: 6, // &
BIT_SHIFT: 7, // << >>
CONCAT: 8, // ..
PLUS: 9, // + -
MULTI: 10, // * / // %
UNARY: 11, // not # - ~
POWER: 12, // ^
};
const list_seq = (rule, separator, trailing_separator = false) =>
trailing_separator
? seq(rule, repeat(seq(separator, rule)), optional(separator))
: seq(rule, repeat(seq(separator, rule)));
const optional_block = ($) => alias(optional($._block), $.block);
// namelist ::= Name {',' Name}
const name_list = ($) => list_seq(field('name', $.identifier), ',');
module.exports = grammar({
name: 'lua',
extras: ($) => [$.comment, /\s/],
externals: ($) => [
$._block_comment_start,
$._block_comment_content,
$._block_comment_end,
$._string_start,
$._string_content,
$._string_end,
],
supertypes: ($) => [$.statement, $.expression, $.declaration, $.variable],
word: ($) => $.identifier,
rules: {
// chunk ::= block
chunk: ($) =>
seq(
optional($.hash_bang_line),
repeat($.statement),
optional($.return_statement)
),
hash_bang_line: (_) => /#!.*/,
// block ::= {stat} [retstat]
_block: ($) =>
choice(
seq(repeat1($.statement), optional($.return_statement)),
seq(repeat($.statement), $.return_statement)
),
/*
stat ::= ';' |
varlist '=' explist |
functioncall |
label |
break |
goto Name |
do block end |
while exp do block end |
repeat block until exp |
if exp then block {elseif exp then block} [else block] end |
for Name '=' exp ',' exp [',' exp] do block end |
for namelist in explist do block end |
function funcname funcbody |
local function Name funcbody |
local namelist ['=' explist]
*/
statement: ($) =>
choice(
$.empty_statement,
$.assignment_statement,
$.function_call,
$.label_statement,
$.break_statement,
$.goto_statement,
$.do_statement,
$.while_statement,
$.repeat_statement,
$.if_statement,
$.for_statement,
$.declaration
),
// retstat ::= return [explist] [';']
return_statement: ($) =>
seq(
'return',
optional(alias($._expression_list, $.expression_list)),
optional(';')
),
// ';'
empty_statement: (_) => ';',
// varlist '=' explist
assignment_statement: ($) =>
seq(
alias($._variable_assignment_varlist, $.variable_list),
'=',
alias($._variable_assignment_explist, $.expression_list)
),
// varlist ::= var {',' var}
_variable_assignment_varlist: ($) =>
list_seq(field('name', $.variable), ','),
// explist ::= exp {',' exp}
_variable_assignment_explist: ($) =>
list_seq(field('value', $.expression), ','),
// label ::= '::' Name '::'
label_statement: ($) => seq('::', $.identifier, '::'),
// break
break_statement: (_) => 'break',
// goto Name
goto_statement: ($) => seq('goto', $.identifier),
// do block end
do_statement: ($) => seq('do', field('body', optional_block($)), 'end'),
// while exp do block end
while_statement: ($) =>
seq(
'while',
field('condition', $.expression),
'do',
field('body', optional_block($)),
'end'
),
// repeat block until exp
repeat_statement: ($) =>
seq(
'repeat',
field('body', optional_block($)),
'until',
field('condition', $.expression)
),
// if exp then block {elseif exp then block} [else block] end
if_statement: ($) =>
seq(
'if',
field('condition', $.expression),
'then',
field('consequence', optional_block($)),
repeat(field('alternative', $.elseif_statement)),
optional(field('alternative', $.else_statement)),
'end'
),
// elseif exp then block
elseif_statement: ($) =>
seq(
'elseif',
field('condition', $.expression),
'then',
field('consequence', optional_block($))
),
// else block
else_statement: ($) => seq('else', field('body', optional_block($))),
// for Name '=' exp ',' exp [',' exp] do block end
// for namelist in explist do block end
for_statement: ($) =>
seq(
'for',
field('clause', choice($.for_generic_clause, $.for_numeric_clause)),
'do',
field('body', optional_block($)),
'end'
),
// namelist in explist
for_generic_clause: ($) =>
seq(
alias($._name_list, $.variable_list),
'in',
alias($._expression_list, $.expression_list)
),
// Name '=' exp ',' exp [',' exp]
for_numeric_clause: ($) =>
seq(
field('name', $.identifier),
'=',
field('start', $.expression),
',',
field('end', $.expression),
optional(seq(',', field('step', $.expression)))
),
// function funcname funcbody
// local function Name funcbody
// local namelist ['=' explist]
declaration: ($) =>
choice(
$.function_declaration,
field(
'local_declaration',
alias($._local_function_declaration, $.function_declaration)
),
field('local_declaration', $.variable_declaration)
),
// function funcname funcbody
function_declaration: ($) =>
seq('function', field('name', $._function_name), $._function_body),
// local function Name funcbody
_local_function_declaration: ($) =>
seq('local', 'function', field('name', $.identifier), $._function_body),
// funcname ::= Name {'.' Name} [':' Name]
_function_name: ($) =>
choice(
$._function_name_prefix_expression,
alias(
$._function_name_method_index_expression,
$.method_index_expression
)
),
_function_name_prefix_expression: ($) =>
choice(
$.identifier,
alias($._function_name_dot_index_expression, $.dot_index_expression)
),
_function_name_dot_index_expression: ($) =>
seq(
field('table', $._function_name_prefix_expression),
'.',
field('field', $.identifier)
),
_function_name_method_index_expression: ($) =>
seq(
field('table', $._function_name_prefix_expression),
':',
field('method', $.identifier)
),
// local namelist ['=' explist]
variable_declaration: ($) =>
seq(
'local',
choice(
alias($._name_list, $.variable_list),
alias($._local_variable_assignment, $.assignment_statement)
)
),
_local_variable_assignment: ($) =>
seq(
alias($._name_list, $.variable_list),
'=',
alias($._variable_assignment_explist, $.expression_list)
),
// namelist ::= Name {',' Name}
_name_list: ($) => name_list($),
// explist ::= exp {',' exp}
_expression_list: ($) => list_seq($.expression, ','),
/*
exp ::= nil | false | true | Numeral | LiteralString | '...' | functiondef |
prefixexp | tableconstructor | exp binop exp | unop exp
*/
expression: ($) =>
choice(
$.nil,
$.false,
$.true,
$.number,
$.string,
$.vararg_expression,
$.function_definition,
$.variable,
$.function_call,
$.parenthesized_expression,
$.table_constructor,
$.binary_expression,
$.unary_expression
),
// nil
nil: (_) => 'nil',
// false
false: (_) => 'false',
// true
true: (_) => 'true',
// Numeral
number: (_) => {
const decimal_digits = /[0-9]+/;
const signed_integer = seq(optional(choice('-', '+')), decimal_digits);
const decimal_exponent_part = seq(choice('e', 'E'), signed_integer);
const decimal_integer_literal = choice(
'0',
seq(optional('0'), /[1-9]/, optional(decimal_digits))
);
const hex_digits = /[a-fA-F0-9]+/;
const hex_exponent_part = seq(choice('p', 'P'), signed_integer);
const decimal_literal = choice(
seq(
decimal_integer_literal,
'.',
optional(decimal_digits),
optional(decimal_exponent_part)
),
seq('.', decimal_digits, optional(decimal_exponent_part)),
seq(decimal_integer_literal, optional(decimal_exponent_part))
);
const hex_literal = seq(
choice('0x', '0X'),
hex_digits,
optional(seq('.', hex_digits)),
optional(hex_exponent_part)
);
return token(choice(decimal_literal, hex_literal));
},
// LiteralString
string: ($) =>
seq(
field('start', alias($._string_start, 'string_start')),
field('content', optional(alias($._string_content, 'string_content'))),
field('end', alias($._string_end, 'string_end'))
),
// '...'
vararg_expression: (_) => '...',
// functiondef ::= function funcbody
function_definition: ($) => seq('function', $._function_body),
// funcbody ::= '(' [parlist] ')' block end
_function_body: ($) =>
seq(
field('parameters', $.parameters),
field('body', optional_block($)),
'end'
),
// '(' [parlist] ')'
parameters: ($) => seq('(', optional($._parameter_list), ')'),
// parlist ::= namelist [',' '...'] | '...'
_parameter_list: ($) =>
choice(
seq(name_list($), optional(seq(',', $.vararg_expression))),
$.vararg_expression
),
// prefixexp ::= var | functioncall | '(' exp ')'
_prefix_expression: ($) =>
prec(1, choice($.variable, $.function_call, $.parenthesized_expression)),
// var ::= Name | prefixexp [ exp ] | prefixexp . Name
variable: ($) =>
choice($.identifier, $.bracket_index_expression, $.dot_index_expression),
// prefixexp [ exp ]
bracket_index_expression: ($) =>
seq(
field('table', $._prefix_expression),
'[',
field('field', $.expression),
']'
),
// prefixexp . Name
dot_index_expression: ($) =>
seq(
field('table', $._prefix_expression),
'.',
field('field', $.identifier)
),
// functioncall ::= prefixexp args | prefixexp ':' Name args
function_call: ($) =>
seq(
field('name', choice($._prefix_expression, $.method_index_expression)),
field('arguments', $.arguments)
),
// prefixexp ':' Name
method_index_expression: ($) =>
seq(
field('table', $._prefix_expression),
':',
field('method', $.identifier)
),
// args ::= '(' [explist] ')' | tableconstructor | LiteralString
arguments: ($) =>
choice(
seq('(', optional(list_seq($.expression, ',')), ')'),
$.table_constructor,
$.string
),
// '(' exp ')'
parenthesized_expression: ($) => seq('(', $.expression, ')'),
// tableconstructor ::= '{' [fieldlist] '}'
table_constructor: ($) => seq('{', optional($._field_list), '}'),
// fieldlist ::= field {fieldsep field} [fieldsep]
_field_list: ($) => list_seq($.field, $._field_sep, true),
// fieldsep ::= ',' | ';'
_field_sep: (_) => choice(',', ';'),
// field ::= '[' exp ']' '=' exp | Name '=' exp | exp
field: ($) =>
choice(
seq(
'[',
field('name', $.expression),
']',
'=',
field('value', $.expression)
),
seq(field('name', $.identifier), '=', field('value', $.expression)),
field('value', $.expression)
),
// exp binop exp
binary_expression: ($) =>
choice(
...[
['or', PREC.OR],
['and', PREC.AND],
['<', PREC.COMPARE],
['<=', PREC.COMPARE],
['==', PREC.COMPARE],
['~=', PREC.COMPARE],
['>=', PREC.COMPARE],
['>', PREC.COMPARE],
['|', PREC.BIT_OR],
['~', PREC.BIT_NOT],
['&', PREC.BIT_AND],
['<<', PREC.BIT_SHIFT],
['>>', PREC.BIT_SHIFT],
['+', PREC.PLUS],
['-', PREC.PLUS],
['*', PREC.MULTI],
['/', PREC.MULTI],
['//', PREC.MULTI],
['%', PREC.MULTI],
].map(([operator, precedence]) =>
prec.left(
precedence,
seq(
field('left', $.expression),
operator,
field('right', $.expression)
)
)
),
...[
['..', PREC.CONCAT],
['^', PREC.POWER],
].map(([operator, precedence]) =>
prec.right(
precedence,
seq(
field('left', $.expression),
operator,
field('right', $.expression)
)
)
)
),
// unop exp
unary_expression: ($) =>
prec.left(
PREC.UNARY,
seq(choice('not', '#', '-', '~'), field('operand', $.expression))
),
// Name
identifier: (_) => /[a-zA-Z_][a-zA-Z0-9_]*/,
// comment
comment: ($) =>
choice(
seq(
field('start', alias('--', 'comment_start')),
field('content', alias(/[^\r\n]*/, 'comment_content'))
),
seq(
field('start', alias($._block_comment_start, 'comment_start')),
field(
'content',
optional(alias($._block_comment_content, 'comment_content'))
),
field('end', alias($._block_comment_end, 'comment_end'))
)
),
},
});

View file

@ -0,0 +1,46 @@
{
"name": "@muniftanjim/tree-sitter-lua",
"version": "0.0.12",
"description": "Lua grammar for tree-sitter",
"keywords": [
"tree-sitter",
"parser",
"lua"
],
"homepage": "https://github.com/MunifTanjim/tree-sitter-lua#readme",
"bugs": "https://github.com/MunifTanjim/tree-sitter-lua/issues",
"license": "MIT",
"author": "Munif Tanjim (https://muniftanjim.dev)",
"files": [
"bindings",
"queries",
"src",
"binding.gyp",
"grammar.js"
],
"main": "bindings/node",
"repository": "https://github.com/MunifTanjim/tree-sitter-lua",
"scripts": {
"build": "tree-sitter generate",
"postbuild": "node-gyp build",
"test": "tree-sitter test",
"posttest": "./script/parse-examples lua"
},
"dependencies": {
"nan": "^2.14.2"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.0"
},
"publishConfig": {
"access": "public"
},
"tree-sitter": [
{
"scope": "source.lua",
"file-types": [
"lua"
]
}
]
}

View file

@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${0}")/.."
checkout_repo() {
local -r path="${1}"
local -r repo="${2}"
local -r sha="${3}"
echo "Checking out github.com/${repo}#${sha} in ${path}"
mkdir -p "${path}"
pushd "${path}" >/dev/null
if [[ ! -d ".git" ]]; then
git init --quiet
git remote add origin "https://github.com/${repo}.git"
git fetch --quiet --depth 1 origin "${sha}"
elif [[ "${sha}" != "$(git rev-parse HEAD)" ]]; then
git fetch --quiet --depth 1 origin "${sha}"
fi
git checkout --quiet FETCH_HEAD
popd >/dev/null
echo
}
checkout_repo "./examples/luvit" "luvit/luvit" "9841bc17aaab32fa63e11063cf68f82da615eefd"
parse_examples() {
local -r known_failures="$(cat script/known_failures.txt)"
tree-sitter parse --quiet \
"./examples/luvit/**/*.lua" \
$(for file in ${known_failures}; do echo "!${file}"; done)
declare -r example_count=$(find ./examples -name "*.lua" | wc -l)
declare -r failure_count=$(wc -w <<< "${known_failures}")
declare -r success_count=$(( ${example_count} - ${failure_count} ))
declare -r success_percent=$(bc -l <<< "100*${success_count}/${example_count}")
printf \
"[Lua] Successfully parsed %d of %d example files (%.1f%%)\n" \
${success_count} ${example_count} ${success_percent}
}
parse_examples

View file

@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -eu
echo "Running Build..."
npm run build
echo
echo "Running Tests..."
npm run test
echo
echo "Bumping Version..."
declare -r curr_version=$(npx -c 'echo $npm_package_version')
npm version --allow-same-version --no-git-tag-version $@
declare -r next_version=$(npx -c 'echo $npm_package_version')
echo
if [[ "${curr_version}" = "${next_version}" ]]; then
echo "Version did not change!"
exit 1
fi
git add package.json
echo "crate: tree-sitter-lua"
echo "v${next_version}"
cargo bump "${next_version}"
git add "Cargo.toml"
echo
git commit -m "chore: release v${next_version}"
git tag "v${next_version}" -m "v${next_version}"

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

10837
tree-sitter-lua/src/parser.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,229 @@
#include <tree_sitter/parser.h>
#include <wctype.h>
#include <stdio.h>
enum TokenType {
BLOCK_COMMENT_START,
BLOCK_COMMENT_CONTENT,
BLOCK_COMMENT_END,
STRING_START,
STRING_CONTENT,
STRING_END,
};
static inline void consume(TSLexer *lexer) { lexer->advance(lexer, false); }
static inline void skip(TSLexer *lexer) { lexer->advance(lexer, true); }
static inline bool consume_char(char c, TSLexer *lexer) {
if (lexer->lookahead != c) {
return false;
}
consume(lexer);
return true;
}
static inline uint8_t consume_and_count_char(char c, TSLexer *lexer) {
uint8_t count = 0;
while (lexer->lookahead == c) {
++count;
consume(lexer);
}
return count;
}
static inline void skip_whitespaces(TSLexer *lexer) {
while (iswspace(lexer->lookahead)) {
skip(lexer);
}
}
void *tree_sitter_lua_external_scanner_create() { return NULL; }
void tree_sitter_lua_external_scanner_destroy(void *payload) {}
char ending_char = 0;
uint8_t level_count = 0;
static inline void reset_state() {
ending_char = 0;
level_count = 0;
}
unsigned tree_sitter_lua_external_scanner_serialize(void *payload, char *buffer) {
buffer[0] = ending_char;
buffer[1] = level_count;
return 2;
}
void tree_sitter_lua_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {
if (length == 0) return;
ending_char = buffer[0];
if (length == 1) return;
level_count = buffer[1];
}
static bool scan_block_start(TSLexer *lexer) {
if (consume_char('[', lexer)) {
uint8_t level = consume_and_count_char('=', lexer);
if (consume_char('[', lexer)) {
level_count = level;
return true;
}
}
return false;
}
static bool scan_block_end(TSLexer *lexer) {
if (consume_char(']', lexer)) {
uint8_t level = consume_and_count_char('=', lexer);
if (level_count == level && consume_char(']', lexer)) {
return true;
}
}
return false;
}
static bool scan_block_content(TSLexer *lexer) {
while (lexer->lookahead != 0) {
if (lexer->lookahead == ']') {
lexer->mark_end(lexer);
if (scan_block_end(lexer)) {
return true;
}
} else {
consume(lexer);
}
}
return false;
}
static bool scan_comment_start(TSLexer *lexer) {
if (consume_char('-', lexer) && consume_char('-', lexer)) {
lexer->mark_end(lexer);
if (scan_block_start(lexer)) {
lexer->mark_end(lexer);
lexer->result_symbol = BLOCK_COMMENT_START;
return true;
}
}
return false;
}
static bool scan_comment_content(TSLexer *lexer) {
if (ending_char == 0) { // block comment
if (scan_block_content(lexer)) {
lexer->result_symbol = BLOCK_COMMENT_CONTENT;
return true;
}
return false;
}
while (lexer->lookahead != 0) {
if (lexer->lookahead == ending_char) {
reset_state();
lexer->result_symbol = BLOCK_COMMENT_CONTENT;
return true;
}
consume(lexer);
}
return false;
}
static bool scan_string_start(TSLexer *lexer) {
if (lexer->lookahead == '"' || lexer->lookahead == '\'') {
ending_char = lexer->lookahead;
consume(lexer);
return true;
}
if (scan_block_start(lexer)) {
return true;
}
return false;
}
static bool scan_string_end(TSLexer *lexer) {
if (ending_char == 0) { // block string
return scan_block_end(lexer);
}
if (consume_char(ending_char, lexer)) {
return true;
}
return false;
}
static bool scan_string_content(TSLexer *lexer) {
if (ending_char == 0) { // block string
return scan_block_content(lexer);
}
while (lexer->lookahead != '\n' && lexer->lookahead != 0 && lexer->lookahead != ending_char) {
if (consume_char('\\', lexer) && consume_char('z', lexer)) {
while (iswspace(lexer->lookahead)) {
consume(lexer);
}
continue;
};
if (lexer->lookahead == 0) {
return true;
}
consume(lexer);
}
return true;
}
bool tree_sitter_lua_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
if (valid_symbols[STRING_END] && scan_string_end(lexer)) {
reset_state();
lexer->result_symbol = STRING_END;
return true;
}
if (valid_symbols[STRING_CONTENT] && scan_string_content(lexer)) {
lexer->result_symbol = STRING_CONTENT;
return true;
}
if (valid_symbols[BLOCK_COMMENT_END] && ending_char == 0 && scan_block_end(lexer)) {
reset_state();
lexer->result_symbol = BLOCK_COMMENT_END;
return true;
}
if (valid_symbols[BLOCK_COMMENT_CONTENT] && scan_comment_content(lexer)) {
return true;
}
skip_whitespaces(lexer);
if (valid_symbols[STRING_START] && scan_string_start(lexer)) {
lexer->result_symbol = STRING_START;
return true;
}
if (valid_symbols[BLOCK_COMMENT_START]) {
if (scan_comment_start(lexer)) {
return true;
}
}
return false;
}

View file

@ -0,0 +1,224 @@
#ifndef TREE_SITTER_PARSER_H_
#define TREE_SITTER_PARSER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define ts_builtin_sym_error ((TSSymbol)-1)
#define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
typedef uint16_t TSStateId;
#ifndef TREE_SITTER_API_H_
typedef uint16_t TSSymbol;
typedef uint16_t TSFieldId;
typedef struct TSLanguage TSLanguage;
#endif
typedef struct {
TSFieldId field_id;
uint8_t child_index;
bool inherited;
} TSFieldMapEntry;
typedef struct {
uint16_t index;
uint16_t length;
} TSFieldMapSlice;
typedef struct {
bool visible;
bool named;
bool supertype;
} TSSymbolMetadata;
typedef struct TSLexer TSLexer;
struct TSLexer {
int32_t lookahead;
TSSymbol result_symbol;
void (*advance)(TSLexer *, bool);
void (*mark_end)(TSLexer *);
uint32_t (*get_column)(TSLexer *);
bool (*is_at_included_range_start)(const TSLexer *);
bool (*eof)(const TSLexer *);
};
typedef enum {
TSParseActionTypeShift,
TSParseActionTypeReduce,
TSParseActionTypeAccept,
TSParseActionTypeRecover,
} TSParseActionType;
typedef union {
struct {
uint8_t type;
TSStateId state;
bool extra;
bool repetition;
} shift;
struct {
uint8_t type;
uint8_t child_count;
TSSymbol symbol;
int16_t dynamic_precedence;
uint16_t production_id;
} reduce;
uint8_t type;
} TSParseAction;
typedef struct {
uint16_t lex_state;
uint16_t external_lex_state;
} TSLexMode;
typedef union {
TSParseAction action;
struct {
uint8_t count;
bool reusable;
} entry;
} TSParseActionEntry;
struct TSLanguage {
uint32_t version;
uint32_t symbol_count;
uint32_t alias_count;
uint32_t token_count;
uint32_t external_token_count;
uint32_t state_count;
uint32_t large_state_count;
uint32_t production_id_count;
uint32_t field_count;
uint16_t max_alias_sequence_length;
const uint16_t *parse_table;
const uint16_t *small_parse_table;
const uint32_t *small_parse_table_map;
const TSParseActionEntry *parse_actions;
const char * const *symbol_names;
const char * const *field_names;
const TSFieldMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries;
const TSSymbolMetadata *symbol_metadata;
const TSSymbol *public_symbol_map;
const uint16_t *alias_map;
const TSSymbol *alias_sequences;
const TSLexMode *lex_modes;
bool (*lex_fn)(TSLexer *, TSStateId);
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
TSSymbol keyword_capture_token;
struct {
const bool *states;
const TSSymbol *symbol_map;
void *(*create)(void);
void (*destroy)(void *);
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned);
} external_scanner;
const TSStateId *primary_state_ids;
};
/*
* Lexer Macros
*/
#define START_LEXER() \
bool result = false; \
bool skip = false; \
bool eof = false; \
int32_t lookahead; \
goto start; \
next_state: \
lexer->advance(lexer, skip); \
start: \
skip = false; \
lookahead = lexer->lookahead;
#define ADVANCE(state_value) \
{ \
state = state_value; \
goto next_state; \
}
#define SKIP(state_value) \
{ \
skip = true; \
state = state_value; \
goto next_state; \
}
#define ACCEPT_TOKEN(symbol_value) \
result = true; \
lexer->result_symbol = symbol_value; \
lexer->mark_end(lexer);
#define END_STATE() return result;
/*
* Parse Table Macros
*/
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
#define STATE(id) id
#define ACTIONS(id) id
#define SHIFT(state_value) \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value \
} \
}}
#define SHIFT_REPEAT(state_value) \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value, \
.repetition = true \
} \
}}
#define SHIFT_EXTRA() \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.extra = true \
} \
}}
#define REDUCE(symbol_val, child_count_val, ...) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
.symbol = symbol_val, \
.child_count = child_count_val, \
__VA_ARGS__ \
}, \
}}
#define RECOVER() \
{{ \
.type = TSParseActionTypeRecover \
}}
#define ACCEPT_INPUT() \
{{ \
.type = TSParseActionTypeAccept \
}}
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_PARSER_H_

View file

@ -0,0 +1,31 @@
================================================================================
chunk
================================================================================
--------------------------------------------------------------------------------
(chunk)
================================================================================
hash_bang_line
================================================================================
#!/usr/bin/env lua
--------------------------------------------------------------------------------
(chunk
(hash_bang_line))
================================================================================
return_statement
================================================================================
return 42
--------------------------------------------------------------------------------
(chunk
(return_statement
(expression_list
(number))))

View file

@ -0,0 +1,80 @@
================================================================================
comment
================================================================================
--
-- single-line comment, below an empty single-line comment
--[[
print("block comment")
--]]
--[[
print("block comment")
]]
-- [[
print("not block comment")
--]]
--[=[[print("level 1 block comment")]]=]
--[=[
[print("level 1 block comment")]
]=]
--[=[
[print("level 1 block comment")
]=]
--[=[
print("level 1 block comment")]
]=]
--[=[
[[print("level 1 block comment")
]=]
--[=[
print("level 1 block comment")]]
]=]
--[==[
print("level 2 block comment")
-- ]==]
--[==[
print("level 2 block comment")
]==]
-- [==[
print("not level 2 block comment")
--]==]
--------------------------------------------------------------------------------
(chunk
(comment)
(comment)
(comment)
(comment)
(comment)
(function_call
name: (identifier)
arguments: (arguments
(string)))
(comment)
(comment)
(comment)
(comment)
(comment)
(comment)
(comment)
(comment)
(comment)
(comment)
(function_call
name: (identifier)
arguments: (arguments
(string)))
(comment))

View file

@ -0,0 +1,591 @@
================================================================================
nil
================================================================================
exp(nil)
--------------------------------------------------------------------------------
(chunk
(function_call
name: (identifier)
arguments: (arguments
(nil))))
================================================================================
false
================================================================================
exp(false)
--------------------------------------------------------------------------------
(chunk
(function_call
name: (identifier)
arguments: (arguments
(false))))
================================================================================
true
================================================================================
exp(true)
--------------------------------------------------------------------------------
(chunk
(function_call
name: (identifier)
arguments: (arguments
(true))))
================================================================================
number
================================================================================
exp(
3,
345,
0xff,
0xBEBADA,
3.0,
3.1416,
314.16e-2,
0.31416E1,
34e1,
0x0.1E,
0xA23p-4,
0X1.921FB54442D18P+1
)
--------------------------------------------------------------------------------
(chunk
(function_call
name: (identifier)
arguments: (arguments
(number)
(number)
(number)
(number)
(number)
(number)
(number)
(number)
(number)
(number)
(number)
(number))))
================================================================================
string
================================================================================
exp(
"string",
'string',
"a\
b",
'a\z',
'a\z
',
'a\z
b',
"'a\z\
b'",
"c",
'c',
"0",
[[ string ]],
[[
string
string
]],
[=[
string
string
]=],
[=[[string]]=],
[=[
[string]
]=],
[=[
[string
]=],
[=[
string]
]=],
[=[
[[string
]=],
[=[
string]]
]=]
)
--------------------------------------------------------------------------------
(chunk
(function_call
name: (identifier)
arguments: (arguments
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string)
(string))))
================================================================================
vararg_expression
================================================================================
exp(...)
--------------------------------------------------------------------------------
(chunk
(function_call
name: (identifier)
arguments: (arguments
(vararg_expression))))
================================================================================
function_definition
================================================================================
f1 = function() end
f2 = function() return end
f3 = function(...)
return ...
end
f4 = function(a1, ...)
print(...)
return a1
end
--------------------------------------------------------------------------------
(chunk
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (function_definition
parameters: (parameters))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (function_definition
parameters: (parameters)
body: (block
(return_statement)))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (function_definition
parameters: (parameters
(vararg_expression))
body: (block
(return_statement
(expression_list
(vararg_expression)))))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (function_definition
parameters: (parameters
name: (identifier)
(vararg_expression))
body: (block
(function_call
name: (identifier)
arguments: (arguments
(vararg_expression)))
(return_statement
(expression_list
(identifier))))))))
================================================================================
variable ::: identifier
================================================================================
v1 = n1
v2, v3 = n2, n3
--------------------------------------------------------------------------------
(chunk
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (identifier)))
(assignment_statement
(variable_list
name: (identifier)
name: (identifier))
(expression_list
value: (identifier)
value: (identifier))))
================================================================================
variable ::: bracket_index_expression
================================================================================
v1 = tbl[k1]
v2, v3[v] = tbl[k1]["k2"]
v4 = tbk[getK1()][getK2()]
--------------------------------------------------------------------------------
(chunk
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (bracket_index_expression
table: (identifier)
field: (identifier))))
(assignment_statement
(variable_list
name: (identifier)
name: (bracket_index_expression
table: (identifier)
field: (identifier)))
(expression_list
value: (bracket_index_expression
table: (bracket_index_expression
table: (identifier)
field: (identifier))
field: (string))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (bracket_index_expression
table: (bracket_index_expression
table: (identifier)
field: (function_call
name: (identifier)
arguments: (arguments)))
field: (function_call
name: (identifier)
arguments: (arguments))))))
================================================================================
variable ::: dot_index_expression
================================================================================
v1 = tbl.k1
v2 = tbl.k1.k2
--------------------------------------------------------------------------------
(chunk
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (dot_index_expression
table: (identifier)
field: (identifier))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (dot_index_expression
table: (dot_index_expression
table: (identifier)
field: (identifier))
field: (identifier)))))
================================================================================
function_call ::: bracket_index_expression | dot_index_expression
================================================================================
v1 = tbl[k1].k2(a1, "a2", a3())
v2 = tbl[k1] { f1 = true }
v3 = tbl[k1] "a1"
--------------------------------------------------------------------------------
(chunk
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (function_call
name: (dot_index_expression
table: (bracket_index_expression
table: (identifier)
field: (identifier))
field: (identifier))
arguments: (arguments
(identifier)
(string)
(function_call
name: (identifier)
arguments: (arguments))))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (function_call
name: (bracket_index_expression
table: (identifier)
field: (identifier))
arguments: (arguments
(table_constructor
(field
name: (identifier)
value: (true)))))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (function_call
name: (bracket_index_expression
table: (identifier)
field: (identifier))
arguments: (arguments
(string))))))
================================================================================
function_call ::: method_index_expression
================================================================================
tbl.k1:m1(a1, "a2")
tbl[k1]:m1 { f1, "f2" }
tbl:m1 "a1"
--------------------------------------------------------------------------------
(chunk
(function_call
name: (method_index_expression
table: (dot_index_expression
table: (identifier)
field: (identifier))
method: (identifier))
arguments: (arguments
(identifier)
(string)))
(function_call
name: (method_index_expression
table: (bracket_index_expression
table: (identifier)
field: (identifier))
method: (identifier))
arguments: (arguments
(table_constructor
(field
value: (identifier))
(field
value: (string)))))
(function_call
name: (method_index_expression
table: (identifier)
method: (identifier))
arguments: (arguments
(string))))
================================================================================
parenthesized_expression
================================================================================
v = ( true )
v = ( ( false ) )
--------------------------------------------------------------------------------
(chunk
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (parenthesized_expression
(true))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (parenthesized_expression
(parenthesized_expression
(false))))))
================================================================================
table_constructor
================================================================================
tbl1 = {
["k1"] = {
['k2'] = true,
k3 = false
}
}
local tbl2 = {
k1 = {
{ 'v1', "v2" }
}
}
local tbl3 = { "v1", k1 = "v2" }
--------------------------------------------------------------------------------
(chunk
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (table_constructor
(field
name: (string)
value: (table_constructor
(field
name: (string)
value: (true))
(field
name: (identifier)
value: (false)))))))
local_declaration: (variable_declaration
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (table_constructor
(field
name: (identifier)
value: (table_constructor
(field
value: (table_constructor
(field
value: (string))
(field
value: (string))))))))))
local_declaration: (variable_declaration
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (table_constructor
(field
value: (string))
(field
name: (identifier)
value: (string)))))))
================================================================================
binary_expression
================================================================================
a = i + j * 3 - k % 5
b = i + j % 3 ^ 2
c = i * 2 ^ j
--------------------------------------------------------------------------------
(chunk
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (binary_expression
left: (binary_expression
left: (identifier)
right: (binary_expression
left: (identifier)
right: (number)))
right: (binary_expression
left: (identifier)
right: (number)))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (binary_expression
left: (identifier)
right: (binary_expression
left: (identifier)
right: (binary_expression
left: (number)
right: (number))))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (binary_expression
left: (identifier)
right: (binary_expression
left: (number)
right: (identifier))))))
================================================================================
unary_expression
================================================================================
v1 = #l
v2 = -n
v3 = not c1 and r1 or r2
--------------------------------------------------------------------------------
(chunk
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (unary_expression
operand: (identifier))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (unary_expression
operand: (identifier))))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (binary_expression
left: (binary_expression
left: (unary_expression
operand: (identifier))
right: (identifier))
right: (identifier)))))

View file

@ -0,0 +1,459 @@
================================================================================
empty_statement
================================================================================
;
;;
--------------------------------------------------------------------------------
(chunk
(empty_statement)
(empty_statement)
(empty_statement))
================================================================================
assignment_statement
================================================================================
i = 1
j, tbl[k()] = 2, i + 1
x, y = y, x
--------------------------------------------------------------------------------
(chunk
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (number)))
(assignment_statement
(variable_list
name: (identifier)
name: (bracket_index_expression
table: (identifier)
field: (function_call
name: (identifier)
arguments: (arguments))))
(expression_list
value: (number)
value: (binary_expression
left: (identifier)
right: (number))))
(assignment_statement
(variable_list
name: (identifier)
name: (identifier))
(expression_list
value: (identifier)
value: (identifier))))
================================================================================
function_call
================================================================================
f1()
tbl.f2()
tbl["f2"]()
tbl.k1:f3()
f4(a1)("a2") { a3 = "a3" }
--------------------------------------------------------------------------------
(chunk
(function_call
name: (identifier)
arguments: (arguments))
(function_call
name: (dot_index_expression
table: (identifier)
field: (identifier))
arguments: (arguments))
(function_call
name: (bracket_index_expression
table: (identifier)
field: (string))
arguments: (arguments))
(function_call
name: (method_index_expression
table: (dot_index_expression
table: (identifier)
field: (identifier))
method: (identifier))
arguments: (arguments))
(function_call
name: (function_call
name: (function_call
name: (identifier)
arguments: (arguments
(identifier)))
arguments: (arguments
(string)))
arguments: (arguments
(table_constructor
(field
name: (identifier)
value: (string))))))
================================================================================
label_statement
================================================================================
:: label_name ::
--------------------------------------------------------------------------------
(chunk
(label_statement
(identifier)))
================================================================================
break_statement
================================================================================
for k, v in pairs(kv) do
if not v then
break
end
end
--------------------------------------------------------------------------------
(chunk
(for_statement
clause: (for_generic_clause
(variable_list
name: (identifier)
name: (identifier))
(expression_list
(function_call
name: (identifier)
arguments: (arguments
(identifier)))))
body: (block
(if_statement
condition: (unary_expression
operand: (identifier))
consequence: (block
(break_statement))))))
================================================================================
goto_statement
================================================================================
goto label_name
--------------------------------------------------------------------------------
(chunk
(goto_statement
(identifier)))
================================================================================
do_statement
================================================================================
do
f1()
return f2()
end
do end
--------------------------------------------------------------------------------
(chunk
(do_statement
body: (block
(function_call
name: (identifier)
arguments: (arguments))
(return_statement
(expression_list
(function_call
name: (identifier)
arguments: (arguments))))))
(do_statement))
================================================================================
while_statement
================================================================================
while i < 9 do
i = i + 1
end
while false do end
--------------------------------------------------------------------------------
(chunk
(while_statement
condition: (binary_expression
left: (identifier)
right: (number))
body: (block
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (binary_expression
left: (identifier)
right: (number))))))
(while_statement
condition: (false)))
================================================================================
repeat_statement
================================================================================
repeat
f1()
i = i - 1
until i == 0
repeat until false
--------------------------------------------------------------------------------
(chunk
(repeat_statement
body: (block
(function_call
name: (identifier)
arguments: (arguments))
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (binary_expression
left: (identifier)
right: (number)))))
condition: (binary_expression
left: (identifier)
right: (number)))
(repeat_statement
condition: (false)))
================================================================================
if_statement
================================================================================
if num % 2 == 0 then
print("even")
elseif num % 2 ~= 0 then
print("odd")
else
error("!")
end
if c1 then end
if c1 then else end
if c1 then elseif c2 then else end
--------------------------------------------------------------------------------
(chunk
(if_statement
condition: (binary_expression
left: (binary_expression
left: (identifier)
right: (number))
right: (number))
consequence: (block
(function_call
name: (identifier)
arguments: (arguments
(string))))
alternative: (elseif_statement
condition: (binary_expression
left: (binary_expression
left: (identifier)
right: (number))
right: (number))
consequence: (block
(function_call
name: (identifier)
arguments: (arguments
(string)))))
alternative: (else_statement
body: (block
(function_call
name: (identifier)
arguments: (arguments
(string))))))
(if_statement
condition: (identifier))
(if_statement
condition: (identifier)
alternative: (else_statement))
(if_statement
condition: (identifier)
alternative: (elseif_statement
condition: (identifier))
alternative: (else_statement)))
================================================================================
for_statement ::: for_generic_clause
================================================================================
for k, v in pairs(kv) do
print(k, v)
end
for i in ipairs(iv) do end
--------------------------------------------------------------------------------
(chunk
(for_statement
clause: (for_generic_clause
(variable_list
name: (identifier)
name: (identifier))
(expression_list
(function_call
name: (identifier)
arguments: (arguments
(identifier)))))
body: (block
(function_call
name: (identifier)
arguments: (arguments
(identifier)
(identifier)))))
(for_statement
clause: (for_generic_clause
(variable_list
name: (identifier))
(expression_list
(function_call
name: (identifier)
arguments: (arguments
(identifier)))))))
================================================================================
for_statement ::: for_numeric_clause
================================================================================
for n = 1, 10 do
print(n)
end
for n = 1, 10, 2 do end
--------------------------------------------------------------------------------
(chunk
(for_statement
clause: (for_numeric_clause
name: (identifier)
start: (number)
end: (number))
body: (block
(function_call
name: (identifier)
arguments: (arguments
(identifier)))))
(for_statement
clause: (for_numeric_clause
name: (identifier)
start: (number)
end: (number)
step: (number))))
================================================================================
function_declaration
================================================================================
function tbl.f1() end
function tbl:f2() end
function tbl.k1:f3() end
function f4()
print('f4')
end
local function f5() end
--------------------------------------------------------------------------------
(chunk
(function_declaration
name: (dot_index_expression
table: (identifier)
field: (identifier))
parameters: (parameters))
(function_declaration
name: (method_index_expression
table: (identifier)
method: (identifier))
parameters: (parameters))
(function_declaration
name: (method_index_expression
table: (dot_index_expression
table: (identifier)
field: (identifier))
method: (identifier))
parameters: (parameters))
(function_declaration
name: (identifier)
parameters: (parameters)
body: (block
(function_call
name: (identifier)
arguments: (arguments
(string)))))
local_declaration: (function_declaration
name: (identifier)
parameters: (parameters)))
================================================================================
variable_declaration
================================================================================
local v1 = 1
local v2, v3 = 2, 3
local v4, v4 = f1(), tbl:f2()
--------------------------------------------------------------------------------
(chunk
local_declaration: (variable_declaration
(assignment_statement
(variable_list
name: (identifier))
(expression_list
value: (number))))
local_declaration: (variable_declaration
(assignment_statement
(variable_list
name: (identifier)
name: (identifier))
(expression_list
value: (number)
value: (number))))
local_declaration: (variable_declaration
(assignment_statement
(variable_list
name: (identifier)
name: (identifier))
(expression_list
value: (function_call
name: (identifier)
arguments: (arguments))
value: (function_call
name: (method_index_expression
table: (identifier)
method: (identifier))
arguments: (arguments))))))