Skip to content

Commit

Permalink
The big rename and cleanup.
Browse files Browse the repository at this point in the history
* peg_meta_gen no longer necessary
* peg_gen -> neotoma
* peg_meta -> neotoma_parse
* peg -> neotoma_peg
  • Loading branch information
seancribbs committed Nov 13, 2009
1 parent 8652541 commit cbf275a
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 190 deletions.
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -16,8 +16,8 @@ priv:
ebin_tests: ebin_tests:
mkdir ebin_tests mkdir ebin_tests


priv/peg_includes.erl: priv src/peg.erl priv/peg_includes.erl: priv src/neotoma_peg.erl
cat src/peg.erl | grep -v "^%" | grep -v "^-" > priv/peg_includes.erl cat src/neotoma_peg.erl | grep -v "^%" | grep -v "^-" > priv/peg_includes.erl


src_src: ebin src/neotoma.app priv/peg_includes.erl src_src: ebin src/neotoma.app priv/peg_includes.erl
cd src;erl -pz ../ebin -make cd src;erl -pz ../ebin -make
Expand All @@ -33,5 +33,5 @@ clean:
rm -rf ebin_tests rm -rf ebin_tests


bootstrap: src_src bootstrap: src_src
${ERL} -pz ebin -b start_sasl -noshell -s init stop -eval 'peg_gen:bootstrap().' ${ERL} -pz ebin -b start_sasl -noshell -s init stop -eval 'neotoma:bootstrap().'
cd src;erl -pz ../ebin -make cd src;erl -pz ../ebin -make
2 changes: 1 addition & 1 deletion src/Emakefile
@@ -1,2 +1,2 @@
{[peg, peg_gen, peg_meta, peg_meta_gen], {[neotoma_peg, neotoma, neotoma_parse],
[{outdir, "../ebin"}, {i, "../../"}, debug_info]}. [{outdir, "../ebin"}, {i, "../../"}, debug_info]}.
4 changes: 2 additions & 2 deletions src/neotoma.app
@@ -1,8 +1,8 @@
{application, neotoma, {application, neotoma,
[ [
{description, "PEG/Packrat toolkit and parser-generator."}, {description, "PEG/Packrat toolkit and parser-generator."},
{vsn, "1.1"}, {vsn, "1.3"},
{modules, [peg, peg_transform, peg_itransform, peg_gen, peg_meta, peg_meta_gen]}, {modules, [neotoma, neotoma_parse, neotoma_peg]},
{applications, [kernel, stdlib]} {applications, [kernel, stdlib]}
] ]
}. }.
8 changes: 4 additions & 4 deletions src/peg_gen.erl → src/neotoma.erl
@@ -1,4 +1,4 @@
-module(peg_gen). -module(neotoma).
-author("Sean Cribbs <seancribbs@gmail.com>"). -author("Sean Cribbs <seancribbs@gmail.com>").
-export([file/1, file/2, bootstrap/0]). -export([file/1, file/2, bootstrap/0]).


Expand Down Expand Up @@ -69,7 +69,7 @@ generate_module_attrs(ModName, Root) ->
" release_memo(), Result.\n"]. " release_memo(), Result.\n"].


parse_grammar(InputFile) -> parse_grammar(InputFile) ->
case peg_meta:file(InputFile) of case neotoma_parse:file(InputFile) of
{fail, Index} -> {fail, Index} ->
throw({grammar_error, {fail, Index}}); throw({grammar_error, {fail, Index}});
{Parsed, Remainder, Index} -> {Parsed, Remainder, Index} ->
Expand Down Expand Up @@ -99,6 +99,6 @@ generate_transform_stub(XfFile,ModName) ->
file:write_file(XfFile, Data). file:write_file(XfFile, Data).


