Skip to content

Commit

Permalink
updated README and vim syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
WeirdConstructor committed Sep 12, 2019
1 parent 2e4e204 commit 4777ff8
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 61 deletions.
44 changes: 21 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ Here are some of it's properties:
- No exceptions, except panics. Error handling is accomplished
by a specialized data type. It can be thought of as dynamic counterpart
of Rust's Result type.
- Closures can capture up values either by value, by reference
or by weak reference. Giving you the ability to keep cyclic
references in check.
- Easy maintenance of the implementation.
- Custom user data implementation using [VValUserData](https://docs.rs/wlambda/newest/wlambda/vval/trait.VValUserData.html).

Expand Down Expand Up @@ -59,7 +56,7 @@ can be found in the [WLambda Language Reference](https://docs.rs/wlambda/newest/
_ + _1 # Arguments are not named, they are put into _, _1, _2
};
a_func(2, 3); # Function call
a_func[2, 3]; # Function call
a_func 2 3; # Equivalent function call
# Shortened one statement function definition:
Expand All @@ -68,32 +65,33 @@ a_func 2 3; # Equivalent function call
# There is no `if` statement. Booleans can be called
# with two arguments. The first one is called when the boolean
# is true, the second one is called when the boolean is false.
[a == 10] {
(a == 10) {
# called if a == 10
} {
# called if a != 10
};
# Counting loop:
!:ref sum = 0; # Defining a reference that can be assignment
# from inside a function.
!sum = $&0; # Defining a reference that can be assignment
# from inside a function.
# `range` calls the given function for each iteration
# and passes the counter as first argument in `_`
range 0 10 1 { # This is a regular function.
.sum = sum + _;
.*sum = $*sum + _; # $* is a dereferencing operator
# and .* starts a reference assignment
};
# `range` loop with `break`
!break_value = range 0 10 1 {
[_ == 5] { break 22 };
(_ == 5) { break 22 };
};
# Returning early from functions:
!some_fun = \:some_fun_lbl { # \:xxx defines a function label for returning
!x = 10;
.x = do_something_to x;
[x > 20] {
(x > 20) {
return :some_fun_lbl 20; # explicit argument for return returns from
# the specified block.
}
Expand All @@ -105,7 +103,7 @@ range 0 10 1 { # This is a regular function.
# you may specify a small unused label like `_` to jump out some unnamed func:
!some_fun = {
!(x) = @;
[x == 20] \:_{ return 30 } # returns from some_fun, not from the if-branch
(x == 20) \:_{ return 30 } # returns from some_fun, not from the if-branch
};
# Error reporting:
Expand All @@ -114,7 +112,7 @@ range 0 10 1 { # This is a regular function.
!some_erroring_func = {
return $error "An error happened!"
};
!value = some_erroring_func();
!value = some_erroring_func[];
# on_error calls the first argument if the second argument
# is an error value.
on_error {
Expand All @@ -126,18 +124,18 @@ range 0 10 1 { # This is a regular function.
!handle_err = { displayln _ };
# with the ~ operator, you can chain it nicely:
on_error {|| handle_err(_) } ~ some_erroring_func();
on_error {|| handle_err[_] } ~ some_erroring_func[];
# or without ~:
on_error {|| handle_err(_) } [some_erroring_func()];
on_error {|| handle_err[_] } (some_erroring_func[]);
# or with |
some_erroring_func() | on_error {|| handle_err(_) };
some_erroring_func[] | on_error {|| handle_err[_] };
# _? transforms an error value, and returns it from the current
# function. optionally jumping outwards.
wl:assert_eq [str {
wl:assert_eq (str {
_? ~ $e "ok"; # is with an error value the same as: `return $e "ok"`
}()] "$e \"ok\"";
}[]) "$e \"ok\"";
_? 10; # passes the value through
Expand All @@ -148,7 +146,7 @@ range 0 10 1 { # This is a regular function.
report_my_error _;
} block :outer {
# do something...
[_ != 10] {
(_ != 10) {
return :outer $error "Something really failed"
# same as, with the difference, that _? only returns
# from :outer if it is an error value.
Expand All @@ -160,14 +158,14 @@ range 0 10 1 { # This is a regular function.
};
# Basic OOP:
# :wref to make any closure capture of some_obj a weak reference, so
# wl:weaken to make any closure capture of some_obj a weak reference, so
# we don't get any cyclic references:
!:wref some_obj = ${};
!some_obj = $&${};
some_obj.do_something = {
# do something here with some_obj captured (weakly)
# from the upper lexical scope.
};
some_obj.do_something(); # Method call
some_obj.do_something[]; # Method call
```

Currently there are many more examples in the test cases in `compiler.rs`.
Expand Down Expand Up @@ -260,8 +258,8 @@ Future plans could be:
!v = tag 10 tag;
!fun = { println("not tagged!") };
.fun = add_tag fun tag { println("tagged with 123"); }
fun(v); # prints "tagged with 123"
fun(10); # prints "not tagged!"
fun[v]; # prints "tagged with 123"
fun[10]; # prints "not tagged!"
# TagFun(Rc<RefCell<std::collections::HashMap<String, Rc<VValFun>>>>),
```
Expand Down
101 changes: 63 additions & 38 deletions vim/wlambda.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,103 @@
" Author: Weird Constructor <[email protected]>
" Maintainer: Weird Constructor <[email protected]>

if exists("b:current_syntax")
finish
endif

"if exists("b:current_syntax")
" finish
"endif
"

syn match wlIdentifier /[a-zA-Z_@]\+[^[:space:]\.,;{}\[\]()~|=]*/
syn match wlAssignId /[a-zA-Z_@]\+[^[:space:]\.,;{}\[\]()~|=]*/ contained
syn match wlMapKeyId /[a-zA-Z_@]\+[^[:space:]\.,;{}\[\]()~|=]*\s*\ze=/ contained

syn match wlComment /#.*$/
syn match wlIdentifier /[a-zA-Z_@]\+[^[:space:]\.,;{}\[\]()~|=]*/
syn match wlAssignId /[a-zA-Z_@]\+[^[:space:]\.,;{}\[\]()~|=]*/ contained
syn match wlMapKeyId /[a-zA-Z_@]\+[^[:space:]\.,;{}\[\]()~|=]*\s*\ze=/ contained

syn match wlKeyword "_?"
syn match wlKeyword "re:map"
syn match wlKeyword "re:replace_all"
syn keyword wlKeyword panic push take drop not neg uneg block unwrap unwrap_err
syn keyword wlRepeat while repeat
syn match wlValue '$t'
syn match wlValue '$true'
syn match wlValue '$false'
syn match wlValue '$f'
syn match wlValue '$n'
syn match wlValue '$nul'
syn match wlValue '$e'
syn match wlValue '$error'
syn match wlKeyword "chrono:timestamp"
syn match wlKeyword "ser:json"
syn match wlKeyword "deser:json"
syn match wlKeyword "ser:msgpack"
syn match wlKeyword "deser:msgpack"
syn match wlKeyword "wl:assert"
syn match wlKeyword "wl:assert_eq"
syn match wlKeyword "wl:dump_func"
syn match wlKeyword "wl:set_ref"
syn match wlKeyword "wl:weaken"
syn match wlKeyword "str:len"
syn match wlKeyword "str:to_lowercase"
syn match wlKeyword "str:to_uppercase"
syn match wlKeyword "str:padl"
syn match wlKeyword "str:padr"
syn match wlKeyword "str:cat"
syn match wlKeyword "str:join"
syn match wlKeyword "str:from_utf8_lossy"
syn match wlKeyword "str:from_utf8"
syn match wlKeyword "str:to_bytes"
syn match wlKeyword "bytes:to_vec"
syn match wlKeyword "bytes:from_vec"
syn match wlKeyword "bytes:from_hex"
syn match wlKeyword "bytes:to_hex"
syn keyword wlRepeat while range return break next match
syn keyword wlKeyword panic push take drop not neg uneg block unwrap unwrap_err
syn keyword wlKeyword str sym is_none is_err is_map is_vec is_fun is_str is_sym
syn keyword wlKeyword is_ref is_wref is_bool is_bytes is_float is_int len type to_drop
syn keyword wlKeyword fold displayln pop bool float int on_error
syn match wlValue '\$t'
syn match wlValue '\$true'
syn match wlValue '\$false'
syn match wlValue '\$f'
syn match wlValue '\$n'
syn match wlValue '\$nul'
syn match wlValue '\$e'
syn match wlRefData '$&'
syn match wlRefData '$&&'
syn match wlRefData '$\*'
syn match wlValue '\$error'
syn match wlValue '[-+]\?\d\+'
syn match wlValue '[-+]\?\d\+\.\d\+'
syn match wlValue '[-+]\?0x[a-fA-F0-9]\+\(\.[a-fA-F0-9]\+\)\?'
syn match wlValue '[-+]\?0b[01]\+\(\.[01]\+\)\?'
syn match wlValue '[-+]\?0o[0-8]\+\(\.[0-8]\+\)\?'
syn match wlValue '[-+]\?[0-9]\+r[0-9a-zA-Z]\+\(\.[0-9a-zA-Z]\+\)\?'

syn match wlFuncCombinators '[|~]'
syn match wlFuncCombinators '|\?[|~]'

syn match wlStringSpec /\\x[a-f0-9A-F][a-f0-9A-F]/ contained
syn match wlStringSpec /\\["'\\nrt0]/ contained
syn match wlStringSpec /\\u[a-f0-9A-F]\+/ contained
"
syn region wlString start="\$q\z(.\)" end="\z1"
syn region wlString start="\$q\[" end="\]"
syn region wlString start="\$q(" end=")"
syn region wlString start="\$q{" end="}"

syn region wlString start="$q\z(.\)" end="\z1"
syn region wlString start="$q\[" end="\]"
syn region wlString start="$q(" end=")"
syn region wlString start="$q{" end="}"

syn region wlQSymbol start=+:"+ skip=+\\\\\|\\"+ end=+"+ contains=wlStringSpec
syn region wlString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=wlStringSpec
syn region wlString start=+$b"+ skip=+\\\\\|\\"+ end=+"+ contains=wlStringSpec
syn region wlQSymbol start=+:"+ skip=+\\\\\|\\"+ end=+"+ contains=wlStringSpec
syn region wlString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=wlStringSpec
syn region wlString start=+\$b"+ skip=+\\\\\|\\"+ end=+"+ contains=wlStringSpec

syn match wlSymbol ':[^[:space:]\.,;{}\[\]()~|="]\+'

syn match wlAssign '\.' nextgroup=wlAssignId,wlDestr
syn match wlDefine '!' nextgroup=wlDefTag,wlDestr
syn match wlDefTag ':ref' contained
syn match wlDefTag ':wref' contained
syn match wlAssign '\(^\|\s\+\|{\|;\)\@<=\.' nextgroup=wlAssignId,wlDestr
syn match wlDefine '!' nextgroup=wlDefTag,wlAssignId,wlDestr
syn match wlDefTag ':global' contained
syn region wlDestr matchgroup=wlDestrDelim start="(" end=")" transparent contained contains=wlIdentifier,wlComment

syn match wlArity '|\s*\d\+\s*<\s*\d\+\s*|'
syn match wlArity '|\s*\d\+\s*|'
syn match wlArity '|\s*|'

syn region wlMap matchgroup=wlStruct start="${" end="}" transparent contains=wlComment,wlValue,wlIdentifier,wlKeyword,wlKeyword2,wlRepeat,wlSymbol,wlQSymbol,wlString,wlFunc,wlFuncCombinators,wlList,wlMap,wlQuote,wlShortFunc,wlMapKeyId
syn region wlList matchgroup=wlStruct start="$\[" end="\]" transparent contains=wlComment,wlValue,wlIdentifier,wlKeyword,wlKeyword2,wlRepeat,wlSymbol,wlQSymbol,wlString,wlFunc,wlFuncCombinators,wlList,wlMap,wlQuote,wlShortFunc
syn region wlQuote matchgroup=wlExprQuote start="\[" end="\]" transparent contains=wlComment,wlValue,wlIdentifier,wlKeyword,wlKeyword2,wlRepeat,wlSymbol,wlQSymbol,wlString,wlFunc,wlFuncCombinators,wlList,wlMap,wlQuote,wlShortFunc
syn region wlFunc matchgroup=wlFuncDelims start="{" end="}" transparent contains=wlComment,wlValue,wlIdentifier,wlKeyword,wlKeyword2,wlRepeat,wlSymbol,wlQSymbol,wlString,wlFunc,wlFuncCombinators,wlList,wlMap,wlQuote,wlShortFunc,wlAssign,wlDefine,wlArity
syn match wlShortFunc '\\' nextgroup=wlComment,wlValue,wlIdentifier,wlKeyword,wlKeyword2,wlRepeat,wlSymbol,wlQSymbol,wlString,wlFunc,wlFuncCombinators,wlList,wlMap,wlQuote,wlShortFunc,wlAssign,wlDefine,wlArity

syn region wlMap matchgroup=wlRefData start="\${" end="}" transparent contains=wlComment,wlRefData,wlValue,wlIdentifier,wlKeyword,wlKeyword2,wlRepeat,wlSymbol,wlQSymbol,wlString,wlArgList,wlFunc,wlFuncCombinators,wlList,wlMap,wlQuote,wlShortFunc,wlMapKeyId
syn region wlList matchgroup=wlRefData start="\$\[" end="\]" transparent contains=wlComment,wlRefData,wlValue,wlIdentifier,wlKeyword,wlKeyword2,wlRepeat,wlSymbol,wlQSymbol,wlString,wlArgList,wlFunc,wlFuncCombinators,wlList,wlMap,wlQuote,wlShortFunc
syn region wlQuote matchgroup=wlExprQuote start="(" end=")" transparent contains=wlComment,wlRefData,wlValue,wlIdentifier,wlKeyword,wlKeyword2,wlRepeat,wlSymbol,wlQSymbol,wlString,wlArgList,wlFunc,wlFuncCombinators,wlList,wlMap,wlQuote,wlShortFunc
syn region wlArgList matchgroup=wlFuncDelims start="\[" end="\]" transparent contains=wlComment,wlRefData,wlValue,wlIdentifier,wlKeyword,wlKeyword2,wlRepeat,wlSymbol,wlQSymbol,wlString,wlArgList,wlFunc,wlFuncCombinators,wlList,wlMap,wlQuote,wlShortFunc
syn region wlFunc matchgroup=wlFuncDelims start="{" end="}" transparent contains=wlComment,wlRefData,wlValue,wlIdentifier,wlKeyword,wlKeyword2,wlRepeat,wlSymbol,wlQSymbol,wlString,wlArgList,wlFunc,wlFuncCombinators,wlList,wlMap,wlQuote,wlShortFunc,wlAssign,wlDefine,wlArity
syn match wlShortFunc '\\' nextgroup=wlComment,wlRefData,wlValue,wlIdentifier,wlKeyword,wlKeyword2,wlRepeat,wlSymbol,wlQSymbol,wlString,wlArgList,wlFunc,wlFuncCombinators,wlList,wlMap,wlQuote,wlShortFunc,wlAssign,wlDefine,wlArity

hi def link wlKeyword Function
hi def link wlKeyword2 Function

hi def link wlArgList Function
hi def link wlFuncDelims Function
hi def link wlShortFunc Function
hi def link wlFuncCombinators Function
Expand All @@ -95,7 +120,7 @@ hi def link wlSymbol Special
hi def link wlQSymbol Special
hi def link wlAssignId Special
hi def link wlMapKeyId Special
hi def link wlStruct Structure
hi def link wlRefData Structure
hi def link wlDefTag Type
hi def link wlArity Type
hi def link wlSymbolSpec Constant
Expand Down

0 comments on commit 4777ff8

Please sign in to comment.