Permalink
Browse files

improve character range lint check

  • Loading branch information...
Alok Menghrajani
Alok Menghrajani committed May 8, 2012
1 parent 919ba4a commit 929e862f4e245b0bcc31d324c9e8c7f747f0cd45
Showing with 19 additions and 9 deletions.
  1. +14 −6 TODO
  2. +4 −3 riskybird_lint.opa
  3. +1 −0 riskybird_unittest.opa
View
20 TODO
@@ -1,6 +1,14 @@
-Todo:
-- clean up character sets:
- - overlapping ranges "[a-mb-n]", "[a-zb-y]"
- - duplicate entires "[aa]"
- - reduce ranges "[ab-cc-d]" to "[a-d]"
-- support various regexp flavors (js, php, etc.)
+Improve UI
+
+Explain what we are doing
+
+Handle differences between various regexp implementations (e.g. php vs javascript)
+
+Make sure parser is complete
+
+More lint rules:
+
+- x*x => x+
+- x*x* => x*
+- xx* => x+
+- crazy things like \c vs \i
View
@@ -146,12 +146,13 @@ module RegexpLinterHelper {
map = List.fold(set_to_charmap, set.items, IntMap.empty)
new_set = {set with items: List.rev(charmap_to_set(map, []))}
- if (List.length(new_set.items) < List.length(set.items)) {
- s = RegexpStringPrinter.print_set(new_set)
+ s1 = RegexpStringPrinter.print_set(new_set)
+ s2 = RegexpStringPrinter.print_set(set)
+ if (String.length(s1) < String.length(s2)) {
err = {
lint_rule: 9,
title: "non optimal character range",
- body: "better(?) way to write this: {s}"
+ body: "shorter way to write {s2}: {s1}"
}
RegexpLinter.add(res, err)
} else {
View
@@ -82,6 +82,7 @@ expect_lint_error("included ranges", "[a-md-g]", 9)
expect_lint_error("character from range", "[a-zx]", 9)
expect_lint_error("duplicate character", "[xabcx]", 9)
expect_lint_error("contiguous ranges", "[a-cde-f]", 9)
+expect_lint_error("repeated ranges", "[a-ca-c]", 9)
expect_lint_error("complex overlapping", "[fg-ia-ec-j]", 9)
expect_lint_error("complex inclusion", "[fg-ia-ec-h]", 9)

0 comments on commit 929e862

Please sign in to comment.