Skip to content
Browse files

Updating to new syntax (mainly change in parsers)

  • Loading branch information...
1 parent 8dd9ccb commit 40bf5a2d1b47e94b02d428ec3da862b164c3e5c7 @akoprow akoprow committed Feb 13, 2012
Showing with 72 additions and 58 deletions.
  1. +6 −4 src/config.opa
  2. +6 −4 src/dropbox.opa
  3. +6 −4 src/facebook.opa
  4. +1 −1 src/login.opa
  5. +42 −37 src/parser.opa
  6. +6 −4 src/search.opa
  7. +5 −4 src/webshell.opa
View
10 src/config.opa
@@ -15,10 +15,12 @@ module Config {
param_doc: "HOST",
description: "Sets the address of the application (needed for all redirects)",
function on_param(state) {
- parser host=(.*) ->
- {
- /host <- Text.to_string(host)
- {no_params: state}
+ parser {
+ case host=(.*) :
+ {
+ /host <- Text.to_string(host)
+ {no_params: state}
+ }
}
}
}]
View
10 src/dropbox.opa
@@ -23,10 +23,12 @@ module DropboxConnect {
param_doc: "APP_KEY,APP_SECRET",
description: "Sets the application data for the associated Dropbox application",
function on_param(state) {
- parser app_key=Rule.alphanum_string [,] app_secret=Rule.alphanum_string ->
- {
- /dropbox_config <- ~{app_key, app_secret}
- {no_params: state}
+ parser {
+ case app_key=Rule.alphanum_string [,] app_secret=Rule.alphanum_string :
+ {
+ /dropbox_config <- ~{app_key, app_secret}
+ {no_params: state}
+ }
}
}
}]
View
10 src/facebook.opa
@@ -24,10 +24,12 @@ module FacebookConnect
param_doc: "APP_ID,APP_SECRET",
description: "Sets the application ID for the associated Facebook application",
function on_param(state) {
- parser app_id=Rule.alphanum_string [,] app_secret=Rule.alphanum_string ->
- {
- /facebook_config <- {~app_id, api_key: app_id, ~app_secret};
- {no_params: state}
+ parser {
+ case app_id=Rule.alphanum_string [,] app_secret=Rule.alphanum_string:
+ {
+ /facebook_config <- {~app_id, api_key: app_id, ~app_secret};
+ {no_params: state}
+ }
}
}
}]
View
2 src/login.opa
@@ -2,7 +2,7 @@
// (c) MLstate, 2011, 2012
// author: Adam Koprowski
-@abstract type Login.user = {guest} or {FacebookConnect.user fb_user}
+abstract type Login.user = {guest} or {FacebookConnect.user fb_user}
module Login {
View
79 src/parser.opa
@@ -13,43 +13,48 @@ client module Calc {
}
function ws(p) {
- parser
- | Rule.ws res=p Rule.ws -> res
- }
-
- `(` = ws(parser | "(" -> void)
- `)` = ws(parser | ")" -> void)
-
- term = parser
- | f = {ws(Rule.float)} -> f
- | `(` ~expr `)` -> expr
-
- factor = parser
- | ~term "*" ~factor -> term * factor
- | ~term "/" ~factor -> term / factor
- | ~term -> term
-
- expr = parser
- | ~factor "+" ~expr -> factor + expr
- | ~factor "-" ~expr -> factor - expr
- | ~factor -> factor
-
- search = ws(parser | "search" -> void)
- set = ws(parser | "set" -> void)
- next = ws(parser | "next" -> void)
- prev = ws(parser | "prev" -> void)
- page = ws(parser | "page" -> void)
-
- args = parser | txt=(.*) -> List.map(String.trim,String.explode(" ",Text.to_string(txt)))
-
- shell = parser
- | search ~args -> { search:args }
- | set ~args -> { set:args }
- | next -> { next }
- | prev -> { prev }
- | page pagenum={ws(Rule.natural)} -> { ~pagenum }
- | command={ws(Rule.ident)} arg={ws(Rule.ident)} -> { ~command, ~arg }
- | ~expr -> {value: expr}
+ parser { case Rule.ws res=p Rule.ws: res }
+ }
+
+ `(` = ws(parser { case "(": void })
+ `)` = ws(parser { case ")": void })
+
+ term = parser {
+ case f = {ws(Rule.float)}: f
+ case `(` ~expr `)`: expr
+ }
+
+ factor = parser {
+ case ~term "*" ~factor : term * factor
+ case ~term "/" ~factor : term / factor
+ case ~term : term
+ }
+
+ expr = parser {
+ case ~factor "+" ~expr : factor + expr
+ case ~factor "-" ~expr : factor - expr
+ case ~factor : factor
+ }
+
+ search = ws(parser { case "search" : void })
+ set = ws(parser { case "set" : void })
+ next = ws(parser { case "next" : void })
+ prev = ws(parser { case "prev" : void })
+ page = ws(parser { case "page" : void })
+
+ args = parser {
+ case txt=(.*) : List.map(String.trim,String.explode(" ",Text.to_string(txt)))
+ }
+
+ shell = parser {
+ case search ~args : { search:args }
+ case set ~args : { set:args }
+ case next : { next }
+ case prev : { prev }
+ case page pagenum={ws(Rule.natural)} : { ~pagenum }
+ case command={ws(Rule.ident)} arg={ws(Rule.ident)} : { ~command, ~arg }
+ case ~expr : {value: expr}
+ }
function compute(s) {
match (Parser.try_parse(expr, s)) {
View
10 src/search.opa
@@ -24,10 +24,12 @@ module Search {
param_doc: "AUTH_KEY",
description: "Sets the authorization key for the Blekko application",
function on_param(state) {
- parser auth_key=Rule.alphanum_string ->
- {
- /blekko_auth_key <- auth_key
- {no_params: state}
+ parser {
+ case auth_key=Rule.alphanum_string :
+ {
+ /blekko_auth_key <- auth_key
+ {no_params: state}
+ }
}
}
}]
View
9 src/webshell.opa
@@ -115,10 +115,11 @@ function connect(connector, raw_data) {
Resource.default_redirection_page("/")
}
-dispatcher = parser
-| "/connect/facebook?" data=(.*) -> connect(FacebookConnect.login, data)
-| "/connect/dropbox?" data=(.*) -> connect(DropboxConnect.connect, data)
-| .* -> page()
+dispatcher = parser {
+ case "/connect/facebook?" data=(.*) : connect(FacebookConnect.login, data)
+ case "/connect/dropbox?" data=(.*) : connect(DropboxConnect.connect, data)
+ case .* : page()
+}
Server.start(Server.http, { custom: dispatcher })

0 comments on commit 40bf5a2

Please sign in to comment.
Something went wrong with that request. Please try again.