[m-rev.] for review: Add times operator for liblex

Paul Bone paul at bone.id.au
Tue May 6 12:17:36 AEST 2014


On Sun, May 04, 2014 at 04:39:23PM +0200, Sebastian Godelet wrote:
> For review by anyone.
> 

Hi Sebastian,

I have some code layout feedback.  The style document is here:
http://www.mercurylang.org/development/developers/coding_standards.html

I notice most of your changes are on github.  If you want to provide a link
it can make it easier for me to apply your patch.  Thanks.


> ---
> 
> Added the times operator for regular expressions,
> such that one can express /[a-z]{10}/
> in this way: letter * 10.
> 

This paragraph can probably be wrapped.

> extras/lex/lex.m:
>     Removed unused and unsafe str_foldr function,
>     added (T * int) = regexp function.
> 
> extras/lex/samples/lex_demo.m:
>     Removed whitespace in comments,
>     added an input prompt,
>     added a lexeme for '//' using the new '*' operator.
> ---
>  extras/lex/lex.m              | 15 ++++++++-------
>  extras/lex/samples/lex_demo.m | 11 +++++++----
>  2 files changed, 15 insertions(+), 11 deletions(-)
> 
> diff --git a/extras/lex/lex.m b/extras/lex/lex.m
> index 7570e32..2c47d91 100644
> --- a/extras/lex/lex.m
> +++ b/extras/lex/lex.m
> @@ -117,6 +117,7 @@
>  :- func ?(T) = regexp <= regexp(T).  % ?(R)       = R or null
>  :- func +(T) = regexp <= regexp(T).  % +(R)       = R ++ *(R)
>  :- func range(char, char) = regexp.  % range('a', 'z') =
> any("ab...xyz") +:- func (T * int) = regexp <= regexp(T). % R * N = R
> ++ R ++ .. ++ R 
>      % Some useful single-char regexps.
>      %
> @@ -837,19 +838,19 @@ anybut(S) = R :-
>      ExcludedChars = sparse_bitset.list_to_set(string.to_char_list(S)),
>      R = re(sparse_bitset.difference(valid_unicode_chars,
> ExcludedChars)). 
> -:- func str_foldr(func(char, T) = T, string, T, int) = T.
> -
> -str_foldr(Fn, S, X, I) =
> -    ( if I < 0 then X
> -               else str_foldr(Fn, S, Fn(string.det_index(S, I), X), I
> - 1)
> -    ).
> -
>  ?(R) = (R or null).
>  
>  +(R) = (R ++ *(R)).
>  
>  range(Start, End) = re(charset(char.to_int(Start), char.to_int(End))).
>  
> +R * N = Result :-
> +    (   N < 0   -> unexpected($file, $pred, "N must be a non-negative
> number")
> +    ;   N = 0   -> Result = null
> +    ;   N = 1   -> Result = re(R)
> +    ;   Result = conc(re(R), (R * (N - 1)))
> +    ).
> +

New goals (each goal after a ->) should begin on new lines.  And lines
should be shorter than 78 charecters.

R * N = Result :-
    ( N < 0 ->
        unexpected($file, $pred, "N must be a non-negative number")
    ; N = 0 ->
        Result = null
    ; N = 1 ->
        Result = re(R)
    ;
        Result = conc(re(R), (R * (N - 1)))
    ).

I realize that the rest of this file (and possibly the library) is not
necessarily formatted correctly.  But it probably should be.

Thanks for your ongoing contributions.


-- 
Paul Bone



More information about the reviews mailing list