From 08e2d74ac0957a1a274be359d50d601a21d3ef0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Sat, 13 Feb 2010 10:19:55 +0100 Subject: parsetools: Replace TABs with spaces The files in the parsetools application are supposed to be indented using spaces only. Remove the stray TABs that somehow have crept in. --- lib/parsetools/include/yeccpre.hrl | 10 +++++----- lib/parsetools/src/yeccparser.erl | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'lib/parsetools') diff --git a/lib/parsetools/include/yeccpre.hrl b/lib/parsetools/include/yeccpre.hrl index 2ffa13d6a7..ceaf06f0f7 100644 --- a/lib/parsetools/include/yeccpre.hrl +++ b/lib/parsetools/include/yeccpre.hrl @@ -37,10 +37,10 @@ parse_and_scan({M, F, A}) -> -spec(format_error/1 :: (any()) -> [char() | list()]). format_error(Message) -> case io_lib:deep_char_list(Message) of - true -> - Message; - _ -> - io_lib:write(Message) + true -> + Message; + _ -> + io_lib:write(Message) end. % To be used in grammar files to throw an error message to the parser @@ -85,7 +85,7 @@ yeccpars1([Token | Tokens], Tzr, State, States, Vstack) -> yeccpars1([], {{F, A},_Line}, State, States, Vstack) -> case apply(F, A) of {ok, Tokens, Endline} -> - yeccpars1(Tokens, {{F, A}, Endline}, State, States, Vstack); + yeccpars1(Tokens, {{F, A}, Endline}, State, States, Vstack); {eof, Endline} -> yeccpars1([], {no_func, Endline}, State, States, Vstack); {error, Descriptor, _Endline} -> diff --git a/lib/parsetools/src/yeccparser.erl b/lib/parsetools/src/yeccparser.erl index 80a6bbce0e..1bd922ce5c 100644 --- a/lib/parsetools/src/yeccparser.erl +++ b/lib/parsetools/src/yeccparser.erl @@ -53,10 +53,10 @@ parse_and_scan({M, F, A}) -> -spec(format_error/1 :: (any()) -> [char() | list()]). format_error(Message) -> case io_lib:deep_char_list(Message) of - true -> - Message; - _ -> - io_lib:write(Message) + true -> + Message; + _ -> + io_lib:write(Message) end. % To be used in grammar files to throw an error message to the parser @@ -101,7 +101,7 @@ yeccpars1([Token | Tokens], Tokenizer, State, States, Vstack) -> yeccpars1([], {F, A}, State, States, Vstack) -> case apply(F, A) of {ok, Tokens, _Endline} -> - yeccpars1(Tokens, {F, A}, State, States, Vstack); + yeccpars1(Tokens, {F, A}, State, States, Vstack); {eof, _Endline} -> yeccpars1([], false, State, States, Vstack); {error, Descriptor, _Endline} -> @@ -123,7 +123,7 @@ yeccpars1(State1, State, States, Vstack, Stack1, [Token | Tokens], yeccpars1(State1, State, States, Vstack, Stack1, [], {F, A}) -> case apply(F, A) of {ok, Tokens, _Endline} -> - yeccpars1(State1, State, States, Vstack, Stack1, Tokens, {F, A}); + yeccpars1(State1, State, States, Vstack, Stack1, Tokens, {F, A}); {eof, _Endline} -> yeccpars1(State1, State, States, Vstack, Stack1, [], false); {error, Descriptor, _Endline} -> -- cgit v1.2.3 From 3117c771e07d8bfee5c3141aabfbc3902c65323b Mon Sep 17 00:00:00 2001 From: Kostis Sagonas Date: Fri, 12 Feb 2010 18:06:35 +0100 Subject: parsetools: Modernize types and specs --- lib/parsetools/include/yeccpre.hrl | 13 ++++++------- lib/parsetools/src/yeccparser.erl | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) (limited to 'lib/parsetools') diff --git a/lib/parsetools/include/yeccpre.hrl b/lib/parsetools/include/yeccpre.hrl index ceaf06f0f7..bbf6c8a232 100644 --- a/lib/parsetools/include/yeccpre.hrl +++ b/lib/parsetools/include/yeccpre.hrl @@ -20,21 +20,20 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % The parser generator will insert appropriate declarations before this line.% --type(yecc_ret() :: {'error', _} | {'ok', _}). +-type yecc_ret() :: {'error', _} | {'ok', _}. -spec parse(Tokens :: list()) -> yecc_ret(). parse(Tokens) -> yeccpars0(Tokens, {no_func, no_line}, 0, [], []). --spec(parse_and_scan/1 :: - ({function() | {atom(), atom()}, [_]} | {atom(), atom(), [_]}) -> - yecc_ret()). +-spec parse_and_scan({function() | {atom(), atom()}, [_]} | {atom(), atom(), [_]}) -> + yecc_ret(). parse_and_scan({F, A}) -> % Fun or {M, F} yeccpars0([], {{F, A}, no_line}, 0, [], []); parse_and_scan({M, F, A}) -> yeccpars0([], {{{M, F}, A}, no_line}, 0, [], []). --spec(format_error/1 :: (any()) -> [char() | list()]). +-spec format_error(any()) -> [char() | list()]. format_error(Message) -> case io_lib:deep_char_list(Message) of true -> @@ -45,8 +44,8 @@ format_error(Message) -> % To be used in grammar files to throw an error message to the parser % toplevel. Doesn't have to be exported! --compile({nowarn_unused_function, return_error/2}). --spec(return_error/2 :: (integer(), any()) -> no_return()). +-compile({nowarn_unused_function,{return_error,2}}). +-spec return_error(integer(), any()) -> no_return(). return_error(Line, Message) -> throw({error, {Line, ?MODULE, Message}}). diff --git a/lib/parsetools/src/yeccparser.erl b/lib/parsetools/src/yeccparser.erl index 1bd922ce5c..7cadb0a68d 100644 --- a/lib/parsetools/src/yeccparser.erl +++ b/lib/parsetools/src/yeccparser.erl @@ -36,21 +36,20 @@ line_of(Token) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % The parser generator will insert appropriate declarations before this line.% --type(yecc_ret() :: {'error', _} | {'ok', _}). +-type yecc_ret() :: {'error', _} | {'ok', _}. --spec(parse/1 :: (_) -> yecc_ret()). +-spec parse(_) -> yecc_ret(). parse(Tokens) -> yeccpars0(Tokens, false). --spec(parse_and_scan/1 :: - ({function() | {atom(), atom()}, [_]} | {atom(), atom(), [_]}) -> - yecc_ret()). +-spec parse_and_scan({function() | {atom(), atom()}, [_]} | {atom(), atom(), [_]}) -> + yecc_ret(). parse_and_scan({F, A}) -> % Fun or {M, F} yeccpars0([], {F, A}); parse_and_scan({M, F, A}) -> yeccpars0([], {{M, F}, A}). --spec(format_error/1 :: (any()) -> [char() | list()]). +-spec format_error(any()) -> [char() | list()]. format_error(Message) -> case io_lib:deep_char_list(Message) of true -> @@ -62,7 +61,7 @@ format_error(Message) -> % To be used in grammar files to throw an error message to the parser % toplevel. Doesn't have to be exported! -compile({nowarn_unused_function,{return_error,2}}). --spec(return_error/2 :: (integer(), any()) -> no_return()). +-spec return_error(integer(), any()) -> no_return(). return_error(Line, Message) -> throw({error, {Line, ?MODULE, Message}}). -- cgit v1.2.3 From b573c21e29d3763c6950f93308cf695ac3eab9ef Mon Sep 17 00:00:00 2001 From: Kostis Sagonas Date: Fri, 12 Feb 2010 18:27:28 +0100 Subject: parsetools: Replace lists:keysearch/3 with lists:keyfind/3 --- lib/parsetools/src/yecc.erl | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'lib/parsetools') diff --git a/lib/parsetools/src/yecc.erl b/lib/parsetools/src/yecc.erl index f4d76f471d..1f1fa96e61 100644 --- a/lib/parsetools/src/yecc.erl +++ b/lib/parsetools/src/yecc.erl @@ -30,8 +30,8 @@ -import(lists, [append/1, append/2, concat/1, delete/2, filter/2, flatmap/2, foldl/3, foldr/3, foreach/2, keydelete/3, - keysearch/3, keysort/2, last/1, map/2, member/2, - reverse/1, sort/1, usort/1]). + keysort/2, last/1, map/2, member/2, reverse/1, + sort/1, usort/1]). -include("erl_compile.hrl"). -include("ms_transform.hrl"). @@ -297,18 +297,18 @@ options(Options0, [Key | Keys], L) when is_list(Options0) -> false -> Options0 end, - V = case keysearch(Key, 1, Options) of - {value, {Key, Filename0}} when Key =:= includefile; - Key =:= parserfile -> + V = case lists:keyfind(Key, 1, Options) of + {Key, Filename0} when Key =:= includefile; + Key =:= parserfile -> case is_filename(Filename0) of no -> badarg; Filename -> {ok, [{Key, Filename}]} end; - {value, {Key, Bool}} when Bool =:= true; Bool =:= false -> - {ok, [{Key, Bool}]}; - {value, {Key, _}} -> + {Key, Bool} = KB when is_boolean(Bool) -> + {ok, [KB]}; + {Key, _} -> badarg; false -> {ok, [{Key, default_option(Key)}]} @@ -366,8 +366,8 @@ shorten_filename(Name0) -> start(Infilex, Options) -> Infile = assure_extension(Infilex, ".yrl"), - {value, {_, Outfilex0}} = keysearch(parserfile, 1, Options), - {value, {_, Includefilex}} = keysearch(includefile, 1, Options), + {_, Outfilex0} = lists:keyfind(parserfile, 1, Options), + {_, Includefilex} = lists:keyfind(includefile, 1, Options), Outfilex = case Outfilex0 of [] -> filename:rootname(Infilex, ".yrl"); _ -> Outfilex0 @@ -715,14 +715,14 @@ names(Symbols) -> map(fun(Symbol) -> Symbol#symbol.name end, Symbols). symbol_line(Name, St) -> - {value, #symbol{line = Line}} = symbol_search(Name, St#yecc.all_symbols), + #symbol{line = Line} = symbol_find(Name, St#yecc.all_symbols), Line. symbol_member(Symbol, Symbols) -> - symbol_search(Symbol#symbol.name, Symbols) =/= false. + symbol_find(Symbol#symbol.name, Symbols) =/= false. -symbol_search(Name, Symbols) -> - keysearch(Name, #symbol.name, Symbols). +symbol_find(Name, Symbols) -> + lists:keyfind(Name, #symbol.name, Symbols). states_and_goto_table(St0) -> St1 = create_symbol_table(St0), @@ -876,8 +876,8 @@ add_warnings(SymNames, W0, St0) -> check_rhs([#symbol{name = '$empty'}], St) -> St; check_rhs(Rhs, St0) -> - case symbol_search('$empty', Rhs) of - {value, #symbol{line = Line}} -> + case symbol_find('$empty', Rhs) of + #symbol{line = Line} -> add_error(Line, illegal_empty, St0); false -> foldl(fun(Sym, St) -> @@ -1096,10 +1096,10 @@ compute_states2([{Sym,Seed} | Seeds], N, Try, CurrState, StateTab, Tables) -> compute_states2(Seeds, N, Try, CurrState, StateTab, Tables); {merge, M, NewCurrent} -> %% io:fwrite(<<"Merging with state ~w\n">>, [M]), - Try1 = case keysearch(M, 1, Try) of + Try1 = case lists:keyfind(M, 1, Try) of false -> [{M, NewCurrent} | Try]; - {value, {_, OldCurrent}} -> + {_, OldCurrent} -> case ordsets:is_subset(NewCurrent, OldCurrent) of true -> Try; -- cgit v1.2.3 From 152088ba9594105ddee758021e4f5428a5e710cc Mon Sep 17 00:00:00 2001 From: Kostis Sagonas Date: Fri, 12 Feb 2010 18:38:32 +0100 Subject: parsetools: Use %% for comments at the beginning of a line According to the style guidelines (and the Erlang mode for Emacs), comments at the beginning of a line should start with "%%", not "%". --- lib/parsetools/include/yeccpre.hrl | 6 +++--- lib/parsetools/src/yeccparser.erl | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/parsetools') diff --git a/lib/parsetools/include/yeccpre.hrl b/lib/parsetools/include/yeccpre.hrl index bbf6c8a232..252274c553 100644 --- a/lib/parsetools/include/yeccpre.hrl +++ b/lib/parsetools/include/yeccpre.hrl @@ -42,8 +42,8 @@ format_error(Message) -> io_lib:write(Message) end. -% To be used in grammar files to throw an error message to the parser -% toplevel. Doesn't have to be exported! +%% To be used in grammar files to throw an error message to the parser +%% toplevel. Doesn't have to be exported! -compile({nowarn_unused_function,{return_error,2}}). -spec return_error(integer(), any()) -> no_return(). return_error(Line, Message) -> @@ -117,7 +117,7 @@ yeccpars1(State1, State, States, Vstack, Token0, [], {no_func, Line}) -> yeccpars2(State, '$end', [State1 | States], [Token0 | Vstack], yecc_end(Line), [], {no_func, Line}). -% For internal use only. +%% For internal use only. yecc_end({Line,_Column}) -> {'$end', Line}; yecc_end(Line) -> diff --git a/lib/parsetools/src/yeccparser.erl b/lib/parsetools/src/yeccparser.erl index 7cadb0a68d..aaa2772fce 100644 --- a/lib/parsetools/src/yeccparser.erl +++ b/lib/parsetools/src/yeccparser.erl @@ -58,8 +58,8 @@ format_error(Message) -> io_lib:write(Message) end. -% To be used in grammar files to throw an error message to the parser -% toplevel. Doesn't have to be exported! +%% To be used in grammar files to throw an error message to the parser +%% toplevel. Doesn't have to be exported! -compile({nowarn_unused_function,{return_error,2}}). -spec return_error(integer(), any()) -> no_return(). return_error(Line, Message) -> -- cgit v1.2.3 From c12397f937d450d885ca6ec44d53ef34ff8788f4 Mon Sep 17 00:00:00 2001 From: Kostis Sagonas Date: Fri, 12 Feb 2010 19:00:37 +0100 Subject: parsetools: Don't use 'try...of' when 'try' will do --- lib/parsetools/src/yecc.erl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/parsetools') diff --git a/lib/parsetools/src/yecc.erl b/lib/parsetools/src/yecc.erl index 1f1fa96e61..9c164c00a4 100644 --- a/lib/parsetools/src/yecc.erl +++ b/lib/parsetools/src/yecc.erl @@ -348,8 +348,7 @@ atom_option(verbose) -> {verbose, true}; atom_option(Key) -> Key. is_filename(T) -> - try filename:flatten(T) of - Filename -> Filename + try filename:flatten(T) catch error: _ -> no end. -- cgit v1.2.3