Fix up regex, fails test for #79(!)#94
Conversation
|
I've pushed a quick refactor to clear up the responsibility of some of the line parsing code. Unfortunately my original change breaks the spec for #79 but I'm not sure why yet. |
lib/canned.js
Outdated
There was a problem hiding this comment.
this does not need to be on the prototype as it is only used inside the file as far as I can see.
|
Really like where this is going 👍 |
remove parseOption from scope
|
Ok so for the regex the problem is indeed that var string = "aaacaaa\naaa\nbbb\nccc\nbaaabaaa"
var re = new RegExp(/aaa/g)
var res = string.split("\n").reduce(function(acc, el) {
el.replace(re, function(match, _index, full){
acc.push({ match: match, full: full })
});
return acc
}, [])
console.log(res)
// => [ { match: 'aaa', full: 'aaacaaa' }, { match: 'aaa', full: 'aaacaaa' },
// { match: 'aaa', full: 'aaa' }, { match: 'aaa', full: 'baaabaaa' },
// { match: 'aaa', full: 'baaabaaa' } ]This now works correctly with the |
|
I pushed another big commit. I moved the request params and return options parsing into their own modules that are ludicrously similar. Probably best to have a shared parser that deals with all the front matter (to steal a term from jekyll) and it can return the comprehensive list of options per entry in the file. Hopefully I'm barking up the right tree. It's very much WIP, but I'd like to hear your feedback. |
There was a problem hiding this comment.
please use underscore _ in the filename - is a pain sometimes :(
|
NICE! I really like the approach, left some comments but mostly style, I try to keep this consistent if possible. Also I think the api would be nicer if the request and response parser would basically work like this var parseRequest = require("./request_parser")
var options = parseRequset(lines) |
This change fixes a couple of problems:
The regexes as they stood were both matching per character, which makes for some interesting matches such as: http://rubular.com/r/uZpZRyhmpN
Changing the character group to a non-captured OR group makes the results: http://rubular.com/r/XBXkjlu54P
It also removes the /g option from the regexp. Since the
.execmethod is called only once per line it was causing weird results because/gcauses it to return falsy unexpectedly. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#Finding_successive_matches)