Skip to content

Instantly share code, notes, and snippets.

@agladysh
Last active December 29, 2015 03:59
Show Gist options
  • Save agladysh/3d9c0b6025711852f5ca to your computer and use it in GitHub Desktop.
Save agladysh/3d9c0b6025711852f5ca to your computer and use it in GitHub Desktop.
An early draft for PKLE8 syntax. Built-in internal enum
data:version "com.logiceditor.8.variables" { 0, 0, 1 }
data:root "mini"
data:type "mini" "script" ("*", "action")
data:type "script"
:scoped_store
{
}
data:type "action" "print" "string"
-- note that this specialization should be possible as well:
-- data:default "foo" "bar" "action" "print2"
default:type "action" "print"
data:type "action" "set" (1, "var-name") :validate
{
down = function(self, node, key)
self:scoped_store("script")[node.value] = true
return true
end;
}
data:type "action" "set" (2, "string")
data:type "action" "get" "var-name"
:validate
{
down = function(self, node, key)
if not self:scoped_store("script")[node.value] then
return nil, "unknown variable", node.value
end
return true
end;
}
-- Terminal (aka lang:const, node:literal)
-- Note that data:type can’t be terminal.
data:leaf "string" "random"
data:type "string" "get"
data:value "var-name"
{
regexp = "^[a-zA-Z_][a-zA-Z0-9_]*$";
}
default:value "var-name" (function(self, node, key)
local prefix, n = "foo", 0
local name = prefix
local storage = self:scoped_store("script")
while storage[name] do
n = n + 1
name = prefix .. "_" .. n
-- TODO: Store max_n instead?
-- Get it during regular traversal.
assert(n < 1000, "too many default variables")
end
return name
end)
data:value "string" "string-value" -- any string would do
to:version "com.logiceditor.8.variables" { 0, 0, 1 }
to:text "mini"
:T [[
math.randomseed(os.time())
${child(1)}
]]
to:text "script"
:T [[
do
local _VARS = { }
${indent(concat(children))}
end
]]
to:text "print" "string"
:T [[
print(${quote:lua(node)})
]]
to:text "get" "var-name"
:T [[_VARS[${quote:lua(node)}]]
to:text "set"
:T [[
_VARS[${quote:lua(child(1))}] = ${child(2)}
]]
to:text "random"
:T [[tostring(math.random())]]
to:text "string-value"
:T [[${quote:lua(node)]]
to:version "com.logiceditor.8.variables" { 0, 0, 1 }
-- TODO: html:list()?
to:ui "script"
:T [[
<ol class="smart-list">
<li>
${indent(concat(children, "</li><li>"))}
</li>
</ol>
]]
to:ui "script"(0)
:T [[
<ol class="smart-list">
<li>
<i>(Add a new item)</i>
</li>
</ol>
]]
to:ui "print"
:T [[
<b>PRINT:</b> ${child(1)}
]]
to:ui "set"
:T [[
<b>SET</b> ${child(1)} <b>to</b> ${child(2)}
]]
to:ui "random"
:T [[
<b>RND</b>
]]
to:ui "get"
:T [[<b>GET</b> ${child(1)}]]
to:ui "string"
:T [[${html:variant(node)]]
to:ui "string-value"
:T [[${html:input(node)}]]
to:ui "set" "var-name"
:T [[${html:input_with_autocomplete(default(node), autosuggest)}]]
:autosuggest
{
down = function(self, node, key)
self:scoped_store("script")[node.value] = true
end;
up = function(self, node, key)
return self:scoped_store("script")
end;
}
to:ui "get" "var-name"
:T [[${html:enum(node.value, autosuggest)}]]
:autosuggest
{
up = function(self, node, key)
return self:scoped_store("script")
end;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment