Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #30 from metadave/dp_unicode_again

use unicode fn instead of list_to_binary
  • Loading branch information...
commit 6c4a6009d3f34da2ec42c4f3585dae0abbb49dfc 2 parents ac74fef + 762b2c0
Sean Cribbs authored
2  src/neotoma.erl
View
@@ -84,7 +84,7 @@ generate_entry_functions(Root) ->
["-spec file(file:name()) -> any().\n",
"file(Filename) -> case file:read_file(Filename) of {ok,Bin} -> parse(Bin); Err -> Err end.\n\n",
"-spec parse(binary() | list()) -> any().\n",
- "parse(List) when is_list(List) -> parse(list_to_binary(List));\n",
+ "parse(List) when is_list(List) -> parse(unicode:characters_to_binary(List));\n",
"parse(Input) when is_binary(Input) ->\n",
" _ = setup_memo(),\n",
" Result = case '",RootRule,"'(Input,{{line,1},{column,1}}) of\n",
2  src/neotoma_parse.erl
View
@@ -116,7 +116,7 @@ used_transform_variables([], Acc) ->
file(Filename) -> case file:read_file(Filename) of {ok,Bin} -> parse(Bin); Err -> Err end.
-spec parse(binary() | list()) -> any().
-parse(List) when is_list(List) -> parse(list_to_binary(List));
+parse(List) when is_list(List) -> parse(unicode:characters_to_binary(List));
parse(Input) when is_binary(Input) ->
_ = setup_memo(),
Result = case 'rules'(Input,{{line,1},{column,1}}) of
2  src/neotoma_parse.erl.safe
View
@@ -116,7 +116,7 @@ used_transform_variables([], Acc) ->
file(Filename) -> case file:read_file(Filename) of {ok,Bin} -> parse(Bin); Err -> Err end.
-spec parse(binary() | list()) -> any().
-parse(List) when is_list(List) -> parse(list_to_binary(List));
+parse(List) when is_list(List) -> parse(unicode:characters_to_binary(List));
parse(Input) when is_binary(Input) ->
setup_memo(),
Result = case 'rules'(Input,{{line,1},{column,1}}) of
19 test/test_parse.erl
View
@@ -0,0 +1,19 @@
+-module(test_parse).
+-include_lib("eunit/include/eunit.hrl").
+
+parser_test() ->
+ % so we don't have to copy test.peg to .eunit
+ Data = "rule <- .+;",
+ file:write_file("test_parser.peg", io_lib:fwrite("~s\n", [Data])),
+ neotoma:file("test_parser.peg"),
+ compile:file("test_parser.erl", []),
+ try
+ TestString = [19990,30028,32,102,111,111],
+ Result = test_parser:parse(TestString),
+ ?assertEqual(6, length(Result)),
+ StringResult = lists:flatten(io_lib:format("~ts", [Result])),
+ ?assertEqual(TestString, StringResult)
+ catch
+ _:_ -> ?assert(false)
+ end.
+
2  test/test_suite.erl
View
@@ -3,4 +3,4 @@
-include_lib("eunit/include/eunit.hrl").
all_test_() ->
- [{module, test_combinators},{module, test_memoization}].
+ [{module, test_combinators},{module, test_memoization},{module, test_parse}].
Please sign in to comment.
Something went wrong with that request. Please try again.