Browse Source

Add help tab to regex_gadget

tags/v0.1.0^2
Garrick Aden-Buie 8 years ago
parent
commit
039729a8a7
7 changed files with 225 additions and 2 deletions
  1. +1
    -0
      DESCRIPTION
  2. +1
    -0
      NAMESPACE
  3. +113
    -1
      R/regex_gadget.R
  4. BIN
      R/sysdata.rda
  5. +1
    -1
      R/utils.R
  6. +66
    -0
      data-raw/cheatsheet.R
  7. +43
    -0
      inst/gadget.css

+ 1
- 0
DESCRIPTION View File

@@ -16,6 +16,7 @@ Imports:
purrr,
dplyr,
rmarkdown,
knitr,
utils,
tidyr,
rstudioapi,

+ 1
- 0
NAMESPACE View File

@@ -9,5 +9,6 @@ importFrom(dplyr,"%>%")
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(dplyr,summarize)
importFrom(utils,getFromNamespace)

+ 113
- 1
R/regex_gadget.R View File

@@ -41,6 +41,7 @@ regex_gadget <- function(text = NULL) {

ui <- miniPage(
shiny::includeCSS(system.file("style.css", package = "regexplain")),
shiny::includeCSS(system.file("gadget.css", package = "regexplain")),
gadgetTitleBar(
"regexplain",
right = miniTitleBarButton("done", "Send Regex To Console", TRUE)
@@ -115,7 +116,36 @@ regex_gadget <- function(text = NULL) {
miniTabPanel(
"Help", icon = icon("support"),
miniContentPanel(
tags$p("Help will go here.")
fillRow(
flex = c(1, 4),
tagList(
# selectInput("help_category", "Category", c("", unique(cheatsheet$category))),
# uiOutput("help_group"),
tags$ul(
id = "help-sidebar",
tags$li("Character Classes", class = "header"),
tags$ul(
class = "subgroup",
tags$li(actionLink("help_cat_character_classes_regular", "Regular")),
tags$li(actionLink("help_cat_character_classes_prebuilt", "Pre-Built"))
),
tags$li(actionLink("help_cat_anchors", "Anchors")),
tags$li("Escaped Characters", class = "header"),
tags$ul(
class = "subgroup",
tags$li(actionLink("help_cat_escaped_general", "General")),
tags$li(actionLink("help_cat_escaped_hex", "Hex")),
tags$li(actionLink("help_cat_escaped_control", "Control Characters"))
),
tags$li(actionLink("help_cat_groups", "Groups")),
tags$li(actionLink("help_cat_quantifiers", "Quantifiers"))
)
),
tags$div(
style = "width: 100%; padding-left: 10px;",
uiOutput('help_text_selected')
)
)
)
)
)
@@ -180,6 +210,88 @@ regex_gadget <- function(text = NULL) {
print(x)
})

# output$help_group <- renderUI({
# req(input$help_category)
# groups <- unique(cheatsheet[cheatsheet$category == input$help_category, ]$group)
# if (is.na(groups[1])) {
# NULL
# } else {
# selectInput("help_group", "Group", groups)
# }
# })

# ---- Help Section ---- #
help_text <- reactiveVal("<p>Select a category from the left sidebar.</p>")

output$help_text_selected <- renderUI({
HTML(help_text())
})

make_html_table <- function(x) {
select(x, .data$regexp, .data$text) %>%
knitr::kable(
col.names = c("Regexp", "Text"),
escape = FALSE,
format = "html")
}

observeEvent(input$help_cat_character_classes_regular, {
cheatsheet %>%
filter(category == "character classes", group == "regular") %>%
make_html_table %>%
help_text
})

observeEvent(input$help_cat_character_classes_prebuilt, {
cheatsheet %>%
filter(category == "character classes", group == "pre-built") %>%
make_html_table %>%
help_text
})

observeEvent(input$help_cat_anchors, {
cheatsheet %>%
filter(category == "anchors") %>%
make_html_table %>%
help_text
})

observeEvent(input$help_cat_escaped_general, {
cheatsheet %>%
filter(category == "escaped characters", group == "general") %>%
make_html_table %>%
help_text
})

observeEvent(input$help_cat_escaped_hex, {
cheatsheet %>%
filter(category == "escaped characters", group == "hex") %>%
make_html_table %>%
help_text
})

observeEvent(input$help_cat_escaped_control, {
cheatsheet %>%
filter(category == "escaped characters", group == "control characters") %>%
make_html_table %>%
help_text
})

observeEvent(input$help_cat_groups, {
cheatsheet %>%
filter(category == "groups") %>%
make_html_table %>%
help_text
})

observeEvent(input$help_cat_quantifiers, {
cheatsheet %>%
filter(category == "quantifiers") %>%
make_html_table %>%
help_text
})


observeEvent(input$done, {
# browser()
if (input$pattern != "") {

BIN
R/sysdata.rda View File


+ 1
- 1
R/utils.R View File

@@ -1,4 +1,4 @@
#' @importFrom dplyr "%>%" mutate filter group_by summarize
#' @importFrom dplyr "%>%" mutate filter group_by summarize select
#' @importFrom utils getFromNamespace
NULL


+ 66
- 0
data-raw/cheatsheet.R View File

@@ -0,0 +1,66 @@
cheatsheet <- tibble::tribble(
~category, ~group, ~regexp, ~text,
"character classes", "regular", "<code>.</code>", "any character except newline",
"character classes", "regular", "<code>\\w</code> <code>\\d</code> <code>\\s</code>", "word, digit, whitespace",
"character classes", "regular", "<code>\\W</code> <code>\\D</code> <code>\\S</code>", "not word, digit, whitespace",
"character classes", "regular", "<code>\\p{property name}</code>", "matches character with unicode property, like <code>\\p{Uppercase}</code>, see <a href=\"http://www.unicode.org/reports/tr44/#Property_Index.\">unicode property list</a>.",
"character classes", "regular", "<code>[abc]</code>", "any of a, b or c",
"character classes", "regular", "<code>[^abc]</code>", "not a, b, or c",
"character classes", "regular", "<code>[a-g]</code> <code>[1-3]</code>", "character between a & g or 1 & 3",
"character classes", "regular", "<code>[\\^\\-]</code>", "matches <code>-</code> or <code>\\</code>",
"character classes", "pre-built", "Used inside <code>[]</code>", "Example <code>[[:digit:]AX]</code> matches all digits and A and X",
"character classes", "pre-built", "<code>[:punct:]</code>", "punctuation",
"character classes", "pre-built", "<code>[:alpha:]</code>", "letters",
"character classes", "pre-built", "<code>[:lower:]</code>", "lowercase letters",
"character classes", "pre-built", "<code>[:upper:]</code>", "uppercase letters",
"character classes", "pre-built", "<code>[:digit:]</code>", "digits",
"character classes", "pre-built", "<code>[:xdigit:]</code>", "hex digits",
"character classes", "pre-built", "<code>[:alnum:]</code>", "letters and numbers",
"character classes", "pre-built", "<code>[:cntrl:]</code>", "control characters",
"character classes", "pre-built", "<code>[:graph:]</code>", "letters, numbers, and punctuation",
"character classes", "pre-built", "<code>[:print:]</code>", "letters, numbers, punctuation, and whitespace",
"character classes", "pre-built", "<code>[:space:]</code>", "space characters (basically equivalent to <code>\\s</code>)",
"character classes", "pre-built", "<code>[:blank:]</code>", "space and tab",
"anchors", NA, "<code>^</code>", "start of string",
"anchors", NA, "<code>$</code>", "end of string",
"anchors", NA, "<code>\\b</code>", "word boundary",
"anchors", NA, "<code>\\B</code>", "not-word boundary",
"anchors", NA, "<code>\\A</code>", "stringr multiline: match start of the input",
"anchors", NA, "<code>\\z</code>", "stringr multiline: match end of the input",
"anchors", NA, "<code>\\Z</code>", "stringr multiline: match end of the input, but before final line terminator (if it exists)",
"escaped characters", "general", "<code>\\.</code>", "dot",
"escaped characters", "general", "<code>\\*</code>", "asterisk",
"escaped characters", "general", "<code>\\\\</code>", "backslash",
"escaped characters", "general", "<code>\\t</code>", "tab",
"escaped characters", "general", "<code>\\n</code>", "linefeed",
"escaped characters", "general", "<code>\\r</code>", "carriage return",
"escaped characters", "hex", "<code>\\xhh</code>", "2 hex digits",
"escaped characters", "hex", "<code>\\x{hhhh}</code>", "1-6 hex digits",
"escaped characters", "hex", "<code>\\uhhhh</code>", "4 hex digitis",
"escaped characters", "hex", "<code>\\Uhhhhhhhh</code>", "8 hex digits",
"escaped characters", "hex", "<code>\\N{name}</code>", "Name of unicode character, e.g. <code>\\N{grinning face}</code>",
"escaped characters", "control characters", "<code>\\a</code>", "bell",
"escaped characters", "control characters", "<code>\\cX</code>", "match a control-X character",
"escaped characters", "control characters", "<code>\\e</code>", "escape (<code>\\u001B</code>)",
"escaped characters", "control characters", "<code>\\f</code>", "form feed (<code>\\u000C</code>)",
"escaped characters", "control characters", "<code>\\0ooo</code>", "octal character where \"ooo\" is 1-3 octal digits",
"groups", NA, "<code>(abc)</code>", "capture group",
"groups", NA, "<code>\\<N></code>", "backreference to group #N, e.g. <code>\\1</code>",
"groups", NA, "<code>(?:abc)</code>", "non-capturing group, e.g. <code>\"gr(?:e|a)y\")</code>",
"groups", NA, "<code>(?=abc)</code>", "postive lookahead; matches are followed by <code>abc</code> (non-capturing)",
"groups", NA, "<code>(?!abc)</code>", "negative lookahead; matches are not followed by <code>abc</code> (non-capturing)",
"groups", NA, "<code>(?<=abc)</code>", "positive lookbehind; matches are preceeded by <code>abc</code> (non-capturing)",
"groups", NA, "<code>(?<!abc)</code>", "negative lookbehind; matches are not preceeded by <code>abc</code> (non-capturing)",
"groups", NA, "<code>(?>abc)</code>", "atomic-match; no back-tracking if later matches fail",
"quantifiers", NA, "<code>a*</code>", "0 or more",
"quantifiers", NA, "<code>a+</code>", "1 or more",
"quantifiers", NA, "<code>a?</code>", "0 or 1",
"quantifiers", NA, "<code>a{n}</code>", "exactly n times",
"quantifiers", NA, "<code>a{n,}</code>", "n or more times",
"quantifiers", NA, "<code>a{n,m}</code>", "n-m times",
"quantifiers", NA, "add <code>+</code>", "makes match possessive",
"quantifiers", NA, "add <code>?</code>", "makes match non-greedy",
"quantifiers", NA, "<code>ab|cd</code>", "match ab or cd",
"quantifiers", NA, "<code>w(?:o|a)ke</code>", "use non-capturing group for precedence"
)


+ 43
- 0
inst/gadget.css View File

@@ -0,0 +1,43 @@
th,
td {
padding: 10px 13px;
text-align: left;
border-bottom: 1px solid #E1E1E1; }
th:first-child,
td:first-child {
padding-left: 0; }
th:last-child,
td:last-child {
padding-right: 0; }

#help-sidebar {
padding-top: 5px;
padding-left: 10px;
}
#help-sidebar ul {
list-style-type: none;
font-size: 1.1em;
}
#help-sidebar li {
list-style: none;
}
#help-sidebar .header li {
padding: 3px;
}
#help-sidebar a {
display: block;
width: 100%;
text-decoration: none;
text-align: left;
padding: 3px;
}
#help-sidebar .subgroup {
padding-left: 0px;
}
#help-sidebar .subgroup a {
padding-left: 15px;
}
#help-sidebar a:hover {
background-color: #eee;
text-decoration: none;
}

Loading…
Cancel
Save