1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-09-28 07:27:35 +00:00

feat: init trolley :trollface:

This commit is contained in:
Natapat Samutpong 2022-01-26 20:49:01 +07:00
parent 25128092e1
commit b78cb3b9a4
8 changed files with 165 additions and 18 deletions

View file

@ -2,24 +2,6 @@
another lisp dialect
> Also available on https://git.ablecorp.us/azur/bobbylisp
```lisp
; example/s.blsp
(fun factorial (x)
(if (<= x 1)
1
(* x (factorial (- x 1)))))
(do
(print (factorial 7)))
```
Compliation flow:
```
Input(file) -> Parser -> Compile(Bytecode) -> Interpret
String SExprs Bytecode IO
|-> Compile
Assembly(?)
```
## Installation
```bash
$ make

92
install.sh Executable file
View file

@ -0,0 +1,92 @@
#!/bin/bash
tput sc
function clear_print() {
tput rc
}
function print_menu() {
local function_arguments=($@)
local selected_item="$1"
local menu_items=(${function_arguments[@]:1})
local menu_size="${#menu_items[@]}"
for (( i = 0; i < $menu_size; ++i ))
do
if [ "$i" = "$selected_item" ]
then
echo "* ${menu_items[i]}"
else
echo " ${menu_items[i]}"
fi
done
}
function run_menu() {
local function_arguments=($@)
local selected_item="$1"
local menu_items=(${function_arguments[@]:1})
local menu_size="${#menu_items[@]}"
local menu_limit=$((menu_size - 1))
clear_print
print_menu "$selected_item" "${menu_items[@]}"
while read -rsn1 input
do
case "$input"
in
$'\x1B')
read -rsn1 -t 0.1 input
if [ "$input" = "[" ]
then
read -rsn1 -t 0.1 input
case "$input"
in
A) # Arrow up
if [ "$selected_item" -ge 1 ]
then
selected_item=$((selected_item - 1))
clear_print
print_menu "$selected_item" "${menu_items[@]}"
fi
;;
B) # Arrow down
if [ "$selected_item" -lt "$menu_limit" ]
then
selected_item=$((selected_item + 1))
clear_print
print_menu "$selected_item" "${menu_items[@]}"
fi
;;
esac
fi
read -rsn5 -t 0.1 # stdin flush
;;
"") # Enter
return "$selected_item"
;;
esac
done
}
selected_item=0
menu_items=("Install" "Uninstall" "Exit")
run_menu "$selected_item" "${menu_items[@]}"
menu_result="$?"
case "$menu_result"
in
0)
echo "Install selected"
;;
1)
echo "Uninstall selected"
;;
2)
echo "Goodbye"
;;
esac

9
trolley/.editorconfig Normal file
View file

@ -0,0 +1,9 @@
root = true
[*.cr]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

5
trolley/.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
/docs/
/lib/
/bin/
/.shards/
*.dwarf

13
trolley/shard.yml Normal file
View file

@ -0,0 +1,13 @@
name: trolley
version: 0.1.0
authors:
- Natapat Samutpong <natapat.samutpong@gmail.com>
targets:
trolley:
main: src/trolley.cr
crystal: 1.3.2
license: MIT

View file

@ -0,0 +1,2 @@
require "spec"
require "../src/trolley"

View file

@ -0,0 +1,9 @@
require "./spec_helper"
describe Trolley do
# TODO: Write tests
it "works" do
false.should eq(true)
end
end

35
trolley/src/trolley.cr Normal file
View file

@ -0,0 +1,35 @@
require "option_parser"
module Trolley
VERSION = "0.1.0"
def self.display_help
puts "trolley " + VERSION
puts <<-HELP
USAGE:
trolley [COMMAND] [OPTION]
COMMANDS:
-h, --help Display this help message
-v, --version Display version
HELP
exit
end
def self.run
OptionParser.parse do |parser|
parser.on("-h", "--help") do
display_help
end
parser.on("-v", "--version") do
puts "trolley " + VERSION
exit
end
end
end
end
begin
Trolley.run
end