Skip to content

Commit cbf275a

Browse files
committed
The big rename and cleanup.
* peg_meta_gen no longer necessary * peg_gen -> neotoma * peg_meta -> neotoma_parse * peg -> neotoma_peg
1 parent 8652541 commit cbf275a

File tree

10 files changed

+55
-190
lines changed

10 files changed

+55
-190
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ priv:
1616
ebin_tests:
1717
mkdir ebin_tests
1818

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

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

3535
bootstrap: src_src
36-
${ERL} -pz ebin -b start_sasl -noshell -s init stop -eval 'peg_gen:bootstrap().'
37-
cd src;erl -pz ../ebin -make
36+
${ERL} -pz ebin -b start_sasl -noshell -s init stop -eval 'neotoma:bootstrap().'
37+
cd src;erl -pz ../ebin -make

src/Emakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{[peg, peg_gen, peg_meta, peg_meta_gen],
1+
{[neotoma_peg, neotoma, neotoma_parse],
22
[{outdir, "../ebin"}, {i, "../../"}, debug_info]}.

src/neotoma.app

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{application, neotoma,
22
[
33
{description, "PEG/Packrat toolkit and parser-generator."},
4-
{vsn, "1.1"},
5-
{modules, [peg, peg_transform, peg_itransform, peg_gen, peg_meta, peg_meta_gen]},
4+
{vsn, "1.3"},
5+
{modules, [neotoma, neotoma_parse, neotoma_peg]},
66
{applications, [kernel, stdlib]}
77
]
88
}.

src/peg_gen.erl renamed to src/neotoma.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-module(peg_gen).
1+
-module(neotoma).
22
-author("Sean Cribbs <seancribbs@gmail.com>").
33
-export([file/1, file/2, bootstrap/0]).
44

@@ -69,7 +69,7 @@ generate_module_attrs(ModName, Root) ->
6969
" release_memo(), Result.\n"].
7070

7171
parse_grammar(InputFile) ->
72-
case peg_meta:file(InputFile) of
72+
case neotoma_parse:file(InputFile) of
7373
{fail, Index} ->
7474
throw({grammar_error, {fail, Index}});
7575
{Parsed, Remainder, Index} ->
@@ -99,6 +99,6 @@ generate_transform_stub(XfFile,ModName) ->
9999
file:write_file(XfFile, Data).
100100

101101
%% @doc Bootstraps the neotoma metagrammar. Intended only for internal development!
102-
%% @equiv file("src/peg_meta.peg", [{transform_module, peg_meta_gen}])
102+
%% @equiv file("src/neotoma_parse.peg")
103103
bootstrap() ->
104-
file("src/peg_meta.peg", [{transform_module, peg_meta_gen}]).
104+
file("src/neotoma_parse.peg").

src/peg_meta.erl renamed to src/neotoma_parse.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-module(peg_meta).
1+
-module(neotoma_parse).
22
-export([parse/1,file/1]).
33
-compile(nowarn_unused_vars).
44
-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]}).
@@ -21,7 +21,7 @@ parse(Input) ->
2121
{code, Block} -> Block;
2222
_ -> []
2323
end,
24-
[{rules, Rules ++ "\n" ++ Code}, {root, RootRule}, {transform, ets:lookup(peg_meta,gen_transform)}]
24+
[{rules, Rules ++ "\n" ++ Code}, {root, RootRule}, {transform, ets:lookup(?MODULE,gen_transform)}]
2525
end).
2626

2727
'declaration_sequence'(Input, Index) ->

