Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How to consume until a delimiter - with exceptions (Petit Parser for Dart)

$
0
0

Fair enough, previously was a badly worded question. I'm going to take another stab at it.

I'm using Dart's PetitParser to consume input. I want a lexer that will accept any string until one of a number of delimiters is found. The trouble I have is that some of the delimiters are single characters and some are strings, and the characters can be escaped if they're in a single quoted string, and also the delimiters don't count if they're in a single quoted string.

This is my attempted basic setup at the moment:

Parser<String> fpLexer(List<String> delimiters) {  return delimiters      .map(string)      .toChoiceParser()      .cast<String>()      .neg()      .plus();}

For instance, if my delimiters are " and the word then. And my input string is:

'<a href=\"http://www.w3.org/1999/xhtml\">then</a>' some "Link"

I need a Lexer that will consume up until "Link". The reasoning is that the first set of double quotes are within the single quoted segment AND escaped, and because the word then is also within the quoted segment, neither of those qualifies as a delimiter. So the first delimiter that's reached is the initial " before the word Link.

Hopefully I've explained myself better this time. Thanks for the input!


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>