add readall, readall test
This commit is contained in:
parent
be6ebfceb6
commit
6d1211c2fd
|
@ -1,2 +1,2 @@
|
|||
bin/*
|
||||
*.html
|
||||
./*.html
|
|
@ -10,7 +10,7 @@
|
|||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "main.go",
|
||||
"args": ["examples/http_hello_world.vqe"]
|
||||
"args": ["examples/http_read.vqe"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"examples/test.html" readall disp
|
||||
} ":3333" servehttp
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>test</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
|
@ -1243,18 +1244,32 @@ func Interpret(code Expr, argv []string, w io.Writer) error {
|
|||
}
|
||||
|
||||
http.ListenAndServe(str.Value.(string), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
req := make([]string, 0)
|
||||
req = append(req, r.RequestURI)
|
||||
fun, e := pop()
|
||||
if e != nil {
|
||||
return
|
||||
}
|
||||
if fun.Tok == FUNCTION {
|
||||
Interpret(fun, nil, w)
|
||||
Interpret(fun, req, w)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}))
|
||||
case READALL:
|
||||
str, e := pop()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if str.Tok != STRING {
|
||||
return fmt.Errorf("cannot `servehttp` exptected a string for the port @%v", idx)
|
||||
}
|
||||
|
||||
filedata, err := ioutil.ReadFile(str.Value.(string)) // the file is inside the local directory
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
push(Expr{STRING, nil, string(filedata), 0})
|
||||
case VERSION:
|
||||
fmt.Fprintf(w, "var'aq -- 0.9.1 Martoq")
|
||||
case ARGV:
|
||||
|
|
|
@ -182,6 +182,7 @@ var keywords = map[string]TokenType{
|
|||
"depth": DEPTH,
|
||||
"juv": DEPTH,
|
||||
"servehttp": SERVEHTTP,
|
||||
"readall": READALL,
|
||||
}
|
||||
|
||||
func isDigit(s string) bool {
|
||||
|
|
|
@ -106,6 +106,7 @@ const (
|
|||
ROT
|
||||
DEPTH
|
||||
SERVEHTTP
|
||||
READALL
|
||||
)
|
||||
|
||||
var tokens = [...]string{
|
||||
|
@ -211,6 +212,7 @@ var tokens = [...]string{
|
|||
ROT: "ROT",
|
||||
DEPTH: "DEPTH",
|
||||
SERVEHTTP: "SERVEHTTP",
|
||||
READALL: "READALL",
|
||||
}
|
||||
|
||||
func (me TokenType) String() string {
|
||||
|
|
Loading…
Reference in New Issue