GithubHelp home page GithubHelp logo

lpp's Introduction

lpp

tiny (80 SLOC) lua preprocessor thing created for personal use

usage

luajit lpp.lua /path/to/file.lpp.lua > output.txt

both lua 5.1 and luajit are supported
.lpp.lua is currently the suggested file extension for lpp files

example

|>! postprocess "remove_empty_lines" <|

|>
  name = "Bob"
  age = 36
<|

Hello! My name is |>! name <|, and my age is |>! age <|. 
I have "|>! -math.huge <|" friends :(.

Some math operations: (age * 36) / 2 = |>! (age * 36) / 2  <|

|>- I'm a comment! |<


Today's lucky number is... |>! math.random(100) <|

Output:

Hello! My name is Bob, and my age is 36.
I have "-inf" friends :(.
Some math operations: (age * 36) / 2 = 648
Today's lucky number is... 60

syntax

wrap your lua code between |> ... <|
returned value gets added to the output
use these to define your globals and functions

inline blocks:

|>! ... <| evaluate a single expression
basically a shorthand for |> return (...) <|
example: |>! 5 * 5 <|

comments:

|>- ... <|
self-explanatory

includes

|>! include "bf_fun.lpp.lua" <|

notice how include(...) is just a normal lua function!

|>! file "data.txt" <|

inserts file without any preprocessing
(again, this is a normal lua function that can be called from anywhere

post-processing

postprocess(...)

adds post-process filter to the queue. runs after the final file is generated

usage:

accepts strings and functions.

|>! postprocess "remove_whitespace" <|
|>! postprocess(postprocess.remove_whitespace) <|
|>! postprocess(function(data)  ... end) <|

strings act as pointers to items in the global postprocess table. they can be defined like so:

postprocess.remove_whitespace = function(data)
  return data:gsub('%s', '')
end

built-in post-processing functions:

  • remove_whitespace: removes all whitespace (including line breaks)
  • convert_crlf: converts \r\n line endings to \n
  • remove_empty_lines: removes all empty lines (lines that don't contain anything)

emit api

_(...) function can be used to write to the file multiple times per block.
it can be useful for loops and conditions.
please note that emit api is incompatible with return values!

emit api example:

|>
  local text = "hello world"
  for i=1,#text do
    _ (text:sub(i,i):byte())
    _ ", "
  end
<|

output: 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100,

security

none.

lpp's People

Contributors

griffi-gh avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.