Skip to content

Commit

Permalink
New macro system implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
lucastercas committed Apr 14, 2018
1 parent 238be9d commit 4aa7280
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
5 changes: 3 additions & 2 deletions spec/media.sncl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ end
macro makeContext(id, mId, mSrc, mLft)
context id
makeMedia(mId, mSrc, mLft)
port pC1 c1m1
media c1m2
src: "text/html"
end
Expand All @@ -29,9 +30,9 @@ media m3
end

onBegin m3 do
start c1m1 end
start c1 end
end

onEnd m3 do
start c1m1 end
start c1 end
end
17 changes: 16 additions & 1 deletion src/parser/gen.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--local ins = require"inspect"
local ins = require"inspect"
local utils = require"utils"

local gen = {
Expand Down Expand Up @@ -136,6 +136,21 @@ end
function gen.genBind(ele, indent, sT)
local NCL = ""

--[[ If the link(ele.father) has a father, then the component must
be a son of the father of the link. Else, then the component must
not have a father either]]
if ele.father.father then
if not ele.father.father.sons[ele.component] then
utils.printErro(string.format('Component %s not in scope', ele.component), ele.line)
return NCL
end
else
if sT.presentation[ele.component].father then
utils.printErro(string.format('Component %s not in scope', ele.component), ele.line)
return NCL
end
end

if not sT.presentation[ele.component] then
utils.printErro(string.format('No element %s declared', ele.component))
return ""
Expand Down
5 changes: 3 additions & 2 deletions src/parser/grammar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ grammar = {
Property = pT.makeProperty( (C(V'Id') *V'Spc'^0* P':' *V'Spc'^0*
C(P'"'*V'PropertyValue'*P'"' + V'PropertyValue') * V'Spc'^0)),

Port = V'Spc'^0*pT.makePort(P'port'* V'Spc'^1 * C(V'Id') * V'Spc'^1 * C(V'Id')*(P'.'*C(V'Id'))^-1, sT),
Port = V'Spc'^0*pT.makePort(P'port'* V'Spc'^1 * C(V'Id') * V'Spc'^1 * C(V'Id')*(P'.'*C(V'Id'))^-1, sT, false),

PresentationElement = V'Spc'^0* pT.makePresentationElement(C(V'Reserved') *V'Spc'^1 * C(V'Id') *V'Spc'^1
*(V'PresentationElement'+V'Port'+V'Property'+V'Link'+V'MacroCall'+V'Template'+V'Spc')^0 *C(V'End'), sT, false),
Expand All @@ -62,8 +62,9 @@ grammar = {
ActionId = pT.makeRelationship(C(V'Reserved') *V'Spc'^1* (C(V'Id')*(P'.'*C(V'Id'))^-1)),
RepeatAction = P'and' *V'Spc'^1*V'ActionId',

MacroPort = V'Spc'^0*pT.makePort(P'port'* V'Spc'^1 * C(V'Id') * V'Spc'^1 * C(V'Id')*(P'.'*C(V'Id'))^-1, sT, true),
MacroPresentationElement = V'Spc'^0* pT.makePresentationElement(C(V'Reserved') *V'Spc'^1 * C(V'Id') *V'Spc'^1
*(V'MacroPresentationElement'+V'Port'+V'Property'+V'MacroLink'+V'Template'+V'MacroCall'+V'Spc')^0 *C(V'End'), sT, true),
*(V'MacroPresentationElement'+V'MacroPort'+V'Property'+V'MacroLink'+V'Template'+V'MacroCall'+V'Spc')^0 *C(V'End'), sT, true),
MacroLink = (V'Spc'^0*
pT.makeLink((V'Condition' *V'Spc'^1* ((V'Property'+V'Action')-V'End')^0 *C(V'End')*V'Spc'^0), sT, true)),
Macro = V'Spc'^0* pT.makeMacro(P'macro' *V'Spc'^1* C(V'Id') *V'Spc'^0* V'Parameters'
Expand Down
11 changes: 9 additions & 2 deletions src/parser/macros.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ function resolveMacros:presentation(ele, call, stack, sT)
}

local parameters = sT.macro[call.macro].parameters
if ele._type == 'port' then
newEle.component = self.getArgument(call.arguments, parameters, ele.component)
end

local newId = self.getArgument(call.arguments, parameters, ele.id)
--[[ Check is an element with the same Id is already declared ]]
Expand Down Expand Up @@ -157,11 +160,15 @@ function resolveMacros:link(ele, call, sT)
local macro = sT.macro[call.macro]

for _, action in pairs(ele.actions) do
table.insert(newEle.actions, self:bind(action, call, sT))
local newAction = self:bind(action, call, sT)
newAction.father = newEle
table.insert(newEle.actions, newAction)
end

for _, condition in pairs(ele.conditions) do
table.insert(newEle.conditions, self:bind(condition, call, sT))
local newCond = self:bind(condition, call, sT)
newCond.father = newEle
table.insert(newEle.conditions, newCond)
end

for name, value in pairs(ele.properties) do
Expand Down
11 changes: 6 additions & 5 deletions src/parser/parse-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local parsingTable = {
-- @param str The return of lpeg
-- @param sT The symbol table
-- @return The generated table
makePort = function(str, sT)
makePort = function(str, sT, isMacroSon)
return str / function(id, comp, iface)
local element = {
_type = 'port',
Expand All @@ -27,7 +27,9 @@ local parsingTable = {
return nil
end

sT.presentation[id] = element
if not isMacroSon then
sT.presentation[id] = element
end
return element
end
end,
Expand Down Expand Up @@ -185,10 +187,9 @@ local parsingTable = {
if type(val) == 'table' then
if val._type == 'action' then
table.insert(element.actions, val)
val.father = element
elseif val._type == 'condition' then
if not element.conditions then
element.conditions = {}
end
val.father = element
table.insert(element.conditions, val)
else
for name, value in pairs(val) do
Expand Down

0 comments on commit 4aa7280

Please sign in to comment.