All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.unlaxer.parser.combinator.ChoiceInterface Maven / Gradle / Ivy

package org.unlaxer.parser.combinator;

import java.util.List;

import org.unlaxer.Parsed;
import org.unlaxer.TokenKind;
import org.unlaxer.context.ParseContext;
import org.unlaxer.parser.Parser;

public interface ChoiceInterface extends Parser{
	
	@Override
	public default Parsed parse(ParseContext parseContext, TokenKind tokenKind, boolean invertMatch) {
		
		parseContext.startParse(this, parseContext, tokenKind, invertMatch);
		List children = getChildren();
		
		for (Parser parser : children) {
			parseContext.begin(this);
			Parsed parsed = parser.parse(parseContext, tokenKind, invertMatch);
			
			if (parsed.isSucceeded()) {
				parseContext.commit(this, tokenKind , new ChoiceCommitAction(parser));
				parseContext.endParse(this, parsed , parseContext, tokenKind, invertMatch);
				return parsed;
			}
			parseContext.rollback(this);
		}
		parseContext.endParse(this, Parsed.FAILED , parseContext, tokenKind, invertMatch);
		return Parsed.FAILED;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy