mirror of https://github.com/japl-lang/japl.git
Merge pull request #42 from Productive2/master
Use Jale, bonus editor support
This commit is contained in:
commit
47beac3b85
|
@ -95,6 +95,14 @@ git clone https://github.com/japl-lang/japl
|
|||
|
||||
### Running the build script
|
||||
|
||||
NOTE: as of now, you will need version 0.1.0 of the nimble package `jale` installed:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/japl-lang/jale --branch 0.1.0
|
||||
cd jale
|
||||
nimble install
|
||||
```
|
||||
|
||||
As a next step, you need to run JABT (YES, Just Another Build Tool). This will generate the required configuration files, compile the JAPL runtime and run tests (unless `--skip-tests` is used). There are some settings that can be tweaked with command-line options (or environment variables), for more information, run `python3 build.py --help`.
|
||||
|
||||
To compile the JAPL runtime, you'll first need to move into the project's directory you cloned before, so run `cd japl`, then `python3 build.py ./src` and wait for it to complete. You should now find an executable named `japl` (or `japl.exe` on windows) inside the `src` folder.
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
hook global BufCreate .*[.]jpl %{
|
||||
set-option buffer filetype japl
|
||||
}
|
||||
|
||||
addhl shared/japl regions
|
||||
addhl shared/japl/code default-region group
|
||||
addhl shared/japl/comment-line region '//' '$' fill comment
|
||||
addhl shared/japl/comment-multiline region '/\*' '\*/' fill comment
|
||||
addhl shared/japl/string region '"' '"' fill string
|
||||
|
||||
addhl shared/japl/code/ regex '\b(?:true|false|nil)\b' 0:keyword
|
||||
addhl shared/japl/code/ regex '\b(?:if|else|while|for)\b' 0:keyword
|
||||
addhl shared/japl/code/ regex '\b(?:fun|lambda|return)\b' 0:keyword
|
||||
addhl shared/japl/code/ regex '\b(?:var)\b' 0:keyword
|
||||
addhl shared/japl/code/ regex '\b(?:class)\b' 0:keyword
|
||||
|
||||
addhl shared/japl/code/num regex '\b[0-9]+(.[0-9]+)?' 0:value
|
||||
|
||||
hook -group japl-highlight global WinSetOption filetype=japl %{ add-highlighter window/ ref japl }
|
||||
hook -group japl-highlight global WinSetOption filetype=(?!japl).* %{ remove-highlighter window/japl }
|
|
@ -0,0 +1 @@
|
|||
autocmd BufNewFile,BufRead *.jpl setfiletype japl
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
augroup japl
|
||||
setlocal commentstring=//\ %s
|
||||
setlocal tabstop=4
|
||||
setlocal softtabstop=4
|
||||
setlocal shiftwidth=4
|
||||
augroup END
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
setlocal indentexpr=JaplIndent()
|
||||
|
||||
function! JaplIndent()
|
||||
let line = getline(v:lnum)
|
||||
let previousNum = prevnonblank(v:lnum-1)
|
||||
let previous = getline(previousNum)
|
||||
|
||||
if previous =~ "{" && previous !~ "}" && line !~ "}"
|
||||
return indent(previousNum) + &tabstop
|
||||
endif
|
||||
|
||||
|
||||
if line =~ "}"
|
||||
return indent(previousNum) - &tabstop
|
||||
endif
|
||||
|
||||
return indent(previousNum)
|
||||
|
||||
|
||||
endfunction
|
|
@ -0,0 +1,34 @@
|
|||
syntax keyword japlTodos TODO XXX FIXME NOTE TEST
|
||||
|
||||
syntax keyword japlKeywords
|
||||
\ if
|
||||
\ var
|
||||
\ fun
|
||||
|
||||
syntax keyword japlBooleans
|
||||
\ true
|
||||
\ false
|
||||
|
||||
syntax match japlNumber "\v<\d+>"
|
||||
syntax match japlNumber "\v<\d+.\d+>"
|
||||
syntax match japlComment "//.*$"
|
||||
syntax match japlBlock "{"
|
||||
syntax match japlBlock "}"
|
||||
|
||||
syntax region japlString start=/"/ end=/"/
|
||||
|
||||
highlight default link japlTodos Todo
|
||||
highlight default link japlComment Comment
|
||||
highlight default link japlString String
|
||||
highlight default link japlNumber Number
|
||||
highlight default link japlBoolean Keyword
|
||||
highlight default link japlKeywords Keyword
|
||||
highlight default link japlBlock Keyword
|
||||
|
||||
" the following exist too:
|
||||
" Operator
|
||||
" PreProc (c macros e.g.)
|
||||
" Delimeter
|
||||
" Structure
|
||||
" Type (user defined types)
|
||||
" Include
|
31
src/japl.nim
31
src/japl.nim
|
@ -25,6 +25,18 @@ import types/japlNil
|
|||
import types/typeutils
|
||||
import types/methods
|
||||
|
||||
import jale/editor
|
||||
import jale/templates
|
||||
import jale/plugin/defaults
|
||||
import jale/plugin/history
|
||||
import jale/plugin/editor_history
|
||||
|
||||
proc getLineEditor: LineEditor =
|
||||
result = newLineEditor()
|
||||
result.prompt = "=> "
|
||||
result.populateDefaults() # setup default keybindings
|
||||
let hist = result.plugHistory() # create history object
|
||||
result.bindHistory(hist) # set default history keybindings
|
||||
|
||||
proc repl(bytecodeVM: VM) =
|
||||
var bytecodeVM = bytecodeVM
|
||||
|
@ -34,18 +46,12 @@ proc repl(bytecodeVM: VM) =
|
|||
let nimDetails = &"[Nim {NimVersion} on {hostOs} ({hostCPU})]"
|
||||
echo nimDetails
|
||||
var source = ""
|
||||
while true:
|
||||
try:
|
||||
stdout.write("=> ")
|
||||
source = stdin.readLine()
|
||||
except IOError:
|
||||
echo ""
|
||||
bytecodeVM.freeVM()
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
echo ""
|
||||
bytecodeVM.freeVM()
|
||||
break
|
||||
let lineEditor = getLineEditor()
|
||||
var keep = true
|
||||
lineEditor.bindEvent(jeQuit):
|
||||
keep = false
|
||||
while keep:
|
||||
source = lineEditor.read()
|
||||
if source == "//clear" or source == "// clear":
|
||||
echo "\x1Bc" & JAPL_VERSION_STRING
|
||||
echo nimDetails
|
||||
|
@ -60,6 +66,7 @@ proc repl(bytecodeVM: VM) =
|
|||
if not bytecodeVM.lastPop.isNil():
|
||||
echo stringify(bytecodeVM.lastPop)
|
||||
bytecodeVM.lastPop = cast[ptr Nil](bytecodeVM.cached[2])
|
||||
bytecodeVM.freeVM()
|
||||
|
||||
|
||||
proc main(file: var string = "", fromString: bool = false, interactive: bool = false) =
|
||||
|
|
Loading…
Reference in New Issue