Skip to content

Instantly share code, notes, and snippets.

@ericbmerritt
Created November 27, 2011 02:05
Show Gist options
  • Save ericbmerritt/1396803 to your computer and use it in GitHub Desktop.
Save ericbmerritt/1396803 to your computer and use it in GitHub Desktop.
-module(jxat_lexer_proper).
-include_lib("proper/include/proper.hrl").
to_string({ident, _, Ident}) ->
Ident;
to_string({char, _, Char}) ->
[$\\, Char];
to_string({syntax_quote, 0, "`"}) ->
"`";
to_string({unquote_splicing, 0, "~@"}) ->
"~@";
to_string({unquote, 0, "~"}) ->
"~";
to_string({quote, 0, "'"}) ->
"'";
to_string({integer, 0, I}) ->
erlang:integer_to_list(I);
to_string({float, 0, F}) ->
erlang:float_to_list(F);
to_string({string, 0, S}) ->
"\"" ++ S ++ "\"";
to_string({vector, 0, Items}) ->
lists:flatten(["[", lists:map(fun(Item) ->
[" ", to_string(Item), " "]
end, Items), "]"]);
to_string({list, 0, Items}) ->
lists:flatten(["(", lists:map(fun(Item) ->
[" ", to_string(Item), " "]
end, Items), ")"]).
%%------------------------------------------------------------------------------
%% Properties
%%------------------------------------------------------------------------------
prop_defun() ->
?FORALL({Expr}, {expression()},
begin
io:format("~s", [to_string(Expr)]),
true == true
end).
%%-----------------------------------------------------------------------------
%% Generators
%%-----------------------------------------------------------------------------
keyword_style_ident() ->
?LET(S, string(),
":" ++ S).
defvar_style_ident() ->
?LET(S, string(),
"*" ++ S ++ "*").
split_ident() ->
?LET({S1, S2}, {string(), string()},
S1 ++ "-" ++ S2).
normal_ident() ->
string().
ident() ->
{ident, 0, union([normal_ident(), split_ident(), defvar_style_ident(),
keyword_style_ident()])}.
character() ->
{char, 0, char()}.
syntax_quote() ->
{syntax_quote, 0, "`"}.
unquote_splicing() ->
{unquote_splicing, 0, "~@"}.
unquote() ->
{unquote, 0, "~"}.
quote() ->
{quote, 0, "'"}.
jxa_int() ->
{integer, 0, integer()}.
jxa_float() ->
{float, 0, float()}.
jxa_string() ->
{string, 0, string()}.
jxa_vector(0) ->
{vector, 0, []};
jxa_vector(Size) ->
{vector, 0, resize(Size, list(value(Size - 1)))}.
jxa_list(0) ->
{vector, 0, []};
jxa_list(Size) ->
{list, 0, resize(Size, list(value(Size div 4)))}.
value(Size) ->
union([jxa_vector(Size),
jxa_list(Size),
jxa_float(),
jxa_int(),
jxa_string(),
quote(),
unquote(),
unquote_splicing(),
syntax_quote(),
character(),
ident()]).
expression() ->
?SIZED(N, jxa_list(N)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment