All Projects → andytill → ohmyguard

andytill / ohmyguard

Licence: BSD-2-Clause license
Binary patten matching style syntax for erlang function guards

Programming Languages

erlang
1774 projects
Makefile
30231 projects

Projects that are alternatives of or similar to ohmyguard

csscomplete.vim
Update the bult-in CSS complete function to latest CSS standard.
Stars: ✭ 61 (+258.82%)
Mutual labels:  syntax
nord-atom-syntax
An arctic, north-bluish clean and elegant Atom syntax theme.
Stars: ✭ 72 (+323.53%)
Mutual labels:  syntax
postcss-styl
PostCSS parser plugin for converting Stylus syntax to PostCSS AST.
Stars: ✭ 15 (-11.76%)
Mutual labels:  syntax
colocat
Fegeya Colocat, Colorized 'cat' implementation. Written in C++17.
Stars: ✭ 14 (-17.65%)
Mutual labels:  syntax
chestnut.vim
Minimal syntax highlighting for 16-color terminals.
Stars: ✭ 31 (+82.35%)
Mutual labels:  syntax
c-compiler-frontend
💻NUAA 2017 编译原理 - C(缩减)语言编译器前端 - Python
Stars: ✭ 44 (+158.82%)
Mutual labels:  syntax
nova-vue
Vue support for Nova editor.
Stars: ✭ 35 (+105.88%)
Mutual labels:  syntax
vscode-liquid
💧Liquid language support for VS Code
Stars: ✭ 137 (+705.88%)
Mutual labels:  syntax
calamity-atom
A purple dark theme with medium to high contrast for the Atom editor ⚛️
Stars: ✭ 12 (-29.41%)
Mutual labels:  syntax
elm-javascript-haskell-equivalents
Comparison of similar functions across Elm, Javascript, and Haskell
Stars: ✭ 31 (+82.35%)
Mutual labels:  syntax
nord-notepadplusplus
An arctic, north-bluish clean and elegant Notepad++ theme.
Stars: ✭ 112 (+558.82%)
Mutual labels:  syntax
syntax highlighter
Syntax Highlighter for Dart/Flutter Code
Stars: ✭ 28 (+64.71%)
Mutual labels:  syntax
language-rainmeter
Syntax highlighting for Rainmeter files in Atom.
Stars: ✭ 19 (+11.76%)
Mutual labels:  syntax
explain-rs
A library which finds language features in rust code and provides resources on them.
Stars: ✭ 38 (+123.53%)
Mutual labels:  syntax
langua
A suite of language tools
Stars: ✭ 29 (+70.59%)
Mutual labels:  syntax
laravel-or-abort
A trait to optionally abort a Laravel application
Stars: ✭ 54 (+217.65%)
Mutual labels:  syntax
language-rust
Parser and pretty-printer for the Rust language
Stars: ✭ 78 (+358.82%)
Mutual labels:  syntax
nerus
Large silver standart Russian corpus with NER, morphology and syntax markup
Stars: ✭ 47 (+176.47%)
Mutual labels:  syntax
es6-template-regex
Regular expression for matching es6 template delimiters in a string.
Stars: ✭ 15 (-11.76%)
Mutual labels:  syntax
elixir-sublime-syntax
The most powerful Elixir for the most Sublime experience.
Stars: ✭ 28 (+64.71%)
Mutual labels:  syntax

ohmyguard

Parse transform for converting my_func(X) when is_binary(X) -> X to my_func(X/binary) -> X..

Why?

Erlang binary pattern matching is one of its best features and its most succinct syntax, so why not apply it to function guards as well? Given this function:

my_func(Value) when is_binary(Value) ->
    Value.

It can be reduced to this:

my_func(Value/binary) ->
    Value.

ohmyguard supports all erlang types:

omg_atom(X/atom) -> X.
omg_binary(X/binary) -> X.
omg_bitstring(X/bitstring) -> X.
omg_float(X/float) -> X.
omg_function(X/function) -> X.
omg_integer(X/integer) -> X.
omg_list(X/list) -> X.
omg_map(X/map) -> X.
omg_number(X/number) -> X.
omg_pid(X/pid) -> X.
omg_port(X/port) -> X.
omg_reference(X/reference) -> X.
omg_ref(X/ref) -> X.
omg_tuple(X/tuple) -> X.

The syntax proves even more concise when a function has multiple arguments that need to be checked:

omg_pid_atom(X/pid, Y/atom) -> {X, Y}.

The andalso and orelse keywords and confusing commas and semi colons are gone and the function is more readable. All type guards must be met or a function_clause error is thrown.

Records are also supported, although the syntax is still being worked on:

-record(myrec, {field = value}).

omg_record(Rec/#myrec{}) -> Rec.

It would be better if record guards looked like f(Rec/#myrec) -> Rec. but this throws a parse error before it can be given to the ohmyguard parse transform. Suggestions welcome!

ohmyguard will not completely replace traditional guards, it is just for type checking.

Syntax that still needs to be implemented...

Case statements
case V of
	{ok, A/binary} -> A
end
Assignments
{ok, V/binary} = application:get_env(my_prop)
And much more...

It would be nice if ohmyguard had integration with the recless parse transform, to allow syntax like:

address_street(Address/#address) -> 
	Address.street.

Also funs, list comprehensions, the mind boggles.

Should I use it?

No way! It is just a proof of concept at the moment.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].