Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding Calculator service to the new architecture.

  • Loading branch information...
commit 84867c5a1eb8edce440a35820414922867b9cb49 1 parent 02c0ce0
@akoprow akoprow authored
View
3  Makefile
@@ -1,6 +1,7 @@
NAME = webshell.exe
-SRC = service.opa parser.opa editor.opa webshell.opa login.opa facebook.opa search.opa dropbox.opa config.opa
+SRC = service.opa editor.opa config.opa login.opa webshell.opa \
+ calc.opa facebook.opa search.opa dropbox.opa
SRCS = $(SRC:%=src/%)
all: $(NAME)
View
42 src/calc.opa
@@ -0,0 +1,42 @@
+// license: AGPL
+// (c) MLstate, 2011, 2012
+// author: Adam Koprowski, Henri Binsztok
+
+module Calc {
+
+ function ws(p) {
+ 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
+ }
+
+ Service.spec spec =
+ { initial_state: void,
+ function parse_cmd(_) {
+ parser {
+ case ~expr : { response: <>= {expr}</>, new_state: void }
+ }
+ }
+ }
+
+}
+
+
View
65 src/parser.opa
@@ -1,65 +0,0 @@
-// license: AGPL
-// (c) MLstate, 2011, 2012
-// author: Adam Koprowski, Henri Binsztok
-
-client module Calc {
-
- function int_of_string(string str) {
- (option(int)) Parser.try_parse(Rule.integer, str);
- }
-
- function nat_of_string(string str) {
- (option(int)) Parser.try_parse(Rule.natural, str);
- }
-
- function ws(p) {
- 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)) {
- case {some: result}: "{result}";
- case {none}: "unknown";
- }
- }
-}
View
33 src/search.opa
@@ -14,6 +14,37 @@ type search_params = {
database string /blekko_auth_key
+module SearchParser {
+
+ function int_of_string(string str) {
+ (option(int)) Parser.try_parse(Rule.integer, str);
+ }
+
+ function nat_of_string(string str) {
+ (option(int)) Parser.try_parse(Rule.natural, str);
+ }
+
+ search = Calc.ws(parser { case "search" : void })
+ set = Calc.ws(parser { case "set" : void })
+ next = Calc.ws(parser { case "next" : void })
+ prev = Calc.ws(parser { case "prev" : void })
+ page = Calc.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={Calc.ws(Rule.natural)} : { ~pagenum }
+ case command={Calc.ws(Rule.ident)} arg={Calc.ws(Rule.ident)} : { ~command, ~arg }
+ }
+
+}
+
module Search {
auth =
@@ -117,7 +148,7 @@ Please re-run your application with: --blekko-config option")
match (args) {
case ["auth",auth]: set_auth({some:auth}); <>set auth to {auth}</>
case ["ps",ps]:
- match (Calc.nat_of_string(ps)) {
+ match (SearchParser.nat_of_string(ps)) {
case {some:ps}:
set_ps({some:ps}); <>set ps to {ps}</>
case {none}: <>set ps &lt;int&gt;</>
View
4 src/service.opa
@@ -41,13 +41,13 @@ server module Service {
// implementation of a system (consisting of a bunch of services)
abstract type System.t = list(Service.t)
-server module System {
+server module Shell {
function System.t build(list(Service.t) services) {
services
}
- function xhtml process(System.t sys, string cmd) {
+ function xhtml execute(System.t sys, string cmd) {
recursive function aux(services) {
match (services) {
case []:
View
13 src/webshell.opa
@@ -8,6 +8,11 @@ import stdlib.widgets.bootstrap
WB = WBootstrap
+shell =
+ Shell.build(
+ [ Service.make(Calc.spec) ]
+ )
+
function focus(set) {
Log.warning("focus", set);
#status = "Focus: {set}";
@@ -33,6 +38,7 @@ function loop(ua)(_) {
LineEditor.init(ua, #editor, readevalwrite(_), true);
}
+/*
function answer(expr) {
(xhtml) match (Parser.try_parse(Calc.shell, expr)) {
case { none }: <>syntax error</>
@@ -45,14 +51,15 @@ function answer(expr) {
case { some: { ~pagenum } }: Search.page(pagenum)
}
}
+*/
-function readevalwrite(expr) {
+function readevalwrite(cmd) {
element =
<div>
<span>{prompt()}</span>
- <span>{expr}</span>
+ <span>{cmd}</span>
</div>
- <div>{answer(expr)}</div>;
+ <div>{Shell.execute(shell, cmd)}</div>;
update(element);
}
Please sign in to comment.
Something went wrong with that request. Please try again.