%% @doc Bootstraps the neotoma metagrammar. Intended only for internal development! %% @doc Bootstraps the neotoma metagrammar. Intended only for internal development!
%% @equiv file("src/peg_meta.peg", [{transform_module, peg_meta_gen}]) %% @equiv file("src/neotoma_parse.peg")
bootstrap() -> bootstrap() ->
file("src/peg_meta.peg", [{transform_module, peg_meta_gen}]). file("src/neotoma_parse.peg").
4 changes: 2 additions & 2 deletions src/peg_meta.erl → src/neotoma_parse.erl
@@ -1,4 +1,4 @@
-module(peg_meta). -module(neotoma_parse).
-export([parse/1,file/1]). -export([parse/1,file/1]).
-compile(nowarn_unused_vars). -compile(nowarn_unused_vars).
-compile({nowarn_unused_function,[p/4, p/5, p_eof/0, p_optional/1, p_not/1, p_assert/1, p_seq/1, p_and/1, p_choose/1, p_zero_or_more/1, p_one_or_more/1, p_label/2, p_string/1, p_anything/0, p_charclass/1]}). -compile({nowarn_unused_function,[p/4, p/5, p_eof/0, p_optional/1, p_not/1, p_assert/1, p_seq/1, p_and/1, p_choose/1, p_zero_or_more/1, p_one_or_more/1, p_label/2, p_string/1, p_anything/0, p_charclass/1]}).
Expand All @@ -21,7 +21,7 @@ parse(Input) ->
{code, Block} -> Block; {code, Block} -> Block;
_ -> [] _ -> []
end, end,
[{rules, Rules ++ "\n" ++ Code}, {root, RootRule}, {transform, ets:lookup(peg_meta,gen_transform)}] [{rules, Rules ++ "\n" ++ Code}, {root, RootRule}, {transform, ets:lookup(?MODULE,gen_transform)}]
end). end).


'declaration_sequence'(Input, Index) -> 'declaration_sequence'(Input, Index) ->
Expand Down
2 changes: 1 addition & 1 deletion src/peg_meta.peg → src/neotoma_parse.peg
Expand Up @@ -6,7 +6,7 @@ rules <- space? declaration_sequence space? code_block? space?
{code, Block} -> Block; {code, Block} -> Block;
_ -> [] _ -> []
end, end,
[{rules, Rules ++ "\n" ++ Code}, {root, RootRule}, {transform, ets:lookup(peg_meta,gen_transform)}] [{rules, Rules ++ "\n" ++ Code}, {root, RootRule}, {transform, ets:lookup(?MODULE,gen_transform)}]
`; `;


declaration_sequence <- head:declaration tail:(space declaration)* declaration_sequence <- head:declaration tail:(space declaration)*
Expand Down
2 changes: 1 addition & 1 deletion src/peg.erl → src/neotoma_peg.erl
@@ -1,4 +1,4 @@
-module(peg). -module(neotoma_peg).
-author("Sean Cribbs <seancribbs@gmail.com>"). -author("Sean Cribbs <seancribbs@gmail.com>").


% Thanks to Jeffrey A. Meunier for the original parser.erl library from which I % Thanks to Jeffrey A. Meunier for the original parser.erl library from which I
Expand Down
135 changes: 0 additions & 135 deletions src/peg_meta_gen.erl

This file was deleted.

60 changes: 30 additions & 30 deletions tests/test_combinators.erl
Expand Up @@ -2,81 +2,81 @@
-author("Sean Cribbs <seancribbs@gmail.com>"). -author("Sean Cribbs <seancribbs@gmail.com>").
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").


% Test the parser-combinators in the 'peg' module % Test the parser-combinators in the 'neotoma_peg' module
-define(STARTINDEX, {{line,1},{column,1}}). -define(STARTINDEX, {{line,1},{column,1}}).
eof_test_() -> eof_test_() ->
[ [
?_assertEqual({fail,{expected,eof,?STARTINDEX}}, (peg:p_eof())("abc",?STARTINDEX)), ?_assertEqual({fail,{expected,eof,?STARTINDEX}}, (neotoma_peg:p_eof())("abc",?STARTINDEX)),
?_assertEqual({eof, [], ?STARTINDEX}, (peg:p_eof())("",?STARTINDEX)) ?_assertEqual({eof, [], ?STARTINDEX}, (neotoma_peg:p_eof())("",?STARTINDEX))
]. ].


