dxml 0.2.0 released

rikki cattermole rikki at cattermole.co.nz
Wed Feb 14 10:57:26 UTC 2018


On 14/02/2018 10:32 AM, Jonathan M Davis wrote:
> On Wednesday, February 14, 2018 10:14:44 Kagamin via Digitalmars-d-announce
> wrote:
>> It looks like EntityRange requires forward range, is it ok for a
>> parser?
> 
> It's very difficult in general to write a parser that isn't at least a
> forward range, because without that, you're stuck at only one character of
> look ahead unless you play a lot of games with putting data from the input
> range in a buffer so that you can keep it around to look at it again after
> you've looked farther ahead.
> 
> Honestly, pure input ranges are borderline useless for a _lot_ of cases.
> It's generally only the cases where you only care about operating on each
> element individually irrespective of what's going on with other elements in
> the range that pure input ranges are really useable, and parsing definitely
> doesn't fall into that camp.
> 
> - Jonathan M Davis

See lines:
- Input!IR temp = input;
- input = temp;

            bool commentLine() {
		Input!IR temp = input;

		if (!temp.empty && temp.front.c == '/') {
			temp.popFront;
			if (!temp.empty && temp.front.c == '/')
				temp.popFront;
			else
				return false;
		} else
			return false;

		if (!temp.empty) {
			size_t endOffset = temp.front.location.fileOffset;

			while(temp.front.location.lineOffset != 0) {
				endOffset = temp.front.location.fileOffset;
				temp.popFront;

				if (temp.empty) {
					endOffset++;
					break;
				}
			}
			
			current.type = Token.Type.Comment_Line;
			current.location = input.front.location;
			current.location.length = endOffset - input.front.location.fileOffset;
			
			input = temp;
			return true;
		} else
			return false;
	}


More information about the Digitalmars-d-announce mailing list