From 87ae0d70b2bc1c5aa4078602a343f2c2d3db3feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Mon, 17 Feb 2020 19:49:05 +0000 Subject: extend README MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Asbjørn Sloth Tønnesen --- README.rst | 47 ++++++++++++++++++++++++++++++++++++++++++++--- test/readme.lua | 5 ++++- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 744cac6..207b1d9 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,8 @@ ``inet`` - an IP address mangling library ========================================= -``inet`` is meant to make it fun to do IP address calculations. +``inet`` is meant to make it simple and fun to do IP address calculations, +subnet math and similar IP address related arithmetics. :: @@ -14,13 +15,51 @@ -- get last /64 in a /56 inet('2001:db8::/56') * 1 / 64 * -1 -- returns inet('2001:db8:0:ff::/64') +All examples on this page, are tested when ``make test`` is run. Dependencies ============ -- Lua_ version 5.2, 5.3 or 5.4 alpha +- Lua_ version 5.2, 5.3 or 5.4 beta - LPeg_ - Parsing Expression Grammars For Lua +Install +======= + +You can install lua-inet in several ways, +after all it is just a pure Lua library. + +From git +-------- + +System-wide +~~~~~~~~~~~ + +:: + + $ sudo -i + # apt install lua-lpeg + # git clone https://git.2e8.dk/lua-inet /opt/lua-inet + # mkdir -p /usr/local/share/lua/5.3 + # ln -s /opt/lua-inet/lua/inet /usr/local/share/lua/5.3/inet + +Local user +~~~~~~~~~~ + +Clone this repo to somewhere, then include this repo's ``lua/`` in your +``package.path``, with something like this:: + + package.path = '/PATH/TO/lua/?.lua;/PATH/TO/lua/?/init.lua;'..package.path + +See also the `LUA_INIT`_ environment variable. + +LuaRocks +-------- + +If you want you can also use LuaRocks_:: + + $ luarocks install inet + API === @@ -172,7 +211,7 @@ Addition ``foo - bar`` ~~~~~~~~~~~~~ -Subtract +Subtraction :: @@ -528,6 +567,8 @@ This project is licensed under `GNU Lesser General Public License version 3`_ or .. _Fiberby: https://peeringdb.com/asn/42541 .. _Lua: http://www.lua.org/ .. _LPeg: http://www.inf.puc-rio.br/~roberto/lpeg/ +.. _LuaRocks: https://luarocks.org/modules/asbjorn/inet +.. _LUA_INIT: http://www.lua.org/manual/5.3/manual.html#pdf-LUA_INIT .. _RFC 4632: https://tools.ietf.org/html/rfc4632 .. _RFC 5952: https://tools.ietf.org/html/rfc5952 .. _GNU Lesser General Public License version 3: https://www.gnu.org/licenses/lgpl-3.0.en.html diff --git a/test/readme.lua b/test/readme.lua index dd39dac..ead30dc 100644 --- a/test/readme.lua +++ b/test/readme.lua @@ -36,9 +36,12 @@ do local assignment = Ct(Cc('assignment') * assign_left * assign_mid * assign_right) local comment = P('--') * rest_of_line local indented_line = sp^2 * (comment + example + assignment) * sp^0 + local section = P('=')^1 + local install_hdr = P('Install') * nl * section * nl + local install_section = install_hdr * ((rest_of_line * nl) - section)^1 * section local anyline = rest_of_line - (sp * rest_of_line) local non_match = Ct(Cc('unable to parse line') * C(rest_of_line)) - local line = indented_line + anyline + non_match + local line = indented_line + install_section + anyline + non_match readme_parser = Ct((line * nl)^0 * line^-1 * -1) end -- cgit v1.2.1