src/peg_meta.peg renamed to src/neotoma_parse.peg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ rules <- space? declaration_sequence space? code_block? space?
66
{code, Block} -> Block;
77
_ -> []
88
end,
9-
[{rules, Rules ++ "\n" ++ Code}, {root, RootRule}, {transform, ets:lookup(peg_meta,gen_transform)}]
9+
[{rules, Rules ++ "\n" ++ Code}, {root, RootRule}, {transform, ets:lookup(?MODULE,gen_transform)}]
1010
`;
1111

1212
declaration_sequence <- head:declaration tail:(space declaration)*

src/peg.erl renamed to src/neotoma_peg.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-module(peg).
1+
-module(neotoma_peg).
22
-author("Sean Cribbs <seancribbs@gmail.com>").
33

44
% Thanks to Jeffrey A. Meunier for the original parser.erl library from which I

src/peg_meta_gen.erl

Lines changed: 0 additions & 135 deletions
This file was deleted.

tests/test_combinators.erl

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,81 @@
22
-author("Sean Cribbs <seancribbs@gmail.com>").
33
-include_lib("eunit/include/eunit.hrl").
44

5-
% Test the parser-combinators in the 'peg' module
5+
% Test the parser-combinators in the 'neotoma_peg' module
66
-define(STARTINDEX, {{line,1},{column,1}}).
77
eof_test_() ->
88
[
9-
?_assertEqual({fail,{expected,eof,?STARTINDEX}}, (peg:p_eof())("abc",?STARTINDEX)),
10-
?_assertEqual({eof, [], ?STARTINDEX}, (peg:p_eof())("",?STARTINDEX))
9+
?_assertEqual({fail,{expected,eof,?STARTINDEX}}, (neotoma_peg:p_eof())("abc",?STARTINDEX)),
10+
?_assertEqual({eof, [], ?STARTINDEX}, (neotoma_peg:p_eof())("",?STARTINDEX))
1111
].
1212

1313
optional_test_() ->
1414
[
15-
?_assertEqual({[], "xyz",?STARTINDEX}, (peg:p_optional(peg:p_string("abc")))("xyz",?STARTINDEX)),
16-
?_assertEqual({"abc", "xyz",{{line,1},{column,4}}}, (peg:p_optional(peg:p_string("abc")))("abcxyz",?STARTINDEX))
15+
?_assertEqual({[], "xyz",?STARTINDEX}, (neotoma_peg:p_optional(neotoma_peg:p_string("abc")))("xyz",?STARTINDEX)),
16+
?_assertEqual({"abc", "xyz",{{line,1},{column,4}}}, (neotoma_peg:p_optional(neotoma_peg:p_string("abc")))("abcxyz",?STARTINDEX))
1717
].
1818

1919
not_test_() ->
2020
[
21-
?_assertEqual({[], "xyzabc",?STARTINDEX}, (peg:p_not(peg:p_string("abc")))("xyzabc",?STARTINDEX)),
22-
?_assertEqual({fail,{expected, {no_match, "abc"}, ?STARTINDEX}}, (peg:p_not(peg:p_string("abc")))("abcxyz",?STARTINDEX))
21+
?_assertEqual({[], "xyzabc",?STARTINDEX}, (neotoma_peg:p_not(neotoma_peg:p_string("abc")))("xyzabc",?STARTINDEX)),
22+
?_assertEqual({fail,{expected, {no_match, "abc"}, ?STARTINDEX}}, (neotoma_peg:p_not(neotoma_peg:p_string("abc")))("abcxyz",?STARTINDEX))
2323
].
2424

2525
assert_test_() ->
2626
[
27-
?_assertEqual({fail,{expected, {string, "abc"}, ?STARTINDEX}}, (peg:p_assert(peg:p_string("abc")))("xyzabc",?STARTINDEX)),
28-
?_assertEqual({[], "abcxyz",?STARTINDEX}, (peg:p_assert(peg:p_string("abc")))("abcxyz",?STARTINDEX))
27+
?_assertEqual({fail,{expected, {string, "abc"}, ?STARTINDEX}}, (neotoma_peg:p_assert(neotoma_peg:p_string("abc")))("xyzabc",?STARTINDEX)),
28+
?_assertEqual({[], "abcxyz",?STARTINDEX}, (neotoma_peg:p_assert(neotoma_peg:p_string("abc")))("abcxyz",?STARTINDEX))
2929
].
3030

3131
seq_test_() ->
3232
[
33-
?_assertEqual({["abc","def"], "xyz",{{line,1},{column,7}}}, (peg:p_seq([peg:p_string("abc"), peg:p_string("def")]))("abcdefxyz",?STARTINDEX)),
34-
?_assertEqual({fail,{expected, {string, "def"}, {{line,1},{column,4}}}}, (peg:p_seq([peg:p_string("abc"), peg:p_string("def")]))("abcxyz",?STARTINDEX))
33+
?_assertEqual({["abc","def"], "xyz",{{line,1},{column,7}}}, (neotoma_peg:p_seq([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def")]))("abcdefxyz",?STARTINDEX)),
34+
?_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))
3535
].
3636

3737
choose_test_() ->
3838
[
39-
?_assertEqual({"abc", "xyz", {{line,1},{column,4}}}, (peg:p_choose([peg:p_string("abc"), peg:p_string("def")]))("abcxyz",?STARTINDEX)),
40-
?_assertEqual({"def", "xyz", {{line,1},{column,4}}}, (peg:p_choose([peg:p_string("abc"), peg:p_string("def")]))("defxyz",?STARTINDEX)),
41-
?_assertEqual({"xyz", "xyz", {{line,1},{column,4}}}, (peg:p_choose([peg:p_string("abc"), peg:p_string("def"), peg:p_string("xyz")]))("xyzxyz",?STARTINDEX)),
42-
?_assertEqual({fail,{expected,{string,"abc"},?STARTINDEX}}, (peg:p_choose([peg:p_string("abc"),peg:p_string("def")]))("xyz", ?STARTINDEX))
39+
?_assertEqual({"abc", "xyz", {{line,1},{column,4}}}, (neotoma_peg:p_choose([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def")]))("abcxyz",?STARTINDEX)),
40+
?_assertEqual({"def", "xyz", {{line,1},{column,4}}}, (neotoma_peg:p_choose([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def")]))("defxyz",?STARTINDEX)),
41+
?_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)),
42+
?_assertEqual({fail,{expected,{string,"abc"},?STARTINDEX}}, (neotoma_peg:p_choose([neotoma_peg:p_string("abc"),neotoma_peg:p_string("def")]))("xyz", ?STARTINDEX))
4343
].
4444

4545
zero_or_more_test_() ->
4646
[
47-
?_assertEqual({[], [], ?STARTINDEX}, (peg:p_zero_or_more(peg:p_string("abc")))("",?STARTINDEX)),
48-
?_assertEqual({[], "def",?STARTINDEX}, (peg:p_zero_or_more(peg:p_string("abc")))("def",?STARTINDEX)),
49-
?_assertEqual({["abc"], "def",{{line,1},{column,4}}}, (peg:p_zero_or_more(peg:p_string("abc")))("abcdef",?STARTINDEX)),
50-
?_assertEqual({["abc", "abc"], "def",{{line,1},{column,7}}}, (peg:p_zero_or_more(peg:p_string("abc")))("abcabcdef",?STARTINDEX))
47+
?_assertEqual({[], [], ?STARTINDEX}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("",?STARTINDEX)),
48+
?_assertEqual({[], "def",?STARTINDEX}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("def",?STARTINDEX)),
49+
?_assertEqual({["abc"], "def",{{line,1},{column,4}}}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("abcdef",?STARTINDEX)),
50+
?_assertEqual({["abc", "abc"], "def",{{line,1},{column,7}}}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("abcabcdef",?STARTINDEX))
5151
].
5252

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

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

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

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

7878
charclass_test_() ->
7979
[
80-
?_assertEqual({$+,"----",{{line,1},{column,2}}}, (peg:p_charclass("[+]"))("+----",?STARTINDEX)),
81-
?_assertEqual({fail,{expected, {character_class, "[+]"}, ?STARTINDEX}}, (peg:p_charclass("[+]"))("----",?STARTINDEX))
80+
?_assertEqual({$+,"----",{{line,1},{column,2}}}, (neotoma_peg:p_charclass("[+]"))("+----",?STARTINDEX)),
81+
?_assertEqual({fail,{expected, {character_class, "[+]"}, ?STARTINDEX}}, (neotoma_peg:p_charclass("[+]"))("----",?STARTINDEX))
8282
].

tests/test_memoization.erl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
-include_lib("eunit/include/eunit.hrl").
44

55
setup_memo_test() ->
6-
peg:setup_memo(),
7-
?assertNot(undefined == ets:info(peg)),
8-
peg:release_memo().
6+
neotoma_peg:setup_memo(),
7+
?assertNot(undefined == ets:info(neotoma_peg)),
8+
neotoma_peg:release_memo().
99

1010
release_memo_test() ->
11-
peg:setup_memo(),
12-
peg:release_memo(),
13-
?assertEqual(undefined, ets:info(peg)).
11+
neotoma_peg:setup_memo(),
12+
neotoma_peg:release_memo(),
13+
?assertEqual(undefined, ets:info(neotoma_peg)).
1414

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

0 commit comments

Comments
 (0)