Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function buildpath(from, to, sepChar)
- --
- -- if no command separator character is specified, use default.
- local sep = sepChar or zs.func.char( zs.func.pref( 'iSepChar' ) )
- --
- zs.var.fromroom = from
- zs.var.toroom = to
- --
- local sw = zs.func.pathfrom( from, to )
- --
- zs.var.rawsw = sw
- --
- local C, Cc, Cf, P, V, match = lpeg.C, lpeg.Cc, lpeg.Cf, lpeg.P, lpeg.V, lpeg.match
- --
- local directions, portal, sw_e, sw_s, walk = V( 'directions' ), V( 'portal' ), V( 'sw_e' ), V( 'sw_s' ), V( 'walk' )
- --
- local run = function( sw ) if sw:len() > 1 then sw = "run "..sw end return sw end
- --
- local fold = function( walk, sw )
- --
- if walk:len() == 0 then return sw end
- --
- if sw:len() == 0 then return walk end
- --
- return walk..sep..sw
- --
- end
- --
- local speedwalk = P { -- grammar for path decoding.
- 'speedwalk', -- starting symbol name.
- sw_e = P(sep), -- end-of-speedwalk marker.
- sw_s = P('.'), -- start-of-speedwalk marker.
- directions = C((1 - sw_e)^0), -- speedwalk string capture.
- portal = P('(' * C((1 - P(')'))^1) * ')')^0, -- custom exit command capture.
- walk = sw_s * portal * (directions / run) * sw_e^-1, -- speedwalk iteration element.
- speedwalk = Cf(Cc("") * walk^0, fold) -- complete speedwalk search pattern.
- } * -1 -- end-of-input marker.
- --
- return match( speedwalk, sw )
- --
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement