6 ms·
> you can then read in stuff with something like input.split("\t").map(unescape) What about input lines like 'asdf\\thjkl\tzxcvb'? That should be two fields, o
by eadmund 3y ago
> you can then read in stuff with something like input.split("\t").map(unescape)
What about input lines like 'asdf\\thjkl\tzxcvb'? That should be two fields, one the string ‘asdf\thjkl’ and the other the string ‘zxcvb.’
I think that your way is a bit like trying to match context-free grammars with a regular expression. The right way is to parse the input character by character.
- cxr 3y agoAlthough matching up nested pairs of brackets requires something at least as powerful as a pushdown automaton (CFG matcher), discriminating between an arbitrary number of escaped backslashes followed by an unescaped 't' versus an arbitrary number of escaped backslashes followed by the '\t' escape sequence doesn't require anything more powerful than a finite state machine.
- qzzi 3y ago> you know any actual tab character in the input is a field separator, and then you can go through the fields to put back the escaped ones The "\t" in "split" is not a "slash-tee" but an actual tab character and then escape sequences in fields are handled by the "unescape" function.
- fiddlerwoaroof 3y agoI think the suggestion is that the field separator is an actual tab character (ascii code 9) but tabs inside the field are `\t`. So, splitting on the tab character always works because fields cannot contain ascii code 9 but must use the two character escape instead.