Skip to content

Commit dc67a65

Browse files
committed
Added parsing of assignments without real assignments [~ doSomething(x)]
1 parent 405276b commit dc67a65

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

ROADMAP.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
- [ ] There is no query functions ```TURNS()``` and ```TURNS_SINCE()```
2323
- [ ] A list uses only standard numerical values ```1, 2, 3...```. Can't define your own numerical values like ```4, 7, 12...```.
2424
- [ ] A comment in the middle of the paragraph ```before /* comment */ and after``` splits it into two paragraphs ```before``` and ```and after```
25-
- [ ] Not possible to run a function after assignment operator without any assignments. *Use ```{ run() }``` instead*.
2625

2726
## Ideas
2827

narrator/parser.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function Parser.parse(content)
8989
unwrapped = unwrapped:gsub('([%w_]*)%s*([%+%-])[%+%-]', '%1 = %1 %2 1')
9090
unwrapped = unwrapped:gsub('([%w_]*)%s*([%+%-])=%s*(.*)', '%1 = %1 %2 %3')
9191
local name, value = unwrapped:match('([%w_]*)%s*=%s*(.*)')
92-
return name, value
92+
return name or '', value or assignment
9393
end
9494

9595
--

narrator/story.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,16 +749,25 @@ end
749749
-- Variables
750750

751751
function Story:assignValueTo(variable, expression, temp)
752-
if self.constants[variable] ~= nil then return end
753-
752+
if self.constants[variable] ~= nil then
753+
return
754+
end
754755
local value = self:doExpression(expression)
756+
757+
if #variable == 0 then
758+
return
759+
end
755760
local storage = (temp or self.temp[variable] ~= nil) and self.temp or self.variables
756761

757-
if storage[variable] == value then return end
762+
if storage[variable] == value then
763+
return
764+
end
758765
storage[variable] = value
759766

760767
local observer = self.observers[variable]
761-
if observer ~= nil then observer(value) end
768+
if observer ~= nil then
769+
observer(value)
770+
end
762771
end
763772

764773
function Story:getValueFor(variable)

test/runtime/binding.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local narrator, describe, it, assert = ...
22

33
local content = [[
4-
{ beep() }
4+
~ beep()
55
{ sum(1, 2) }
66
{ didSolvePuzzle("labirint") }
77
]]

0 commit comments

Comments
 (0)