Skip to content

Commit d979c4e

Browse files
committed
Add modules documentation
1 parent 1f7c9ed commit d979c4e

File tree

9 files changed

+220
-1
lines changed

9 files changed

+220
-1
lines changed

docs/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
# lapse-hs
22

33
Hello, this is official [Lapse](https://github.com/ProggerX/lapse-hs) documentation. Lapse is my LISP dialect that was created in educational purposes only.
4+
5+
## Why use it?
6+
Lapse is really small language but it has some [modules](modules/index.md) for different use-cases.
7+
8+
## Installation guide
9+
- Go to [this page](https://github.com/ProggerX/lapse-hs/actions/workflows/build.yml)
10+
- Click on latest successful action run from master (or run from specific commit)
11+
- Find an "Artifacts" section and download version for your OS. (If you can't see download button, log in to your github account)
12+
- Unzip this artifact and you will get an executable of Lapse interpreter
13+
- To run some code, write this code in ".lp" file (in fact, extension does not matter) and run `<path-to-lapse-interpreter> <path-to-file>` command in command line
14+
- (You can find example files [here](https://github.com/ProggerX/lapse-hs/blob/master/example/))
15+
- Also, Lapse provides a clean REPL by `<path-to-lapse-interpreter>` command

docs/modules/colors.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# ANSI terminal colors
2+
3+
### Description
4+
Small module that allows you to type thing like `(blue "hello")` and produces string with that color (e.g. `"\e[0;34mhello\e[0m"`).
5+
6+
### Import
7+
```
8+
(import "colors")
9+
```
10+
11+
### Usage
12+
```
13+
(print $ blue "Hello, user!")
14+
```
15+
16+
### Reference
17+
- `(black <string>)` -- produces black string.
18+
- `(red <string>)` -- produces red string.
19+
- `(green <string>)` -- produces green string.
20+
- `(yellow <string>)` -- produces yellow string.
21+
- `(blue <string>)` -- produces blue string.
22+
- `(purple <string>)` -- produces purple string.
23+
- `(cyan <string>)` -- produces cyan string.
24+
- `(white <string>)` -- produces white string.
25+
26+
### Source
27+
[Source](https://github.com/ProggerX/lapse-hs/blob/master/modules/colors.lp)

docs/modules/fs.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Filesystem
2+
3+
### Description
4+
Module that allows you to interact with files.
5+
6+
### Import
7+
```
8+
(import "fs")
9+
```
10+
11+
### Usage
12+
```
13+
(print $ readF "text.txt")
14+
```
15+
16+
### Reference
17+
- `(readF <string:filename>)` -- reads file as string and returns its text.
18+
- `(writeF <string:filename> <string:contents>)` -- writes contents to file.
19+
- `(appendF <string:filename> <string:contents>)` -- appends contents to file.
20+
- `(lsdir)` -- returns list of strings -- files in CWD.
21+
- `(lsdir <string:path>)` -- returns list of strings -- files in `path`.
22+
- `(chdir <string:path>)` -- changes CWD to `path`.
23+
24+
### Source
25+
[Source](https://github.com/ProggerX/lapse-hs/blob/master/src/Lapse/Modules/FS.hs)

docs/modules/gcode.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# G-code generator
2+
3+
### Description
4+
Module that allows you to generate G-code from human-readable LISP code and prints it to stdout.
5+
6+
### Import
7+
```
8+
(import "gcode")
9+
```
10+
11+
### Usage
12+
```
13+
(import "gcode")
14+
15+
(init "plra4")
16+
(base)
17+
(go 5 50)
18+
(delta 5 -40)
19+
(down)
20+
(left 5)
21+
(right 20)
22+
(forward 50)
23+
(right 20)
24+
(backward 15)
25+
(base)
26+
(end)
27+
```
28+
29+
### Reference
30+
- `(init <string:name>)` -- init G-code for machine with name `name` (runs `init_func` of machine).
31+
- `(machine <string:name> <function:init_func> <function:end_func>)` -- creates custom machine with name `name`, init `init_func` and end `end_func`.
32+
- `(end)` -- end of G-code (runs `end_func` of machine).
33+
- `(base)` -- go to base (`G0Z10`; `G0X0Y0`; disable cutting).
34+
- `(down)` -- enable cutting and run `G1Z<material-z>F<speed>`.
35+
- `(up)` -- disable cutting and run `G0Z10`.
36+
- `(go x y)` -- go to x, y (`G0X<x>Y<y>` or `G1X<x>Y<y>F<speed>`).
37+
- `(delta x y)` -- same as go, but relative to current position.
38+
- `left, right, forward, backward` -- extra functions on top of delta.
39+
40+
### Source
41+
[Source](https://github.com/ProggerX/lapse-hs/blob/master/modules/gcode.lp)

docs/modules/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Modules
2+
3+
Lapse includes different modules:
4+
5+
- [ANSI terminal colors](colors.md)
6+
- [G-code generator](gcode.md)
7+
- [Filesystem](fs.md)
8+
- [JSON](json.md)
9+
- [Web server and client](web.md)

docs/modules/json.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# JSON
2+
3+
### Description
4+
Module that allows you to encode and decode JSON.
5+
6+
### Import
7+
```
8+
(import "json")
9+
```
10+
11+
### Usage
12+
```
13+
(print $ decode $ encode 5)
14+
```
15+
16+
### Reference
17+
- `(encode <value:data>)` -- encodes `data` to JSON (Of course, it cannot store functions and macroses) and returns string.
18+
- `(decode <string:json-data>)` -- decodes JSON and returns value (All numbers become floats!)
19+
20+
### Source
21+
[Source](https://github.com/ProggerX/lapse-hs/blob/master/src/Lapse/Modules/Json.hs)

docs/modules/web.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Web (server and client)
2+
3+
### Description
4+
Module that allows you to make small web servers and clients.
5+
6+
### Import
7+
```
8+
(import "web")
9+
```
10+
11+
### Usage
12+
#### Server
13+
```lisp
14+
-- Built for web client from examples
15+
16+
(import "std" "web" "json")
17+
18+
(defn greet (fn ln) (concat "Hello, " fn " " ln "!"))
19+
20+
- Create a handler
21+
(defn f (fn ln) (encode $ dict
22+
(first_name fn)
23+
(last_name ln)
24+
(greeting $ greet fn ln)))
25+
26+
(defn fpost (txt fn ln) (concat txt " " fn " " ln))
27+
28+
(defn echo (body) body)
29+
30+
- Build + serve
31+
(serve
32+
$ routeGET "/greet" (list "fname" "lname") f
33+
$ routePOST "/post" (list "fname" "lname") fpost
34+
$ routePOST "/echo" () echo
35+
$ server 2025)
36+
```
37+
#### Client
38+
```lisp
39+
-- Uses web server from examples
40+
41+
(import "web" "std" "io" "json")
42+
43+
- Build request
44+
(set rget $ send
45+
$ withParam "fname" "John"
46+
$ withParam "lname" "Black"
47+
$ get "http://localhost:2025/greet")
48+
49+
- Print response
50+
(print $ concat "Got response: " $ show rget)
51+
(print "Body:")
52+
(print $ resBody rget)
53+
54+
- Decode JSON and get a greeting
55+
(set gr $ lookup greeting $ fst $ decode $ resBody rget)
56+
57+
(print "Greeting:")
58+
(print gr)
59+
```
60+
61+
### Reference
62+
#### Server
63+
- `(server <number:port>)` -- creates a web server on port `port`.
64+
- `(routeGET <string:path> <list of strings:params> <function(params -> string):handler> <server>)` -- adds GET route to `server`.
65+
- `(routePOST <string:path> <list of strings:params> <function(body, params -> string):handler> <server>)` -- adds POST route to `server`.
66+
- `(serve <server>)` -- serves a server.
67+
#### Client
68+
- `(get <string:url>)` -- creates a GET request to `url`.
69+
- `(post <string:url>)` -- creates a POST request to `url`.
70+
- `(withParam <string:name> <string or list of strings:value(s)>)` -- adds param to request.
71+
- `(withBody <string:body>)` -- adds body to request.
72+
- `(send <request>)` -- sends `request` and returns response.
73+
- `(resStatus <response>)` -- returns statusCode of `response`.
74+
- `(resBody <response>)` -- returns body of `response`.
75+
76+
### Source
77+
[Source](https://github.com/ProggerX/lapse-hs/tree/master/src/Lapse/Modules/Web)

example/gcode.lp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(import "std" "io" "gcode")
1+
(import "gcode")
22

33
(init "plra4")
44
(base)

mkdocs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
site_name: Lapse Docs
22
nav:
33
- Lapse: index.md
4+
- Modules:
5+
- Index: modules/index.md
6+
- Colors: modules/colors.md
7+
- G-code: modules/gcode.md
8+
- FS: modules/fs.md
9+
- JSON: modules/json.md
10+
- Web: modules/web.md
411
theme: readthedocs

0 commit comments

Comments
 (0)