Example #1
0
func main() {

	qall.InitSafe(true)
	qlang.SetDumpCode(os.Getenv("QLANG_DUMPCODE"))

	libs := os.Getenv("QLANG_PATH")
	if libs == "" {
		libs = os.Getenv("HOME") + "/qlang"
	}

	if len(os.Args) > 1 {
		lang, err := qlang.New(qlang.InsertSemis)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
		lang.SetLibs(libs)
		fname := os.Args[1]
		b, err := ioutil.ReadFile(fname)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(2)
		}
		err = lang.SafeExec(b, fname)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(3)
		}
		return
	}

	qall.Copyright()

	var ret interface{}
	qlang.SetOnPop(func(v interface{}) {
		ret = v
	})

	lang, err := qlang.New(nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	lang.SetLibs(libs)

	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		line := strings.Trim(scanner.Text(), " \t\r\n")
		if line == "" {
			continue
		}
		ret = nil
		err := lang.SafeEval(line)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			continue
		}
		fmt.Printf("> %v\n\n", ret)
	}
}
Example #2
0
func main() {

	qall.InitSafe(false)
	qlang.Import("", interpreter.Exports)
	qlang.SetDumpCode(os.Getenv("QLANG_DUMPCODE"))

	libs := os.Getenv("QLANG_PATH")
	if libs == "" {
		libs = os.Getenv("HOME") + "/qlang"
	}

	lang := qlang.New()
	lang.SetLibs(libs)

	vars = lang.Context
	eql := eqlang.New(lang)

	parseFlags()
	if source == "" {
		fmt.Fprintln(os.Stderr, usage)
		return
	}

	fi, err := os.Stat(source)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(-2)
	}

	if fi.IsDir() {
		global := lang.CopyVars()
		eql.ExecuteDir(global, source, output)
	} else {
		eql.ExecuteFile(source, output)
	}
}