Răsfoiți Sursa

Add README;

bjorn 10 ani în urmă
părinte
comite
915691b6cd
2 a modificat fișierele cu 83 adăugiri și 5 ștergeri
  1. 78 0
      README.md
  2. 5 5
      docroc.lua

+ 78 - 0
README.md

@@ -0,0 +1,78 @@
+docroc
+===
+
+Minimal library that parses formatted Lua comments and returns them as a table.
+
+Usage
+---
+
+```lua
+local docroc = require 'docroc'
+local comments = docroc.process('file.lua')
+```
+
+`comments` is now a table of comment blocks in the file, each with a table of `tags` and a `context` key. The `tags` table is an array of each tag, but also groups the tags by type. The `context` key is a string containing the contents of the line after the comment block.
+
+Notes on parsing:
+
+- A comment block must start with three dashes. It ends on the next non-commentented line.
+- Tags are recognized as any sequence of letters that start with `@`, and continue until the next tag is encountered. The first tag is implicitly `@description`.
+
+Example
+---
+
+Go from this:
+
+```lua
+--- Displays a friendly greeting.
+-- @arg {string=} name - The person to greet.
+-- @returns {number}
+function greet(name)
+  print('hi', name)
+  return 3, 4
+end
+```
+
+to this:
+
+```lua
+{
+  {
+    context = 'function greet(name)',
+    tags = {
+      [1] = {
+        tag = 'description',
+        raw = 'The person to greet.',
+        text = 'The person to greet.'
+      },
+      [2] = {
+        tag = 'arg',
+        raw = '{string=} name - The person to greet',
+        type = 'string',
+        optional = true,
+        name = 'name',
+        description = 'The person to greet.'
+      },
+      [3] = {
+        tag = 'returns',
+        raw = '{number}',
+        type = 'number'
+      },
+      description = {...},
+      arg = {...},
+      returns = {...}
+    }
+  }
+}
+```
+
+Related
+---
+
+- [Locco](http://rgieseke.github.io/locco)
+- [LDoc](https://github.com/stevedonovan/LDoc)
+
+License
+---
+
+MIT, see [`LICENSE`](LICENSE) for details.

+ 5 - 5
docroc.lua

@@ -2,9 +2,9 @@
 -- https://github.com/bjornbytes/docroc
 -- License - MIT, see LICENSE for details.
 
-local rocdoc = {}
+local docroc = {}
 
-function rocdoc.process(filename)
+function docroc.process(filename)
   local file = io.open(filename, 'r')
   local text = file:read('*a')
   file:close()
@@ -18,7 +18,7 @@ function rocdoc.process(filename)
     local tags = {}
     chunk:gsub('@(%w+)%s?([^@]*)', function(name, body)
       body = body:gsub('(%s+)$', '')
-      local processor = rocdoc.processors[name]
+      local processor = docroc.processors[name]
       local tag = processor and processor(body) or {}
       tag.tag = name
       tag.raw = body
@@ -36,7 +36,7 @@ function rocdoc.process(filename)
   return comments
 end
 
-rocdoc.processors = {
+docroc.processors = {
   description = function(body)
     return {
       text = body
@@ -84,4 +84,4 @@ rocdoc.processors = {
   end
 }
 
-return rocdoc
+return docroc