Skip to content

Commit 6d608b4

Browse files
committed
Initial commit
1 parent 5cdc4be commit 6d608b4

File tree

8 files changed

+544
-0
lines changed

8 files changed

+544
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
*/*.swp
3+
*.swp

Cargo.lock

Lines changed: 187 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "hyperlisp"
3+
version = "0.1.0"
4+
authors = ["curlpipe <[email protected]>"]
5+
edition = "2018"
6+
7+
[profile.release]
8+
lto = true
9+
panic = 'abort'
10+
11+
[dependencies]
12+
ezcli = "0.3.4"
13+
pest = "2.1.3"
14+
pest_derive = "2.1.0"

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Hyperlisp
2+
3+
## What the heck is hyperlisp?
4+
5+
- It's a markup language designed for the web
6+
- It transpiles directly into html
7+
- It's written in Rust therefore it can transpile quickly
8+
- It's inspired by Lisp and isn't too verbose
9+
- It's free to use for any purpose you wish
10+
- Feel free to modify and play around with how it's made
11+
- It's only 145 lines of code (excluding comments and blank lines)
12+
- The code is well commented
13+
<!-- It'll alert you to any errors in your markup, making it easier to debug -->
14+
15+
## Installation
16+
17+
You can run the following commands on linux to get it up and running
18+
```sh
19+
git clone https://github.com/curlpipe/hyperlisp.git
20+
cd hyperlisp
21+
cargo build --release
22+
sudo cp target/release/hyperlisp /usr/bin/
23+
```
24+
25+
Or you can use the prebuilt binaries provided in the releases section and move it to `/usr/bin/`
26+
27+
## Conversion from hyperlisp to html
28+
After installation, you'll be able to convert hyperlisp files into html
29+
30+
To show the help menu:
31+
```
32+
hyperlisp -h
33+
```
34+
35+
To convert `index.hp` file into html and print it out:
36+
```
37+
hyperlisp -i index.hp
38+
```
39+
40+
To convert `index.hp` file into `index.html`:
41+
```
42+
hyperlisp -i index.hp -o index.html
43+
```
44+
45+
## Syntax
46+
You can check out the examples folder to see some examples of how to write it.
47+
48+
Below are some smaller snippets to help you quickly grasp the language.
49+
50+
### Single tags
51+
52+
```lisp
53+
(h1 Hello World)
54+
```
55+
56+
```html
57+
<h1>Hello World</h1>
58+
```
59+
60+
### Nested tags
61+
```lisp
62+
(h1 This is an example of (b Nested tags!) Pretty cool!)
63+
```
64+
65+
```html
66+
<h1>This is an example of <b>Nested tags!</b> Pretty cool!</h1>
67+
```
68+
69+
### Attributes
70+
```lisp
71+
(div id="background" class="container gradient"
72+
Here's a tag: (h1 This is a div)
73+
)
74+
```
75+
76+
```html
77+
<div id="background" class="container gradient">
78+
Here's a tag: <h1>This is a div</h1>
79+
</div>
80+
```
81+
82+
### Multiple nested tags
83+
```lisp
84+
(body (h1 Tag number 1) (p Tag number 2))
85+
```
86+
87+
```html
88+
<body><h1>Tag number 1</h1> <p>Tag number 2</p></body>
89+
```
90+
91+
### Comments
92+
```lisp
93+
(h1 This is a heading, it is displayed) !(This is a comment and it's not displayed)
94+
```
95+
96+
```html
97+
<h1>This is a heading, it is displayed</h1>
98+
```
99+

examples/0.hp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(html
2+
(head
3+
(title HTML test!)
4+
)
5+
(body
6+
(h1 Hello World!)
7+
(p This is an example of hyperlisp)
8+
(p You can nest tags (b style="color: blue" easily))
9+
)
10+
)

examples/1.hp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(html lang="en"
2+
(head
3+
(title Hyperlisp)
4+
)
5+
(body style="font-family: verdana;"
6+
(h1 Hyperlisp!)
7+
(hr)
8+
(p This is an example of (b style="color: blue;" hyperlisp))
9+
(h2 What the hell is hyperlisp?)
10+
(ul
11+
(li It's a markup language designed for the web)
12+
(li It's written in Rust and can transpile very quickly)
13+
(li It's inspired by Lisp, providing a nice way to write webpages)
14+
(li It's free, open source and you can learn it pretty quickly)
15+
(li It'll alert you to any errors in your markup, making it easier to debug)
16+
)
17+
(h2 How do I use it?)
18+
(p
19+
You can head to my
20+
(a href="https://github.com/curlpipe/hyperlisp" Github repository)
21+
where you'll find everything you need to get started
22+
)
23+
(p I hope that this tool makes you more productive :D)
24+
(br)
25+
(p - Curlpipe)
26+
)
27+
)

src/hyperlisp.pest

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Root is the roots of the tree, contains all the tags
2+
root = { (WHITESPACE | comment | tag)* }
3+
4+
// A tag is made up of an id, attributes and body
5+
tag = ${ "(" ~ id ~ (" " ~ attribute)* ~ (" "? ~ body)? ~ ")" }
6+
7+
// An ID is a html element name, e.g. "h1" or "script"
8+
id = ${ (!(")" | "(" | " " | "!" | "\n" | "\t") ~ ANY)+ }
9+
10+
// An attribute is where extra info is provided like styling and classes
11+
attribute = ${ name ~ "=" ~ "\"" ~ value ~ "\"" }
12+
13+
// Name captures anythign that isn't a bracket, whitespace or an equals sign
14+
name = { (!("=" | "(" | ")") ~ ANY)* }
15+
16+
// Value captures everything that isn't a quote
17+
value = { (!("\"") ~ ANY)* }
18+
19+
// A body is made up of one or more comments, tags or text
20+
body = ${ (comment | tag | text)+ }
21+
22+
// Text is made up of anything that isn't a bracket
23+
text = ${ (!(")" | "(") ~ ANY)+ }
24+
25+
// Comments are ignored by the parser and don't make it to Rust
26+
comment = _{ "!(" ~ (!(")") ~ ANY)* ~ ")" }
27+
28+
// Whitespace is made up of spaces, newlines and tabs, these are ignored
29+
WHITESPACE = _{ " " | "\n" | "\t" }

0 commit comments

Comments
 (0)