optional_test_() -> optional_test_() ->
[ [
?_assertEqual({[], "xyz",?STARTINDEX}, (peg:p_optional(peg:p_string("abc")))("xyz",?STARTINDEX)), ?_assertEqual({[], "xyz",?STARTINDEX}, (neotoma_peg:p_optional(neotoma_peg:p_string("abc")))("xyz",?STARTINDEX)),
?_assertEqual({"abc", "xyz",{{line,1},{column,4}}}, (peg:p_optional(peg:p_string("abc")))("abcxyz",?STARTINDEX)) ?_assertEqual({"abc", "xyz",{{line,1},{column,4}}}, (neotoma_peg:p_optional(neotoma_peg:p_string("abc")))("abcxyz",?STARTINDEX))
]. ].


not_test_() -> not_test_() ->
[ [
?_assertEqual({[], "xyzabc",?STARTINDEX}, (peg:p_not(peg:p_string("abc")))("xyzabc",?STARTINDEX)), ?_assertEqual({[], "xyzabc",?STARTINDEX}, (neotoma_peg:p_not(neotoma_peg:p_string("abc")))("xyzabc",?STARTINDEX)),
?_assertEqual({fail,{expected, {no_match, "abc"}, ?STARTINDEX}}, (peg:p_not(peg:p_string("abc")))("abcxyz",?STARTINDEX)) ?_assertEqual({fail,{expected, {no_match, "abc"}, ?STARTINDEX}}, (neotoma_peg:p_not(neotoma_peg:p_string("abc")))("abcxyz",?STARTINDEX))
]. ].


assert_test_() -> assert_test_() ->
[ [
?_assertEqual({fail,{expected, {string, "abc"}, ?STARTINDEX}}, (peg:p_assert(peg:p_string("abc")))("xyzabc",?STARTINDEX)), ?_assertEqual({fail,{expected, {string, "abc"}, ?STARTINDEX}}, (neotoma_peg:p_assert(neotoma_peg:p_string("abc")))("xyzabc",?STARTINDEX)),
?_assertEqual({[], "abcxyz",?STARTINDEX}, (peg:p_assert(peg:p_string("abc")))("abcxyz",?STARTINDEX)) ?_assertEqual({[], "abcxyz",?STARTINDEX}, (neotoma_peg:p_assert(neotoma_peg:p_string("abc")))("abcxyz",?STARTINDEX))
]. ].


