Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function parse_cmud_sws( _, _, wildcards )
- --
- lpeg = require( "lpeg" )
- world.SetVariable ( "sws", "" )
- local sw = wildcards[1] or ""
- 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 sep = ";"
- 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.
- --
- world.SetVariable ( "sws", match( speedwalk, sw ) )
- return
- --
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement