git.s-ol.nu mmm / 20aeafe
fix conversion pattern escapes s-ol 3 years ago
2 changed file(s) with 5 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
11 converts = require '.converts'
22
33 count = (base, pattern='->') -> select 2, base\gsub pattern, ''
4 escape_pattern = (inp) -> "^#{inp\gsub '([-/])', '%%%1'}$"
4 escape_pattern = (inp) -> "^#{inp\gsub '([^%w])', '%%%1'}$"
5 escape_inp = (inp) -> "^#{inp\gsub '([-/])', '%%%1'}$"
56
67 -- attempt to find a conversion path from 'have' to 'want'
78 -- * have - start type string or list of type strings
89 -- * want - stop type pattern
910 -- * limit - limit conversion amount
1011 -- returns a list of conversion steps
11 get_conversions = (want, have, _converts=converts, limit=3) ->
12 get_conversions = (want, have, _converts=converts, limit=5) ->
1213 assert have, 'need starting type(s)'
1314
1415 if 'string' == type have
2728 return conversions, start
2829 else
2930 for convert in *_converts
30 inp = escape_pattern convert.inp
31 inp = escape_inp convert.inp
3132 continue unless rest\match inp
3233 result = rest\gsub inp, convert.out
3334 if result
200200 transform: single code
201201 },
202202 {
203 inp: 'URL -> .*',
203 inp: 'URL -> .+',
204204 out: 'mmm/dom',
205205 transform: single code
206206 },