seq_test_() -> seq_test_() ->
[ [
?_assertEqual({["abc","def"], "xyz",{{line,1},{column,7}}}, (peg:p_seq([peg:p_string("abc"), peg:p_string("def")]))("abcdefxyz",?STARTINDEX)), ?_assertEqual({["abc","def"], "xyz",{{line,1},{column,7}}}, (neotoma_peg:p_seq([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def")]))("abcdefxyz",?STARTINDEX)),
?_assertEqual({fail,{expected, {string, "def"}, {{line,1},{column,4}}}}, (peg:p_seq([peg:p_string("abc"), peg:p_string("def")]))("abcxyz",?STARTINDEX)) ?_assertEqual({fail,{expected, {string, "def"}, {{line,1},{column,4}}}}, (neotoma_peg:p_seq([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def")]))("abcxyz",?STARTINDEX))
]. ].


choose_test_() -> choose_test_() ->
[ [
?_assertEqual({"abc", "xyz", {{line,1},{column,4}}}, (peg:p_choose([peg:p_string("abc"), peg:p_string("def")]))("abcxyz",?STARTINDEX)), ?_assertEqual({"abc", "xyz", {{line,1},{column,4}}}, (neotoma_peg:p_choose([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def")]))("abcxyz",?STARTINDEX)),
?_assertEqual({"def", "xyz", {{line,1},{column,4}}}, (peg:p_choose([peg:p_string("abc"), peg:p_string("def")]))("defxyz",?STARTINDEX)), ?_assertEqual({"def", "xyz", {{line,1},{column,4}}}, (neotoma_peg:p_choose([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def")]))("defxyz",?STARTINDEX)),
?_assertEqual({"xyz", "xyz", {{line,1},{column,4}}}, (peg:p_choose([peg:p_string("abc"), peg:p_string("def"), peg:p_string("xyz")]))("xyzxyz",?STARTINDEX)), ?_assertEqual({"xyz", "xyz", {{line,1},{column,4}}}, (neotoma_peg:p_choose([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def"), neotoma_peg:p_string("xyz")]))("xyzxyz",?STARTINDEX)),
?_assertEqual({fail,{expected,{string,"abc"},?STARTINDEX}}, (peg:p_choose([peg:p_string("abc"),peg:p_string("def")]))("xyz", ?STARTINDEX)) ?_assertEqual({fail,{expected,{string,"abc"},?STARTINDEX}}, (neotoma_peg:p_choose([neotoma_peg:p_string("abc"),neotoma_peg:p_string("def")]))("xyz", ?STARTINDEX))
]. ].


zero_or_more_test_() -> zero_or_more_test_() ->
[ [
?_assertEqual({[], [], ?STARTINDEX}, (peg:p_zero_or_more(peg:p_string("abc")))("",?STARTINDEX)), ?_assertEqual({[], [], ?STARTINDEX}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("",?STARTINDEX)),
?_assertEqual({[], "def",?STARTINDEX}, (peg:p_zero_or_more(peg:p_string("abc")))("def",?STARTINDEX)), ?_assertEqual({[], "def",?STARTINDEX}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("def",?STARTINDEX)),
?_assertEqual({["abc"], "def",{{line,1},{column,4}}}, (peg:p_zero_or_more(peg:p_string("abc")))("abcdef",?STARTINDEX)), ?_assertEqual({["abc"], "def",{{line,1},{column,4}}}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("abcdef",?STARTINDEX)),
?_assertEqual({["abc", "abc"], "def",{{line,1},{column,7}}}, (peg:p_zero_or_more(peg:p_string("abc")))("abcabcdef",?STARTINDEX)) ?_assertEqual({["abc", "abc"], "def",{{line,1},{column,7}}}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("abcabcdef",?STARTINDEX))
]. ].


one_or_more_test_() -> one_or_more_test_() ->
[ [
?_assertEqual({fail,{expected, {at_least_one, {string, "abc"}}, ?STARTINDEX}}, (peg:p_one_or_more(peg:p_string("abc")))("def",?STARTINDEX)), ?_assertEqual({fail,{expected, {at_least_one, {string, "abc"}}, ?STARTINDEX}}, (neotoma_peg:p_one_or_more(neotoma_peg:p_string("abc")))("def",?STARTINDEX)),
?_assertEqual({["abc"], "def",{{line,1},{column,4}}}, (peg:p_one_or_more(peg:p_string("abc")))("abcdef",?STARTINDEX)), ?_assertEqual({["abc"], "def",{{line,1},{column,4}}}, (neotoma_peg:p_one_or_more(neotoma_peg:p_string("abc")))("abcdef",?STARTINDEX)),
?_assertEqual({["abc","abc"], "def",{{line,1},{column,7}}}, (peg:p_one_or_more(peg:p_string("abc")))("abcabcdef",?STARTINDEX)) ?_assertEqual({["abc","abc"], "def",{{line,1},{column,7}}}, (neotoma_peg:p_one_or_more(neotoma_peg:p_string("abc")))("abcabcdef",?STARTINDEX))
]. ].


label_test_() -> label_test_() ->
[ [
?_assertEqual({fail,{expected, {string, "!"}, ?STARTINDEX}}, (peg:p_label(bang, peg:p_string("!")))("?",?STARTINDEX)), ?_assertEqual({fail,{expected, {string, "!"}, ?STARTINDEX}}, (neotoma_peg:p_label(bang, neotoma_peg:p_string("!")))("?",?STARTINDEX)),
?_assertEqual({{bang, "!"}, "",{{line,1},{column,2}}}, (peg:p_label(bang, peg:p_string("!")))("!",?STARTINDEX)) ?_assertEqual({{bang, "!"}, "",{{line,1},{column,2}}}, (neotoma_peg:p_label(bang, neotoma_peg:p_string("!")))("!",?STARTINDEX))
]. ].


string_test_() -> string_test_() ->
[ [
?_assertEqual({"abc", "def",{{line,1},{column,4}}}, (peg:p_string("abc"))("abcdef",?STARTINDEX)), ?_assertEqual({"abc", "def",{{line,1},{column,4}}}, (neotoma_peg:p_string("abc"))("abcdef",?STARTINDEX)),
?_assertEqual({fail,{expected, {string, "abc"}, ?STARTINDEX}}, (peg:p_string("abc"))("defabc",?STARTINDEX)) ?_assertEqual({fail,{expected, {string, "abc"}, ?STARTINDEX}}, (neotoma_peg:p_string("abc"))("defabc",?STARTINDEX))
]. ].


anything_test_() -> anything_test_() ->
[ [
?_assertEqual({$a,"bcde",{{line,1},{column,2}}}, (peg:p_anything())("abcde",?STARTINDEX)), ?_assertEqual({$a,"bcde",{{line,1},{column,2}}}, (neotoma_peg:p_anything())("abcde",?STARTINDEX)),
?_assertEqual({fail,{expected, any_character, ?STARTINDEX}}, (peg:p_anything())("",?STARTINDEX)) ?_assertEqual({fail,{expected, any_character, ?STARTINDEX}}, (neotoma_peg:p_anything())("",?STARTINDEX))
]. ].


charclass_test_() -> charclass_test_() ->
[ [
?_assertEqual({$+,"----",{{line,1},{column,2}}}, (peg:p_charclass("[+]"))("+----",?STARTINDEX)), ?_assertEqual({$+,"----",{{line,1},{column,2}}}, (neotoma_peg:p_charclass("[+]"))("+----",?STARTINDEX)),
?_assertEqual({fail,{expected, {character_class, "[+]"}, ?STARTINDEX}}, (peg:p_charclass("[+]"))("----",?STARTINDEX)) ?_assertEqual({fail,{expected, {character_class, "[+]"}, ?STARTINDEX}}, (neotoma_peg:p_charclass("[+]"))("----",?STARTINDEX))
]. ].
20 changes: 10 additions & 10 deletions tests/test_memoization.erl
Expand Up @@ -3,20 +3,20 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").


setup_memo_test() -> setup_memo_test() ->
peg:setup_memo(), neotoma_peg:setup_memo(),
?assertNot(undefined == ets:info(peg)), ?assertNot(undefined == ets:info(neotoma_peg)),
peg:release_memo(). neotoma_peg:release_memo().


release_memo_test() -> release_memo_test() ->
peg:setup_memo(), neotoma_peg:setup_memo(),
peg:release_memo(), neotoma_peg:release_memo(),
?assertEqual(undefined, ets:info(peg)). ?assertEqual(undefined, ets:info(neotoma_peg)).


step_memo_test() -> step_memo_test() ->
peg:setup_memo(), neotoma_peg:setup_memo(),
Result = peg:p("abcdefghi", {{line,1},{column,1}}, anything, peg:p_anything()), Result = neotoma_peg:p("abcdefghi", {{line,1},{column,1}}, anything, neotoma_peg:p_anything()),
?assertEqual({$a, "bcdefghi", {{line,1},{column,2}}}, Result), ?assertEqual({$a, "bcdefghi", {{line,1},{column,2}}}, Result),
Result2 = peg:p("abcdefghi", {{line,1},{column,1}}, anything, fun(_) -> Result2 = neotoma_peg:p("abcdefghi", {{line,1},{column,1}}, anything, fun(_) ->
throw(bork) end), throw(bork) end),
?assertEqual(Result, Result2), ?assertEqual(Result, Result2),
peg:release_memo(). neotoma_peg:release_memo().

0 comments on commit cbf275a

Please sign in to comment.