V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
freestyle
V2EX  ›  Go 编程语言

wow skylark go 实现的 Python 语法的配置语言

  •  
  •   freestyle ·
    hanjm · 2017-10-04 10:43:50 +08:00 · 1261 次点击
    这是一个创建于 2609 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://github.com/google/skylark

    package main
    
    import (
    	"github.com/google/skylark"
    	"log"
    	"fmt"
    )
    
    func main() {
    	script := `print("hello {}".format("world"))
    print([i for i in range(10) if i%2==0])`
    	thread := new(skylark.Thread)
    	globals := make(skylark.StringDict)
    	err := skylark.ExecFile(thread, "", script, globals)
    	if err != nil {
    		log.Fatalf("eval error:%s", err)
    	}
    	value, err := skylark.Eval(thread, "", "range(10)", globals)
    	if err != nil {
    		log.Fatalf("eval error:%s", err)
    	}
    	fmt.Printf("%T %v", value, value)
    }
    
    
    hello world
    [0, 2, 4, 6, 8]
    *skylark.List [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]skylark.String "hello world"
    
    3 条回复    2017-10-06 10:15:49 +08:00
    freestyle
        1
    freestyle  
    OP
       2017-10-04 10:56:44 +08:00
    fix output:
    ```
    hello world
    [0, 2, 4, 6, 8]
    *skylark.List [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    ```
    naomhan
        2
    naomhan  
       2017-10-04 11:34:09 +08:00
    Skylark in Go is an interpreter for Skylark, implemented in Go.

    Skylark is a dialect of Python intended for use as a configuration language.
    janxin
        3
    janxin  
       2017-10-06 10:15:49 +08:00
    Skylark is a dialect of Python intended for use as a configuration language. Like Python, it is an untyped dynamic language with high-level data types, first-class functions with lexical scope, and garbage collection. Unlike CPython, independent Skylark threads execute in parallel, so Skylark workloads scale well on parallel machines.

    这个可以做内嵌脚本系统用了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3365 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 12:07 · PVG 20:07 · LAX 04:07 · JFK 07:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.