Permalink
Browse files

Add www-all.g to load all www demos.

  • Loading branch information...
birchb1024 committed Nov 11, 2017
1 parent d0ce764 commit 418efbe80870d42699f50dafd9f328d61e64df0f
@@ -8,31 +8,37 @@ def myparse (string)
.read
df httpd-serve (request)
print request
var params (request(.getParameters))
define expression-string (params (.lookup "expression"))
define expression (myparse expression-string)
define result nil
catch eval-errors
setq result (context(eval expression))
cond
eval-errors
setq result (list '*** ERROR: ' eval-errors)
list 200 "text/html"
template
html()
head()
title() "Genyris Inspector"
body()
form((action="/"))
input((type="hidden")(name="expression")(value="(include 'examples/apps/inspector/inspect.g')"))
input((type="submit")(value="reload"))
pre() $("%s"(.format expression))
verbatim() '<hr>'
pre() $("%s"(.format result))
verbatim() '<hr>'
form((action="/"))
input((type="textarea")(name="expression")(length="32"))
input((type="submit")(value="Eval"))
cond
(equal? (request(.getPath)) '/favicon.ico')
list 404 "text/plain" ^("Not Found")
else
define expression nil
define expression-string ''
define result nil
var params (request(.getParameters))
catch eval-errors
setq expression-string (params (.lookup "expression"))
setq expression (myparse expression-string)
setq result (context(eval expression))
cond
eval-errors
setq result (list '*** ERROR: ' eval-errors)
list 200 "text/html"
template
html()
head()
title() "Genyris Inspector"
body()
form((action="/"))
input((type="hidden")(name="expression")(value="(include 'examples/apps/inspector/inspect.g')"))
input((type="submit")(value="reload"))
pre() $("%s"(.format expression))
verbatim() '<hr>'
pre() $("%s"(.format result))
verbatim() '<hr>'
form((action="/"))
input((type="textarea")(name="expression")(length="32"))
input((type="submit")(value="Eval"))
@@ -0,0 +1,102 @@
@prefix u "http://www.genyris.org/lang/utilities#"
@prefix ver "http://www.genyris.org/lang/version#"
@prefix sys "http://www.genyris.org/lang/system#"
@prefix java 'http://www.genyris.org/lang/java#'
@prefix : "http://www.genyris.org/lang/types#"
@prefix foaf 'http://xmlns.com/foaf/0.1/'
include "lib/types.g"
include "lib/classify.g"
def classify-from-list(obj list-of-classes)
for klass in
def read-classify-eval-print-loop(root-classes)
define looping true
define parser (IndentedParser(.new stdin true))
parser
.prefix ^sys "http://www.genyris.org/lang/system#"
.prefix ^u "http://www.genyris.org/lang/utilities#"
.prefix ^java 'http://www.genyris.org/lang/java#'
.prefix ^foaf 'http://xmlns.com/foaf/0.1/'
while looping
u:format '\n> '
define bt nil
define result nil
catch (errors bt)
define expression (parser (.read))
cond
(equal? expression EOF)
print 'Bye!'
setq looping nil
else
map-left root-classes
lambda (klass)
classify klass (left expression)
#sys:print-classnames expression
setq result (eval expression)
map-left root-classes
lambda (klass)
classify klass result
u:format '%s # ' result
sys:print-classnames result
cond
errors
u:format "*** Error - %s\n" errors
sys:printBackTrace bt
setq bt nil
Bignum
def .new(obj)
define parser (ParenParser(.new obj))
parser(.read)
class DemoString(String)
def .valid? (obj)
is-instance? obj String
class DemoURL(DemoString)
def .valid? (obj)
obj(.regex 'http://[^/]+/.*')
def >< (min max x)
# Number x value between min and max.
and
> x min
< x max
class DemoDate(DemoString)
define separator '/'
def .valid? (obj)
and
obj(.regex '[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]')
> (obj(DemoDate!year)) 0
>< 0 13 (obj(DemoDate!month))
>< 0 32 (obj(DemoDate!day))
def partAsNumber(this index)
Bignum!new
nth index (this(.split separator))
def .year()
partAsNumber .self 2
def .month()
partAsNumber .self 1
def .day()
partAsNumber .self 0
def classifyNreturn (klass obj)
classify klass obj
the obj
assert (not (DemoURL!valid? "32"))
assert (DemoURL!valid? 'http://www.genyris.org/lang/java#')
assert
is-instance? (classifyNreturn DemoString 'foo') DemoString
assert
is-instance? (classifyNreturn DemoString 'http://www.genyris.org/lang/java#') DemoURL
read-classify-eval-print-loop (list :Record :SequenceOfRecords DemoString)
@@ -11,17 +11,18 @@ java:import 'javax.swing.ListSelectionModel' as ListSelectionModel
java:import 'javax.swing.DefaultListSelectionModel' as DefaultListSelectionModel
def getValueAt(row col)
print ("getValueAt: row %s col %s"(.format row col))
* (+ row 1) (+ col 1)
def getColumnCount() 12
def getRowCount() 12
def setValueAt(row col value)
print value
print ("setValueAt: row %s col %s value = %s"(.format row col value))
def callback(&rest args)
print args
print ("callback: %s"(.format args))
def createAndShowGUI()
@@ -7,13 +7,20 @@
##
@prefix sys "http://www.genyris.org/lang/system#"
@prefix u "http://www.genyris.org/lang/utilities#"
print sys:argv
cond
(not (equal? (length sys:argv) 3))
raise "Usage: web-server.g <port> <root directory>"
@prefix task "http://www.genyris.org/lang/task#"
define number-threads 10
var port (nth 1 sys:argv)
var port (parse (nth 1 sys:argv))
var rootdir (nth 2 sys:argv)
u:format "Serving web pages on port %a from %a%n" port rootdir
httpd port 'test/mocks/www-static.g' rootdir
df httpd-serve (request)
list ^SERVE-FILE rootdir (request(.getPath)) ^ls
cond
(equal? (task:id)!name 'main')
for _ in (range 1 number-threads)
httpd port @FILE (nth 1 sys:argv) rootdir
u:format "Serving web pages on port %a from %a\n" port rootdir
read
@@ -0,0 +1,53 @@
@prefix sys "http://www.genyris.org/lang/system#"
@prefix task "http://www.genyris.org/lang/task#"
@prefix u "http://www.genyris.org/lang/utilities#"
df httpd-serve (request)
# print request
cond
(equal? (request(.getPath)) '/favicon.ico')
list 404 "text/plain" ^("Not Found")
else
list 200 "text/html"
template
html()
head()
body()
div()
"username: foo"
div()
"password: bar"
ul()
$(web-tasks)
def web-tasks()
map-left (task:ps)
lambda (x)
template
li()
a
(href = $("http://127.0.0.1:%a/"(.format (must-split x!name 1))))
$(must-split x!name 2)
def must-split (item index)
var splitted (item(.split))
cond
(> (length splitted) index)
nth index splitted
else
''
cond
(equal? (task:id)!name 'main')
httpd 8000 @FILE
httpd 8001 'examples/www-demo.g'
httpd 8002 'examples/www-basic-auth.g'
httpd 8003 'examples/www-hello.g'
httpd 8004 'examples/www-ntlm.g'
httpd 8005 'examples/www-rcepl.g'
httpd 8006 'examples/www-static.g'
httpd 8007 'examples/web-server.g' '8007' 'examples'
httpd 8008 'examples/apps/inspector/inspect.g'
u:format "Server listening on http://127.0.0.1:8000/\nType Ctrl-C to halt."
read
@@ -70,7 +70,7 @@ def login(request)
# web:get 'http://localhost/' (list (cons 'authorization' ('Basic %a' (.format ('foo:bar'(.toBase64))))))
#
cond
(and sys:argv (equal? (task:id)!name 'main'))
httpd 8000 sys:argv!left
(equal? (task:id)!name 'main')
httpd 8000 @FILE
u:format "Server listening on http://127.0.0.1:8000/\nType Ctrl-C to halt."
read
@@ -2,48 +2,58 @@
@prefix task "http://www.genyris.org/lang/task#"
@prefix u "http://www.genyris.org/lang/utilities#"
define script
(File(.new @FILE))
.abs-path
define counter 0
df httpd-serve (request)
setq counter (+ counter 1)
print request
list 200 "text/html"
template
html()
head()
title() $sys:argv
style()
verbatim() "table, th, td { border: 1px solid black; border-collapse: collapse; }"
body()
div()
"Hit number: " $counter
div()
$(request (.toHTML))
div()
a((href="/")) "GET link"
" "
a((href="/geted?variable=value&another=42")) "GET link with arguments"
div()
form((action="posted") (method="post"))
fieldset()
legend()
"POST Form:"
"Text: "
input((type="text")(name="Text")(value='text here'))
"Password: "
input((type="password")(name="password")(value='secret'))
br()
"Checked: "
input((type="checkbox")(name="checkbox") (value="Checked"))
input((type="radio")(name="radio") (value="yes") (checked="true"))
"Yes"
input((type="radio")(name="radio") (value="no"))
'No'
br()
input((type="submit")(name="Submit")(value="submit"))
print request
cond
(equal? (request(.getPath)) '/favicon.ico')
list 404 "text/plain" ^("Not Found")
else
setq counter (+ counter 1)
list 200 "text/html"
template
html()
head()
title() $script
style()
verbatim() "table, th, td { border: 1px solid black; border-collapse: collapse; }"
body()
dic()
'Script: ' $script
div()
"Hit number: " $counter
div()
$(request (.toHTML))
div()
a((href="/")) "GET link"
" "
a((href="/geted?variable=value&another=42")) "GET link with arguments"
div()
form((action="posted") (method="post"))
fieldset()
legend()
"POST Form:"
"Text: "
input((type="text")(name="Text")(value='text here'))
"Password: "
input((type="password")(name="password")(value='secret'))
br()
"Checked: "
input((type="checkbox")(name="checkbox") (value="Checked"))
input((type="radio")(name="radio") (value="yes") (checked="true"))
"Yes"
input((type="radio")(name="radio") (value="no"))
'No'
br()
input((type="submit")(name="Submit")(value="submit"))
cond
(and sys:argv (equal? (task:id)!name 'main'))
httpd 8000 sys:argv!left
(equal? (task:id)!name 'main')
print script
httpd 8000 script
u:format "Server listening on http://127.0.0.1:8000/\nType Ctrl-C to halt."
read
@@ -12,7 +12,7 @@ df httpd-serve (request)
h1()
"Hello World"
cond
(and sys:argv (equal? (task:id)!name 'main'))
httpd 8000 sys:argv!left
(equal? (task:id)!name 'main')
httpd 8000 @FILE
u:format "Server listening on http://127.0.0.1:8000/\nType Ctrl-C to halt."
read
@@ -148,7 +148,7 @@ df httpd-serve (request)
response
cond
(and sys:argv (equal? (task:id)!name 'main'))
httpd 8000 sys:argv!left
(equal? (task:id)!name 'main')
httpd 8000 @FILE
u:format "Server listening on http://127.0.0.1:8000/\nType Ctrl-C to halt."
read
Oops, something went wrong.

0 comments on commit 418efbe

Please sign in to comment.