Skip to content
This repository has been archived by the owner on Jun 3, 2022. It is now read-only.

WIP: Lua documentation #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
build
*.log

# Seems like we'd want to ignore this...
tree-sitter-lua.wasm
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"bracketSpacing": true,
"trailingComma": "all",
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true
}
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

generate:
tree-sitter generate

test: generate
tree-sitter test

build_parser: generate
cc -o ./build/parser.so -I./src src/parser.c src/scanner.cc -shared -Os -lstdc++ -fPIC

wasm: build_parser
tree-sitter build-wasm

web: wasm
tree-sitter web-ui
50 changes: 50 additions & 0 deletions corpus/comments.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
============================================
Simplest comment
============================================

-- Simple comments work

---

(program (comment))

============================================
Comments
============================================
Expand All @@ -15,6 +25,7 @@ a level 0 multi-line comment

--[==[
a level 2 multi-line comment
we can stil lhave a ] in here
]==]

-- [==[
Expand All @@ -25,6 +36,7 @@ a level 2 multi-line comment

(program
(comment)

(comment)

(comment)
Expand All @@ -34,3 +46,41 @@ a level 2 multi-line comment
(comment)

(comment))

============================================
In-line Comments
============================================

local a = 1 -- this is a comment

---

(program
(local_variable_declaration (variable_declarator (identifier)) (number))
(comment))

============================================
Comments - In between still fine.
============================================


--[==[
a level 2 multi-line comment
]==]

x = 1

-- [==[
a level 2 multi-line ]= comment
]==]


---

(program
(comment)
(variable_declaration
(variable_declarator (identifier))
(number))
(comment))

156 changes: 156 additions & 0 deletions corpus/documentation_comments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
============================================
Simple documentation
============================================

--- hello world
--
-- wow cool
function cool_function()
return true
end

----------

(program
(function
(lua_documentation)
(function_name (identifier)) (parameters)
(return_statement (true))))

============================================
TODO: We should make it so that those show up as special comments for the function
============================================


============================================
Full documentation
============================================

--- A function description
--@param p: param value
--@param x: another value
--@returns true
function cool_function(p, x)
return true
end

----------

(program
(function
(lua_documentation
(parameter_documentation
name: (identifier)
description: (parameter_description))
(parameter_documentation
name: (identifier)
description: (parameter_description))

(return_description))

(function_name (identifier))
(parameters
(identifier)
(identifier))

(return_statement (true))))

============================================
Local documentation
============================================

--- A function description
--@param p: param value
--@param x: another value
--@returns true
local function cool_function(p, x)
return true
end

----------

(program
(local_function
(lua_documentation
(parameter_documentation
name: (identifier)
description: (parameter_description))
(parameter_documentation
name: (identifier)
description: (parameter_description))

(return_description))

(identifier)
(parameters
(identifier)
(identifier))

(return_statement (true))))

============================================
Full documentation with assignment
============================================

local x = {}

--- hello world
--@param y: add 1
x.my_func = function(y)
return y + 1
end

---

(program
(local_variable_declaration
variable: (variable_declarator (identifier)) (table))

(variable_declaration
documentation: (lua_documentation
(parameter_documentation
name: (identifier)
description: (parameter_description)))

variable: (variable_declarator
(field_expression (identifier) (property_identifier)))

expression: (function_definition
(parameters (identifier))
(return_statement (binary_operation (identifier) (number))))

))


============================================
Full documentation with assignment bracket
============================================

local x = {}

--- hello world
--@param y: add 1
x["my_func"] = function(y)
return y + 1
end

---

(program
(local_variable_declaration
variable: (variable_declarator (identifier)) (table))

(variable_declaration
documentation: (lua_documentation
(parameter_documentation
name: (identifier)
description: (parameter_description)))

variable: (variable_declarator (identifier) (string))

expression: (function_definition
(parameters (identifier))
(return_statement (binary_operation (identifier) (number))))

))

14 changes: 14 additions & 0 deletions corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ c = i * 2 ^ j
(binary_operation (identifier)
(binary_operation (number) (identifier)))))

============================================
Weird Unary operations
============================================

food_table_size = - -a

---

(program
(variable_declaration
(variable_declarator (identifier))
(unary_operation
(unary_operation (identifier)))))

============================================
Unary operations
============================================
Expand Down
13 changes: 13 additions & 0 deletions corpus/module.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
============================================
Module Returns
============================================

local x = {}

return x

---

(program
(local_variable_declaration (variable_declarator (identifier)) (table))
(module_return_statement (identifier)))
12 changes: 12 additions & 0 deletions corpus/simple_fields.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
============================================
Simple Fields
============================================

local x = 1

---

(program
(local_variable_declaration
(variable_declarator (identifier))
(number)))
Loading