Skip to content

Commit 6edc682

Browse files
committed
Candran 0.12.0
1 parent 33ac4c5 commit 6edc682

3 files changed

Lines changed: 62 additions & 22 deletions

File tree

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ end
7272
Candran is released under the MIT License (see ```LICENSE``` for details).
7373

7474
#### Quick setup
75-
Install Candran automatically using LuaRocks: ```sudo luarocks install rockspec/candran-0.11.0-1.rockspec```.
75+
Install Candran automatically using LuaRocks: ```sudo luarocks install rockspec/candran-0.12.0-1.rockspec```.
7676

7777
Or manually install LPegLabel (```luarocks install lpeglabel```, version 1.5 or above), download this repository and use Candran through the scripts in ```bin/``` or use it as a library with the self-contained ```candran.lua```.
7878

79-
You can optionally install lua-linenoise (```luarocks install linenoise```, version 0.9 or above) for an improved REPL. The rockspec will install linenoise by default.
79+
You can optionally install lua-linenoise (```luarocks install linenoise```, version 0.9 or above) for an improved REPL, and luacheck (```luarocks install luacheck```, version 0.23.0 or above) to be able to use ```cancheck```. Installing Candran using LuaRocks will install linenoise and luacheck by default.
8080

8181
You can register the Candran package searcher in your main Lua file (`require("candran").setup()`) and any subsequent `require` call in your project will automatically search for Candran modules.
8282

@@ -87,6 +87,8 @@ Most editors should be able to use their existing Lua support for Candran code.
8787
* [SublimeLinter-candran-contrib](https://github.com/Reuh/SublimeLinter-contrib-candran) SublimeLinter plugin for Candran
8888
* **Atom**: [language-candran](https://atom.io/packages/language-candran) support the full Candran syntax
8989

90+
For linting, if your editor support [luacheck](https://github.com/luarocks/luacheck), you should be able to replace it with ```cancheck``` (in this repository ```bin/cancheck```, or installed automatically if Candran was installed using LuaRocks), which is a wrapper around luacheck that monkey-patch it to support Candran.
91+
9092
The language
9193
------------
9294
### Syntax additions
@@ -495,7 +497,7 @@ The library can be used standalone through the ```canc``` and ```can``` utility:
495497

496498
Start a simplisitic Candran REPL.
497499

498-
If you want a better REPL (autocompletion, history, ability to move the cursor), install lua-linenoise: ```luarocks install linenoise```.
500+
If you want a better REPL (autocompletion, history, ability to move the cursor), install lua-linenoise: ```luarocks install linenoise``` (automatically installed if Candran was installed using LuaRocks).
499501

500502
* ````can [options] filename````
501503

@@ -509,6 +511,12 @@ The library can be used standalone through the ```canc``` and ```can``` utility:
509511

510512
Use the ```-h``` or ```-help``` option to display a short help text.
511513

514+
* ```cancheck```
515+
516+
Provides a linter and static analyzer with the exact same interface as [luacheck](https://github.com/luarocks/luacheck).
517+
518+
This requires luacheck: ```luarocks install luacheck``` (automatically installed if Candran was installed through LuaRocks).
519+
512520
### Library usage
513521
Candran can also be used as a Lua library:
514522
````lua
@@ -534,9 +542,9 @@ The table returned by _require("candran")_ gives you access to:
534542

535543
##### Compiler & preprocessor
536544
* ````candran.VERSION````: Candran's version string (e.g. `"0.10.0"`).
537-
* ````candran.preprocess(code[, options])````: return the Candran code _code_, preprocessed with the _options_ options table.
538-
* ````candran.compile(code[, options])````: return the Candran code compiled to Lua with the _options_ option table.
539-
* ````candran.make(code[, options])````: return the Candran code, preprocessed and compiled with the _options_ options table.
545+
* ````candran.preprocess(code[, options])````: return the Candran code _code_, preprocessed with the _options_ options table; or nil, err in case of error.
546+
* ````candran.compile(code[, options])````: return the Candran code compiled to Lua with the _options_ option table; or nil, err in case of error.
547+
* ````candran.make(code[, options])````: return the Candran code, preprocessed and compiled with the _options_ options table; or nil, err in case of error.
540548

541549
##### Code loading helpers
542550
* ```candran.loadfile(filepath, env, options)```: Candran equivalent to the Lua 5.3's loadfile funtion. Will rewrite errors by default.

bin/cancheck

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
11
#!/usr/bin/env lua
22

3+
--[[
4+
Based on luacheck: https://github.com/luarocks/luacheck
5+
6+
The MIT License (MIT)
7+
8+
Copyright (c) 2014 - 2018 Peter Melnichenko
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
SOFTWARE.
27+
]]
28+
329
-- Monkey patch Luacheck (tested against version 0.23.0) to support Candran files
430
local candran = require("candran")
531
local util = require("candran.util")
632

33+
-- set a function upvalues (if several names are given, will go up the upvalue chain)
34+
local function setupvalue(fn, val, name, ...)
35+
for i=1, debug.getinfo(fn, "u").nups do
36+
local n, v = debug.getupvalue(fn, i)
37+
if n == name then
38+
if not ... then
39+
debug.setupvalue(fn, i, val)
40+
else
41+
setupvalue(v, val, ...)
42+
end
43+
end
44+
end
45+
end
46+
47+
-- escape a string to be used as a pattern
748
local function escape(str)
849
return str:gsub("[^%w]", "%%%0")
950
end
1051

52+
-- returns a pattern that find start and stop position of a token
1153
local function pattern(token)
1254
return "()"..escape(token).."()"
1355
end
1456

57+
-- token aliases
1558
local tokenAlias = {
1659
["self"] = { "@", ":" }
1760
}
@@ -135,18 +178,6 @@ local function format_location(file, location, opts)
135178
end
136179
return res
137180
end
138-
local function setupvalue(fn, val, name, ...)
139-
for i=1, debug.getinfo(fn, "u").nups do
140-
local n, v = debug.getupvalue(fn, i)
141-
if n == name then
142-
if not ... then
143-
debug.setupvalue(fn, i, val)
144-
else
145-
setupvalue(v, val, ...)
146-
end
147-
end
148-
end
149-
end
150181
setupvalue(format.builtin_formatters.plain, format_location, "format_event", "format_location")
151182

152183
-- Fix some Luacheck messages and run
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ rockspec_format = "3.0"
22

33
package = "candran"
44

5-
version = "0.11.0-1"
5+
version = "0.12.0-1"
66

77
description = {
88
summary = "A simple Lua dialect and preprocessor.",
@@ -19,13 +19,14 @@ description = {
1919

2020
source = {
2121
url = "git://github.com/Reuh/candran",
22-
tag = "v0.11.0"
22+
tag = "v0.12.0"
2323
}
2424

2525
dependencies = {
2626
"lua >= 5.1",
2727
"lpeglabel >= 1.5.0",
28-
"linenoise >= 0.9"
28+
"linenoise >= 0.9",
29+
"luacheck >= 0.23.0"
2930
}
3031

3132
build = {
@@ -34,6 +35,6 @@ build = {
3435
candran = "candran.lua"
3536
},
3637
install = {
37-
bin = { "bin/can", "bin/canc" }
38+
bin = { "bin/can", "bin/canc", "bin/cancheck" }
3839
}
3940
}

0 commit comments

Comments
 (0)