Skip to content

Commit

Permalink
Documentation for counting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jimhester committed Sep 30, 2014
1 parent 6d29143 commit 6b9c89b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 34 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Collate:
'escape.R'
'capture.R'
'character_class.R'
'counts.R'
'lookarounds.R'
'modifiers.R'
'or.R'
'rex.R'
'word.R'
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export(exclude_range)
export(group)
export(lazy)
export(maybe)
export(n)
export(n_times)
export(named_capture)
export(none_of)
Expand Down
39 changes: 39 additions & 0 deletions R/counts.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' @include escape.R
#' @include utils.R
NULL

# TODO: Improve documentation, put +, * here as well
#' Counts
#'
#' Functions to restrict a regex to a specific number
#' @param x A regex pattern.
#' @param n An integer number
#' @param low An integer number for the lower limit.
#' @param high An integer number for the upper limit.
#' @aliases n
#' @family rex
#' @export
n_times <- function(x, n) {
p("(?:", p(escape(x)), "){", n, "}")
}

#' @export
n <- n_times

#' @export
#' @describeIn n_times \code{x} must occur between \code{low} and \code{high} times.
between <- function(x, low, high) {
p("(?:", p(escape(x)), "){", low, ",", high, "}")
}

#' @export
#' @describeIn n_times \code{x} must occur at least \code{n} times.
at_least <- function(x, n) {
between(x, n, '')
}

#' @export
#' @describeIn n_times \code{x} must occur at most \code{n} times.
at_most <- function(x, n) {
between(x, '', n)
}
23 changes: 0 additions & 23 deletions R/word.R

This file was deleted.

11 changes: 7 additions & 4 deletions man/capture.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ Other rex: \code{\link{\%if_next_is\%}},
\code{\link{\%if_next_isnt\%}},
\code{\link{\%if_prev_is\%}},
\code{\link{\%if_prev_isnt\%}},
\code{\link{lookarounds}}; \code{\link{character_class}},
\code{\link{except}}, \code{\link{exclude_range}},
\code{\link{none_of}}, \code{\link{one_of}},
\code{\link{range}}; \code{\link{group}}
\code{\link{lookarounds}}; \code{\link{at_least}},
\code{\link{at_most}}, \code{\link{between}},
\code{\link{n}}, \code{\link{n_times}};
\code{\link{character_class}}, \code{\link{except}},
\code{\link{exclude_range}}, \code{\link{none_of}},
\code{\link{one_of}}, \code{\link{range}};
\code{\link{group}}
}

5 changes: 4 additions & 1 deletion man/character_class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Other rex: \code{\link{.}}, \code{\link{..}},
\code{\link{\%if_next_isnt\%}},
\code{\link{\%if_prev_is\%}},
\code{\link{\%if_prev_isnt\%}},
\code{\link{lookarounds}}; \code{\link{group}}
\code{\link{lookarounds}}; \code{\link{at_least}},
\code{\link{at_most}}, \code{\link{between}},
\code{\link{n}}, \code{\link{n_times}};
\code{\link{group}}
}

10 changes: 6 additions & 4 deletions man/group.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ Other rex: \code{\link{.}}, \code{\link{..}},
\code{\link{\%if_next_isnt\%}},
\code{\link{\%if_prev_is\%}},
\code{\link{\%if_prev_isnt\%}},
\code{\link{lookarounds}}; \code{\link{character_class}},
\code{\link{except}}, \code{\link{exclude_range}},
\code{\link{none_of}}, \code{\link{one_of}},
\code{\link{range}}
\code{\link{lookarounds}}; \code{\link{at_least}},
\code{\link{at_most}}, \code{\link{between}},
\code{\link{n}}, \code{\link{n_times}};
\code{\link{character_class}}, \code{\link{except}},
\code{\link{exclude_range}}, \code{\link{none_of}},
\code{\link{one_of}}, \code{\link{range}}
}

4 changes: 3 additions & 1 deletion man/lookarounds.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ Perl 5 Documentation \url{http://perldoc.perl.org/perlre.html#Extended-Patterns}

Other rex: \code{\link{.}}, \code{\link{..}},
\code{\link{capture}}, \code{\link{capture_group}},
\code{\link{named_capture}};
\code{\link{named_capture}}; \code{\link{at_least}},
\code{\link{at_most}}, \code{\link{between}},
\code{\link{n}}, \code{\link{n_times}};
\code{\link{character_class}}, \code{\link{except}},
\code{\link{exclude_range}}, \code{\link{none_of}},
\code{\link{one_of}}, \code{\link{range}};
Expand Down

0 comments on commit 6b9c89b

Please sign in to comment.