Skip to content
Browse files

Downgrade neotoma

  • Loading branch information...
1 parent 43b92ed commit a0e99699d285110fefeb4712ec687afd29402eb9 Tony Arcieri committed
View
1 ebin/.gitignore
@@ -0,0 +1 @@
+*
View
16 src/neotoma/extra/csv_gen.erl
@@ -1,24 +1,24 @@
-module(csv_gen).
--export([transform/3]).
+-export([transform/2]).
%% Add clauses to this function to transform syntax nodes
%% from the parser into semantic output.
-transform(rows, Node, _Idx) when length(Node) =:= 1 ->
+transform(rows, Node) when length(Node) =:= 1 ->
[];
-transform(rows, Node, _Idx) ->
+transform(rows, Node) ->
Head = proplists:get_value(head, Node),
Tail = [R || [_,R] <- proplists:get_value(tail, Node)],
[Head|Tail];
-transform(row, Node, _Idx) when length(Node) =:= 1 ->
+transform(row, Node) when length(Node) =:= 1 ->
[];
-transform(row, Node, _Idx) ->
+transform(row, Node) ->
Head = proplists:get_value(head, Node),
Tail = [F || [_,F] <- proplists:get_value(tail, Node)],
[Head|Tail];
-transform(field, Node, _Idx) ->
+transform(field, Node) ->
lists:flatten(Node);
-transform(quoted_field, Node, _Idx) ->
+transform(quoted_field, Node) ->
String = proplists:get_value(string, Node),
re:replace(String, "[\"]{2}", "\"",[global, {return, list}]);
-transform(Symbol, Node, _Idx) when is_atom(Symbol) ->
+transform(Symbol, Node) when is_atom(Symbol) ->
Node.
View
34 src/neotoma/extra/json_tree.erl
@@ -1,36 +1,36 @@
-module(json_tree).
--export([transform/3]).
+-export([transform/2]).
%% Add clauses to this function to transform syntax nodes
%% from the parser into semantic output.
-transform(json_value, Node, _Idx) ->
+transform(json_value, Node) ->
lists:nth(2, Node);
-transform(object, Node, _Idx) when length(Node) =:= 3 ->
+transform(object, Node) when length(Node) =:= 3 ->
{struct, []};
-transform(object, Node, _Idx) ->
+transform(object, Node) ->
Head = proplists:get_value(head, Node),
Rest = [lists:nth(4, I) || I <- proplists:get_value(tail, Node)],
{struct, [Head|Rest]};
-transform(array, Node, _Idx) when length(Node) =:= 3 ->
+transform(array, Node) when length(Node) =:= 3 ->
[];
-transform(array, Node, _Idx) ->
+transform(array, Node) ->
Head = proplists:get_value(head, Node),
Rest = [lists:nth(4, I) || I <- proplists:get_value(tail, Node)],
[Head|Rest];
-transform(number, [Int, [],[]], _Idx) ->
+transform(number, [Int, [],[]]) ->
list_to_integer(lists:flatten(Int));
-transform(number, [Int, Frac, []], _Idx) ->
+transform(number, [Int, Frac, []]) ->
list_to_float(lists:flatten([Int, Frac]));
-transform(number, [Int, [], Exp], Idx) ->
- transform(number, [Int, ".0", Exp], Idx);
-transform(number, Node, _Idx) ->
+transform(number, [Int, [], Exp]) ->
+ transform(number, [Int, ".0", Exp]);
+transform(number, Node) ->
list_to_float(lists:flatten(Node));
-transform(string, Node, _Idx) ->
+transform(string, Node) ->
lists:flatten(proplists:get_value(chars, Node));
-transform(pair, Node, _Idx) ->
+transform(pair, Node) ->
{proplists:get_value(key, Node), proplists:get_value(value, Node)};
-transform(true, _Node, _Idx) -> true;
-transform(false, _Node, _Idx) -> false;
-transform(null, _Node, _Idx) -> null;
-transform(Symbol, Node, _Idx) when is_atom(Symbol) ->
+transform(true, _Node) -> true;
+transform(false, _Node) -> false;
+transform(null, _Node) -> null;
+transform(Symbol, Node) when is_atom(Symbol) ->
Node.
View
4 src/neotoma/src/peg.erl
@@ -24,7 +24,7 @@
%% @doc Memoizing parsing function wrapper. This form does not transform the result of a successful parse.
%% @see p/5.
p(Inp, Index, Name, ParseFun) ->
- p(Inp, Index, Name, ParseFun, fun(N, _Idx) -> N end).
+ p(Inp, Index, Name, ParseFun, fun(N) -> N end).
%% @doc Memoizing and transforming parsing function wrapper.
%% @spec p(Input::string(), StartIndex::parse_index(), Name::atom(), ParseFun::parse_fun(), TransformFun::transform_fun()) -> parse_result()
@@ -44,7 +44,7 @@ p(Inp, StartIndex, Name, ParseFun, TransformFun) ->
Failure;
% If it passes, transform and memoize the result.
{Result, InpRem, NewIndex} ->
- Transformed = TransformFun(Result, StartIndex),
+ Transformed = TransformFun(Result),
memoize(StartIndex, dict:store(Name, {Transformed, InpRem, NewIndex}, Memo)),
{Transformed, InpRem, NewIndex}
end
View
6 src/neotoma/src/peg_gen.erl
@@ -69,14 +69,14 @@ create_transform(ModName,Dir) when is_atom(ModName) ->
true -> io:format("'~s' already exists, skipping generation.~n", [XfFile]);
false -> generate_transform_stub(XfFile, ModName)
end,
- ["transform(Symbol,Node,Index) -> ",atom_to_list(ModName),":transform(Symbol, Node, Index)."].
+ ["transform(Symbol,Node) -> ",atom_to_list(ModName),":transform(Symbol, Node)."].
generate_transform_stub(XfFile,ModName) ->
Data = ["-module(",atom_to_list(ModName),").\n",
- "-export([transform/3]).\n\n",
+ "-export([transform/2]).\n\n",
"%% Add clauses to this function to transform syntax nodes\n",
"%% from the parser into semantic output.\n",
- "transform(Symbol, Node, _Index) when is_atom(Symbol) ->\n Node."],
+ "transform(Symbol, Node) when is_atom(Symbol) ->\n Node."],
file:write_file(XfFile, Data).
%% @doc Bootstraps the neotoma metagrammar. Intended only for internal development!
View
2 src/neotoma/src/peg_meta.erl
@@ -86,4 +86,4 @@ rule(comment_to_eol) ->
rule(white) ->
peg:charclass("[ \t\n\r]").
-transform(Symbol,Node,Index) -> peg_meta_gen:transform(Symbol, Node, Index).
+transform(Symbol,Node) -> peg_meta_gen:transform(Symbol, Node).
View
78 src/neotoma/src/peg_meta_gen.erl
@@ -1,95 +1,95 @@
-module(peg_meta_gen).
--export([transform/3]).
+-export([transform/2]).
-author("Sean Cribbs <seancribbs@gmail.com>").
-transform(rules, Node, _Index) ->
+transform(rules, Node) ->
verify_rules(),
Rules = string:join(lists:nth(2, Node), ";\n\n"),
Rules ++ ".\n";
-transform(declaration_sequence, Node, _Index) ->
+transform(declaration_sequence, Node) ->
FirstRule = proplists:get_value(head, Node),
OtherRules = [lists:last(I) || I <- proplists:get_value(tail, Node, [])],
[FirstRule|OtherRules];
-transform(declaration, [{nonterminal,Symbol}|Node], Index) ->
- add_lhs(Symbol, Index),
+transform(declaration, [{nonterminal,Symbol}|Node]) ->
+ add_lhs(Symbol),
"rule("++Symbol++") ->\n " ++ lists:nth(4, Node);
-transform(sequence, Node, _Index) ->
+transform(sequence, Node) ->
Tail = [lists:nth(2, S) || S <- proplists:get_value(tail, Node)],
Statements = [proplists:get_value(head, Node)|Tail],
"peg:seq(["++ string:join(Statements, ", ") ++ "])";
-transform(choice, Node, _Index) ->
+transform(choice, Node) ->
Tail = [lists:last(S) || S <- proplists:get_value(tail, Node)],
Statements = [proplists:get_value(head, Node)|Tail],
"peg:choose([" ++ string:join(Statements, ", ") ++ "])";
-transform(label, Node, _Index) ->
+transform(label, Node) ->
String = lists:flatten(Node),
lists:sublist(String, length(String)-1);
-transform(labeled_sequence_primary, Node, _Index) ->
+transform(labeled_sequence_primary, Node) ->
case hd(Node) of
[] -> lists:nth(2, Node);
Label -> "peg:label('" ++ Label ++ "', "++lists:nth(2, Node)++")"
end;
-transform(single_quoted_string, Node, Index) ->
- transform(double_quoted_string, Node, Index);
-transform(double_quoted_string, Node, _Index) ->
+transform(single_quoted_string, Node) ->
+ transform(double_quoted_string, Node);
+transform(double_quoted_string, Node) ->
"peg:string(\""++escape_quotes(lists:flatten(proplists:get_value(string, Node)))++"\")";
-transform(character_class, Node, _Index) ->
+transform(character_class, Node) ->
"peg:charclass(\"[" ++ escape_quotes(lists:flatten(proplists:get_value(characters, Node))) ++ "]\")";
-transform(parenthesized_expression, Node, _Index) ->
+transform(parenthesized_expression, Node) ->
lists:nth(3, Node);
-transform(atomic, {nonterminal, Symbol}, Index) ->
- add_nt(Symbol, Index),
+transform(atomic, {nonterminal, Symbol}) ->
+ add_nt(Symbol),
"fun " ++ Symbol ++ "/2";
-transform(primary, [Atomic, one_or_more], _Index) ->
+transform(primary, [Atomic, one_or_more]) ->
"peg:one_or_more("++Atomic++")";
-transform(primary, [Atomic, zero_or_more], _Index) ->
+transform(primary, [Atomic, zero_or_more]) ->
"peg:zero_or_more("++Atomic++")";
-transform(primary, [Atomic, optional], _Index) ->
+transform(primary, [Atomic, optional]) ->
"peg:optional("++Atomic++")";
-transform(primary, [assert, Atomic], _Index)->
+transform(primary, [assert, Atomic])->
"peg:assert("++Atomic++")";
-transform(primary, [not_, Atomic], _Index) ->
+transform(primary, [not_, Atomic]) ->
"peg:not_("++Atomic++")";
-transform(nonterminal, Node, _Index) ->
+transform(nonterminal, Node) ->
{nonterminal, lists:flatten(Node)};
-transform(anything_symbol, _Node, _Index) ->
+transform(anything_symbol, _Node) ->
"peg:anything()";
-transform(suffix, Node, _Index) ->
+transform(suffix, Node) ->
case Node of
"*" -> zero_or_more;
"+" -> one_or_more;
"?" -> optional
end;
-transform(prefix, Node, _Index) ->
+transform(prefix, Node) ->
case Node of
"&" -> assert;
"!" -> not_
end;
-transform(Rule, Node, _Index) when is_atom(Rule) ->
+transform(Rule, Node) when is_atom(Rule) ->
Node.
escape_quotes(String) ->
{ok, RE} = re:compile("\""),
re:replace(String, RE, "\\\\\"", [global, {return, list}]).
-add_lhs(Symbol, Index) ->
+add_lhs(Symbol) ->
case get(lhs) of
undefined ->
- put(lhs, [{Symbol,Index}]);
+ put(lhs, [Symbol]);
L when is_list(L) ->
- put(lhs, [{Symbol,Index}|L])
+ put(lhs, [Symbol|L])
end.
-add_nt(Symbol, Index) ->
+add_nt(Symbol) ->
case get(nts) of
undefined ->
- put(nts, [{Symbol,Index}]);
+ put(nts, [Symbol]);
L when is_list(L) ->
- case proplists:is_defined(Symbol, L) of
+ case lists:member(Symbol, L) of
true ->
ok;
_ ->
- put(nts, [{Symbol,Index}|L])
+ put(nts, [Symbol|L])
end
end.
@@ -97,20 +97,20 @@ verify_rules() ->
LHS = erase(lhs),
NTs = erase(nts),
NonRoots = tl(lists:reverse(LHS)),
- lists:foreach(fun({Sym,Idx}) ->
- case proplists:is_defined(Sym, NTs) of
+ lists:foreach(fun(L) ->
+ case lists:member(L, NTs) of
true ->
ok;
_ ->
- io:format("neotoma warning: rule '~s' is unused. ~p~n", [Sym,Idx])
+ io:format("neotoma warning: rule '~s' is unused.~n", [L])
end
end, NonRoots),
- lists:foreach(fun({S,I}) ->
- case proplists:is_defined(S, LHS) of
+ lists:foreach(fun(S) ->
+ case lists:member(S, LHS) of
true ->
ok;
_ ->
- io:format("neotoma error: symbol '~s' has no reduction. (found at ~p) No parser will be generated!~n", [S,I]),
+ io:format("neotoma error: symbol '~s' has no reduction. No parser will be generated!~n", [S]),
exit({neotoma, {no_reduction, list_to_atom(S)}})
end
end, NTs).
View
4 src/neotoma/src/peg_transform.erl
@@ -105,8 +105,8 @@ semantic_fun(Rule, Line) ->
{'fun',Line,
{clauses,
[{clause,Line,
- [{var,Line,'Node'},{var,Line,'Idx'}],
+ [{var,Line,'Node'}],
[],
[{call,Line,
{atom,Line,transform},
- [{atom,Line,Rule},{var,Line,'Node'},{var,Line,'Idx'}]}]}]}}.
+ [{atom,Line,Rule},{var,Line,'Node'}]}]}]}}.
View
22 src/neotoma/tests/examples/arithmetic.erl
@@ -22,7 +22,7 @@ additive(Input, Index) ->
peg:string("+"),
fun additive/2]),
fun multitive/2]))(I,D) end,
- fun(Node, Idx) -> transform(additive, Node, Idx) end).
+ fun(Node) -> transform(additive, Node) end).
multitive(Input, Index) ->
peg:p(Input, Index, multitive, fun(I,D) ->
@@ -31,7 +31,7 @@ multitive(Input, Index) ->
fun multitive/2]),
fun primary/2]))(I,D)
end,
- fun(Node, Idx) -> transform(multitive, Node, Idx) end).
+ fun(Node) -> transform(multitive, Node) end).
primary(Input, Index) ->
peg:p(Input, Index, primary, fun(I,D) ->
@@ -40,26 +40,26 @@ primary(Input, Index) ->
peg:string(")")]),
fun decimal/2]))(I,D)
end,
- fun(Node, Idx) -> transform(primary, Node, Idx) end).
+ fun(Node) -> transform(primary, Node) end).
decimal(Input, Index) ->
peg:p(Input, Index, decimal, fun(I,D) ->
(peg:charclass("[0-9]"))(I,D)
end,
- fun(Node, Idx) -> transform(decimal, Node, Idx) end).
+ fun(Node) -> transform(decimal, Node) end).
%% Transform the nodes into the result of the expression
-transform(decimal, Node, _Idx) ->
+transform(decimal, Node) ->
list_to_integer([Node]);
-transform(primary, Node, _Idx) when is_integer(Node) ->
+transform(primary, Node) when is_integer(Node) ->
Node;
-transform(primary, Node, _Idx) when is_list(Node) ->
+transform(primary, Node) when is_list(Node) ->
lists:nth(2, Node);
-transform(multitive, Node, _Idx) when is_integer(Node) ->
+transform(multitive, Node) when is_integer(Node) ->
Node;
-transform(multitive, Node, _Idx) when is_list(Node) ->
+transform(multitive, Node) when is_list(Node) ->
hd(Node) * lists:nth(3, Node);
-transform(additive, Node, _Idx) when is_integer(Node) ->
+transform(additive, Node) when is_integer(Node) ->
Node;
-transform(additive, Node, _Idx) when is_list(Node) ->
+transform(additive, Node) when is_list(Node) ->
hd(Node) + lists:nth(3, Node).
View
14 src/neotoma/tests/examples/arithmetic_xf.erl
@@ -23,17 +23,17 @@ rule(primary) ->
rule(decimal) ->
peg:charclass("[0-9]").
-transform(decimal, Node, _Idx) ->
+transform(decimal, Node) ->
list_to_integer([Node]);
-transform(primary, Node, _Idx) when is_integer(Node) ->
+transform(primary, Node) when is_integer(Node) ->
Node;
-transform(primary, Node, _Idx) when is_list(Node) ->
+transform(primary, Node) when is_list(Node) ->
lists:nth(2, Node);
-transform(multitive, Node, _Idx) when is_integer(Node) ->
+transform(multitive, Node) when is_integer(Node) ->
Node;
-transform(multitive, Node, _Idx) when is_list(Node) ->
+transform(multitive, Node) when is_list(Node) ->
hd(Node) * lists:nth(3, Node);
-transform(additive, Node, _Idx) when is_integer(Node) ->
+transform(additive, Node) when is_integer(Node) ->
Node;
-transform(additive, Node, _Idx) when is_list(Node) ->
+transform(additive, Node) when is_list(Node) ->
hd(Node) + lists:nth(3, Node).

0 comments on commit a0e9969

Please sign in to comment.
Something went wrong with that request. Please try again.