Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix parser.

  • Loading branch information...
commit 6c5005ccaccdfb408eb891bf0a0b943da65e556b 1 parent 8f2ed4b
Alok Menghrajani authored
View
5 riskybird.opa
@@ -32,6 +32,7 @@
import stdlib.themes.bootstrap
import stdlib.web.client
+import stdlib.database.db3
type regexp_result = {
string regexp,
@@ -84,7 +85,7 @@ function save_data(int id) {
true_negatives: true_negatives,
}
- int id2 = if (id == 0) { Db.fresh_key(@/regexps); } else { id; }
+ int id2 = if (id == 0) { Db3.fresh_key(@/regexps); } else { id; }
/regexps[id2] <- r
Client.goto("/{id2}")
@@ -316,7 +317,7 @@ function resource start(Uri.relative uri) {
match (uri) {
case {path:{nil} ...}:
// regexp_result data = {regexp:"", comment:"", true_positives:Map.empty, true_negatives:Map.empty}
- regexp_id = Db.fresh_key(@/regexps)
+ regexp_id = Db3.fresh_key(@/regexps)
r = Resource.raw_status({address_redirected})
Resource.add_header(r, {location:"/{regexp_id}"})
case {path:{~hd, tl:[]} ...}:
View
4 riskybird_lint.opa
@@ -82,10 +82,10 @@ module Checker {
function lstatus regexp(regexp re) {
lstatus = {ok}
- core_regexp(lstatus, re.core)
+ core_regexp(lstatus, re)
}
- function lstatus core_regexp(lstatus st, core_regexp re) {
+ function lstatus core_regexp(lstatus st, regexp re) {
List.fold_left(simple, st, re)
}
View
39 riskybird_parser.opa
@@ -1,9 +1,4 @@
-type regexp =
- { bool start_anchor,
- core_regexp core,
- bool end_anchor }
-
-and core_regexp = list(simple)
+type regexp = list(simple)
and simple = list(basic)
@@ -17,15 +12,17 @@ and postfix =
{ plus } or
{ int exact } or
{ int at_least } or
- { int min, int max }
+ { int min, int max }
and elementary =
{ qmark } or
{ edot } or
{ string echar } or
{ string escaped_char } or
- { core_regexp egroup } or
- { rset eset }
+ { regexp egroup } or
+ { rset eset } or
+ { start_anchor } or
+ { end_anchor }
and rset =
{ bool neg, list(item) items }
@@ -40,13 +37,7 @@ and range =
module RegexpParser {
- function core_regexp coerce(core_regexp x) { x }
-
- regexp = parser
- | "^" x = {core_regexp} "$" -> { start_anchor: true, core: x, end_anchor: true }
- | "^" x = {core_regexp} -> { start_anchor: true, core: x, end_anchor: false }
- | x = {core_regexp} "$" -> { start_anchor: false, core: x, end_anchor: true }
- | x = { core_regexp } -> { start_anchor: false, core: x, end_anchor: false }
+ function regexp coerce(regexp x) { x }
/* Ok this is ugly as hell!!!
* I am forced into this nightmare because of erling, first thing he tried was
@@ -55,15 +46,15 @@ module RegexpParser {
* of the parser costing too much ... eventhough, I didn't look, so don't really know.
* However, I can avoid backtracking with this ugly piece of code ... and solve the
* problem. Damn you erling!
-*/
- core_regexp = parser
+ */
+ regexp = parser
| ")" -> [[]]
| Rule.eos -> [[]]
- | "|" ~core_regexp -> List.cons([], core_regexp)
- | ~basic ~core_regexp ->
- match(core_regexp) {
+ | "|" ~regexp -> List.cons([], regexp)
+ | ~basic ~regexp ->
+ match(regexp) {
case {nil}: nil /* never triggered */
- case { ~hd, ~tl }:
+ case { ~hd, ~tl }:
{ hd: List.cons(basic, hd), tl: tl }
}
@@ -85,7 +76,7 @@ module RegexpParser {
elementary = parser
| "?" -> { qmark }
| "." -> { edot }
- | "(" ~core_regexp -> { egroup: coerce(core_regexp) }
+ | "(" ~regexp -> { egroup: coerce(regexp) }
| "[^" ~items "]" -> { eset: { neg: true, ~items } }
| "[" ~items "]" -> { eset: { neg:false, ~items } }
| "\\" x = { any_char } -> { escaped_char: x}
@@ -129,7 +120,7 @@ module RegexpParser {
| x = "`" -> x
| x = "_" -> x
| x = "=" -> x
-
+
items = parser
| ~item ~items -> List.cons(item, items)
| ~item -> [item]
View
11 riskybird_string_printer.opa
@@ -7,14 +7,11 @@ module RegexpStringPrinter {
match (parsed_regexp) {
case {none}:
""
- case {some: x}:
- start_anchor = if (x.start_anchor) { "^" } else { "" }
- end_anchor = if (x.end_anchor) { "$" } else { "" }
- "{start_anchor}{print_simple_list(x.core)}{end_anchor}"
+ case {some: x}: print_simple_list(x)
}
}
- function string print_simple_list(core_regexp regexp) {
+ function string print_simple_list(regexp regexp) {
String.concat("|", List.map(print_basic_list, regexp))
}
@@ -40,6 +37,8 @@ module RegexpStringPrinter {
case {escaped_char:x}: "\\{x}"
case {~egroup}: "({print_simple_list(egroup)})"
case {~eset}: "{print_set(eset)}"
+ case {start_anchor}: "^"
+ case {end_anchor}: "$"
}
}
@@ -70,7 +69,7 @@ module RegexpStringPrinter {
case {plus}: "+"
case {exact: x}: "\{{x}\}"
case {at_least: x}: "\{{x},\}"
- case {~min, ~max}: "\{{min},{max}\}"
+ case {~min, ~max}: "\{{min},{max}\}"
}
}
}
View
10 riskybird_xhtml_printer.opa
@@ -8,13 +8,9 @@ module RegexpXhtmlPrinter {
</div>
</>
case {some: x}:
- start_anchor = if (x.start_anchor) { "^" } else { "…" }
- end_anchor = if (x.end_anchor) { "$" } else { "…" }
<>
<div class="pp">
- <span class="noborder pretty_print">{start_anchor}</span>
- {print_simple_list(x.core)}
- <span class="noborder pretty_print">{end_anchor}</span>
+ {print_simple_list(x)}
</div>
<br style="clear: both"/>
<div>{Debug.dump(parsed_regexp)}</div>
@@ -30,7 +26,7 @@ module RegexpXhtmlPrinter {
}
}
- function xhtml print_simple_list(core_regexp regexp) {
+ function xhtml print_simple_list(regexp regexp) {
t = List.map(
print_basic_list,
regexp)
@@ -71,6 +67,8 @@ module RegexpXhtmlPrinter {
<span class="mylabel"><span>group N</span></span>{print_simple_list(egroup)}
</span>
case {~eset}: <>{print_set(eset)}</>
+ case {start_anchor}: <>^</>
+ case {end_anchor}: <>$</>
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.