Magpie语法解析器

haifenghuang · · 1387 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
![magpie.png](https://static.studygolang.com/190309/bee595ae20a1263b40799b3b632cb3b0.png) ## Magpie语法解析器 Magpie是一个用`go`语言写的语法解析器,支持class, linq, sql, net, http, fmt, json等。还包含一个实时语法高亮的REPL。 ## 例子 ```csharp class Linq { static fn TestSimpleLinq() { //Prepare Data Source let ingredients = [ {Name: "Sugar", Calories: 500}, {Name: "Egg", Calories: 100}, {Name: "Milk", Calories: 150}, {Name: "Flour", Calories: 50}, {Name: "Butter", Calories: 200}, ] //Query Data Source ingredient = from i in ingredients where i.Calories >= 150 orderby i.Name select i //Display for item in ingredient => println(item) } static fn TestFileLinq() { //Read Data Source from file. file = newFile("./examples/linqSample.csv", "r") //Query Data Source result = from field in file where int(field[1]) > 300000 select field[0] //Display for item in result => printf("item = %s\n", item) file.close() } static fn TestComplexLinq() { //Data Source stringList = [ "A penny saved is a penny earned.", "The early bird catches the worm.", "The pen is mightier than the sword." ] //Query Data Source earlyBirdQuery = from sentence in stringList let words = sentence.split(" ") from word in words let w = word.lower() where w[0] == "a" || w[0] == "e" || w[0] == "i" || w[0] == "o" || w[0] == "u" select word //Display for v in earlyBirdQuery => printf("'%s' starts with a vowel\n", v) } } Linq.TestSimpleLinq() println("======================================") Linq.TestFileLinq() println("======================================") Linq.TestComplexLinq() ```

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1387 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传