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

org.unlaxer.parser.elementary.QuotedParser Maven / Gradle / Ivy

package org.unlaxer.parser.elementary;

import java.util.List;

import org.unlaxer.Name;
import org.unlaxer.parser.Parser;
import org.unlaxer.parser.Parsers;
import org.unlaxer.parser.combinator.Choice;
import org.unlaxer.parser.combinator.LazyChain;
import org.unlaxer.parser.combinator.NotPropagatableSource;
import org.unlaxer.parser.combinator.ParserWrapper;
import org.unlaxer.parser.combinator.ZeroOrMore;

public class QuotedParser extends LazyChain {
	
	public enum Parts{
		leftQuote,
		contents,
		rightQuote,
		;
		Name nameInstance;
		
		private Parts(){
			nameInstance = Name.of(this);
		}
		public Name get(){
			return nameInstance;
		}
	}
	
	private static final long serialVersionUID = 8673007906829254945L;
	
	Parser quoteParser;
	
	public QuotedParser(Parser quoteParser) {
		super();
		this.quoteParser = quoteParser;
	}
	

	public QuotedParser(Name name,Parser quoteParser) {
		super(name);
		this.quoteParser = quoteParser;
	}


	public static final Name contensName = Name.of(QuotedParser.class, Parts.contents.get());

	@Override
	public List getLazyParsers() {
		return new Parsers(
			new ParserWrapper(
				Name.of(QuotedParser.class, Parts.leftQuote.get()),
				quoteParser
			),
			new ZeroOrMore(contensName,
				new Choice(
					new EscapeInQuotedParser(),
					new NotPropagatableSource(quoteParser)
				)
			),
			new ParserWrapper(
				Name.of(QuotedParser.class, Parts.rightQuote.get()),
				quoteParser
			)
		);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy