Skip to content

Commit

Permalink
Added parsing of assignments without real assignments [~ doSomething(x)]
Browse files Browse the repository at this point in the history
  • Loading branch information
astrochili committed Sep 25, 2021
1 parent 405276b commit dc67a65
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 0 additions & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
- [ ] There is no query functions ```TURNS()``` and ```TURNS_SINCE()```
- [ ] A list uses only standard numerical values ```1, 2, 3...```. Can't define your own numerical values like ```4, 7, 12...```.
- [ ] A comment in the middle of the paragraph ```before /* comment */ and after``` splits it into two paragraphs ```before``` and ```and after```
- [ ] Not possible to run a function after assignment operator without any assignments. *Use ```{ run() }``` instead*.

## Ideas

Expand Down
2 changes: 1 addition & 1 deletion narrator/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function Parser.parse(content)
unwrapped = unwrapped:gsub('([%w_]*)%s*([%+%-])[%+%-]', '%1 = %1 %2 1')
unwrapped = unwrapped:gsub('([%w_]*)%s*([%+%-])=%s*(.*)', '%1 = %1 %2 %3')
local name, value = unwrapped:match('([%w_]*)%s*=%s*(.*)')
return name, value
return name or '', value or assignment
end

--
Expand Down
17 changes: 13 additions & 4 deletions narrator/story.lua
Original file line number Diff line number Diff line change
Expand Up @@ -749,16 +749,25 @@ end
-- Variables

function Story:assignValueTo(variable, expression, temp)
if self.constants[variable] ~= nil then return end

if self.constants[variable] ~= nil then
return
end
local value = self:doExpression(expression)

if #variable == 0 then
return
end
local storage = (temp or self.temp[variable] ~= nil) and self.temp or self.variables

if storage[variable] == value then return end
if storage[variable] == value then
return
end
storage[variable] = value

local observer = self.observers[variable]
if observer ~= nil then observer(value) end
if observer ~= nil then
observer(value)
end
end

function Story:getValueFor(variable)
Expand Down
2 changes: 1 addition & 1 deletion test/runtime/binding.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local narrator, describe, it, assert = ...

local content = [[
{ beep() }
~ beep()
{ sum(1, 2) }
{ didSolvePuzzle("labirint") }
]]
Expand Down

0 comments on commit dc67a65

Please sign in to comment.