[需要讨论]NetLogo语法糖

是时候给NetLogo加上多行注释、多行字符串、转义字符、原始字符串、模板字符串了
这是目前的语法糖设计:
多行注释(参考wabt)

;(;注释开始
换行开头无需分号
注释结束;);

模板字符串(参考javascript|coffeescript,允许换行和\x,\u转义字符)

let t timer
print """use #[timer - t] ms"""

在模板字符串嵌入原始字符串(在同一对括号内需要紧跟相同的字符区分嵌套层级)

print table:from-json """#(;
{
  "key":"\u6d4b\u8bd5",
  "foo":"bar"
}
;)"""

测试链接:https://maizi20.github.io/nlw/?ref=/nlw/proc/0004/
(使用parse控件更新语法糖代码为原版代码)
测试代码:

;line1
;line2

;(;mline1
mline2
mline3;);to something end

to setup
  print "\x45\o123\u6d4b\u{08bd5}\n\s"
  print """#(;
  {
    "code":"200",
    "status":200,
    "msg":"",
    "body":{
      "time":;)#[timer]#(;
    }
  }
  ;)"""
end

to startup
  setup
end

生成代码:

1 Like

NetLogo终于有语法糖了!

论坛讨论贴:[需要讨论]NetLogo语法糖
测试链接:https://maizi20.github.io/nlw/?ref=/nlw/proc/0004/

这是目前的语法糖设计:
多行注释(参考wabt)

;(;注释开始
换行开头无需分号
注释结束;);
模板字符串(参考javascript|coffeescript,允许换行和\x,\u转义字符)

let t timer
print “”“use #[timer - t] ms”“”
在模板字符串嵌入原始字符串(在同一对括号内需要紧跟相同的字符区分嵌套层级)

print table:from-json “”“#(;
{
“key”:”\u6d4b\u8bd5",
“foo”:“bar”
}
;)“”"

反引号是控制台的MD语法(防止吞换行和花括号),和NL语法糖无关

@jeremy.baker This friend wants some new grammar for NetLogo and wrote a small parser. Typescript moment close?

加上八进制,十六进制表达式?如: 010 0xff

迟点会加上更好的数字表达式,包括二进制,八进制,十进制表达式和下划线分隔
不采用js不标准的前置零八进制数字
另外我会尝试修复负零编译丢符号问题

Hey John, I’m not sure what this question is, can you elaborate on what you mean?

For the rest, these would be changes to the core NetLogo parser. We had an open issue for string interpolation. Surprisingly we had no open issues for multi-line strings or multi-line comments. I went ahead and opened them. Note that opening them doesn’t mean we will implement them, just that it’s a proposed enhancement.

Hi Jeremy,

I was refering to the fact that @maizi20 is trying to work on a custom transpiler that implements the grammar before we ever started.

That said, to maintain compatibility, maybe we could first come up with a draft grammar as a way both to support the user-lead effort and to keep our language consistent in the long run.

1 Like