<commit_before>package org.peg4d;

class PegVisitor {
	private UMap<String> visitedMap = new UMap<String>();
	boolean isVisited(String name) {
		if(this.visitedMap != null) {
			return this.visitedMap.hasKey(name);
		}
		return true;
	}
	void visited(String name) {
		if(this.visitedMap != null) {		
			this.visitedMap.put(name, name);
		}
	}
	void initVisitor() {
		if(this.visitedMap != null) {
			this.visitedMap.clear();
		}
	}
	public void visitNonTerminal(PegNonTerminal e) {
		if(!this.isVisited(e.symbol)) {
			visited(e.symbol);
			e.base.getExpression(e.symbol).visit(this);
		}
	}
	public void visitString(PegString e) {
	}
	public void visitCharacter(PegCharacter e) {
	}
	public void visitAny(PegAny e) {
	}
	public void visitNotAny(PegNotAny e) {
		e.orig.visit(this);
	}
	public void visitTagging(PegTagging e) {
	}
	public void visitMessage(PegMessage e) {
	}
	public void visitIndent(PegIndent e) {
	}
	public void visitIndex(PegIndex e) {
	}
	public void visitUnary(PegUnary e) {
		e.inner.visit(this);
	}
	public void visitNot(PegNot e) {
		this.visitUnary(e);
	}
	public void visitAnd(PegAnd e) {
		this.visitUnary(e);
	}
	public void visitOptional(PegOptional e) {
		this.visitUnary(e);
	}
	public void visitRepeat(PegRepeat e) {
		this.visitUnary(e);
	}
	public void visitSetter(PegSetter e) {
		this.visitUnary(e);
	}
	public void visitExport(PegExport e) {
		this.visitUnary(e);
	}
	public void visitList(PegList e) {
		for(int i = 0; i < e.size(); i++) {
			e.get(i).visit(this);
		}
	}
	public void visitSequence(PegSequence e) {
		this.visitList(e);
	}
	public void visitChoice(PegChoice e) {
		this.visitList(e);
	}
	public void visitNewObject(PegNewObject e) {
		this.visitList(e);
	}
	public void visitOperation(PegOperation e) {
		e.inner.visit(this);
	}
}

class Formatter extends PegVisitor {
	UStringBuilder sb;
	
	public Formatter() {
		sb = new UStringBuilder();
	}

	public String getDesc() {
		return "PEG4d ";
	}
	
	public void format(Peg e, UStringBuilder sb) {
		this.sb = sb;
		e.visit(this);
		this.sb = null;
	}

	public void formatHeader() {
	}

	public void formatFooter() {
	}
	
	public void formatRule(String ruleName, Peg e, UStringBuilder sb) {
		this.sb = sb;
		sb.appendNewLine();
		this.formatRuleName(ruleName, e);
		sb.append(this.getNewLine(), this.getSetter(), " ");
		if(e instanceof PegChoice) {
			for(int i = 0; i < e.size(); i++) {
				if(i > 0) {
					sb.append(this.getNewLine(), "/ ");
				}
				e.get(i).visit(this);
			}
		}
		else {
			e.visit(this);
		}
		sb.append(getNewLine(), this.getSemiColon());
		this.sb = null;
	}
	
	public String getNewLine() {
		return "\n\t";
	}

	public String getSetter() {
		return "=";
	}

	public String getSemiColon() {
		return ";";
	}

	public void formatRuleName(String ruleName, Peg e) {
		if(e.is(Peg.HasNewObject)) {
			sb.append(ruleName);
		}
		else {
			sb.append(ruleName.toUpperCase());
		}
	}

	@Override
	public void visitNonTerminal(PegNonTerminal e) {
		this.formatRuleName(e.symbol, e);
	}

	@Override
	public void visitString(PegString e) {
		char quote = '\'';
		if(e.text.indexOf("'") != -1) {
			quote = '"';
		}
		sb.append(UCharset._QuoteString(quote, e.text, quote));
	}

	@Override
	public void visitCharacter(PegCharacter e) {
		sb.append("[" + e.charset, "]");
	}

	@Override
	public void visitAny(PegAny e) {
		sb.append(".");
	}

	@Override
	public void visitTagging(PegTagging e) {
		sb.append(e.symbol);
	}
	
	@Override
	public void visitMessage(PegMessage e) {
		sb.append("`", e.symbol, "`");
	}

	@Override
	public void visitIndent(PegIndent e) {
		sb.append("indent");
	}

	@Override
	public void visitIndex(PegIndex e) {<commit_msg>bugs fixed at Formatter<commit_after>package org.peg4d;

class PegVisitor {
	private UMap<String> visitedMap = new UMap<String>();
	boolean isVisited(String name) {
		if(this.visitedMap != null) {
			return this.visitedMap.hasKey(name);
		}
		return true;
	}
	void visited(String name) {
		if(this.visitedMap != null) {		
			this.visitedMap.put(name, name);
		}
	}
	void initVisitor() {
		if(this.visitedMap != null) {
			this.visitedMap.clear();
		}
	}
	public void visitNonTerminal(PegNonTerminal e) {
		if(!this.isVisited(e.symbol)) {
			visited(e.symbol);
			e.base.getExpression(e.symbol).visit(this);
		}
	}
	public void visitString(PegString e) {
	}
	public void visitCharacter(PegCharacter e) {
	}
	public void visitAny(PegAny e) {
	}
	public void visitNotAny(PegNotAny e) {
		e.orig.visit(this);
	}
	public void visitTagging(PegTagging e) {
	}
	public void visitMessage(PegMessage e) {
	}
	public void visitIndent(PegIndent e) {
	}
	public void visitIndex(PegIndex e) {
	}
	public void visitUnary(PegUnary e) {
		e.inner.visit(this);
	}
	public void visitNot(PegNot e) {
		this.visitUnary(e);
	}
	public void visitAnd(PegAnd e) {
		this.visitUnary(e);
	}
	public void visitOptional(PegOptional e) {
		this.visitUnary(e);
	}
	public void visitRepeat(PegRepeat e) {
		this.visitUnary(e);
	}
	public void visitSetter(PegSetter e) {
		this.visitUnary(e);
	}
	public void visitExport(PegExport e) {
		this.visitUnary(e);
	}
	public void visitList(PegList e) {
		for(int i = 0; i < e.size(); i++) {
			e.get(i).visit(this);
		}
	}
	public void visitSequence(PegSequence e) {
		this.visitList(e);
	}
	public void visitChoice(PegChoice e) {
		this.visitList(e);
	}
	public void visitNewObject(PegNewObject e) {
		this.visitList(e);
	}
	public void visitOperation(PegOperation e) {
		e.inner.visit(this);
	}
}

class Formatter extends PegVisitor {
	UStringBuilder sb;
	public Formatter() {
		sb = new UStringBuilder();
	}
	public String getDesc() {
		return "PEG4d ";
	}
	public void format(Peg e, UStringBuilder sb) {
		this.sb = sb;
		e.visit(this);
		this.sb = null;
	}
	public void formatHeader() {
	}
	public void formatFooter() {
	}
	public void formatRule(String ruleName, Peg e, UStringBuilder sb) {
		this.sb = sb;
		sb.appendNewLine();
		this.formatRuleName(ruleName, e);
		sb.append(this.getNewLine(), this.getSetter(), " ");
		if(e instanceof PegChoice) {
			for(int i = 0; i < e.size(); i++) {
				if(i > 0) {
					sb.append(this.getNewLine(), "/ ");
				}
				e.get(i).visit(this);
			}
		}
		else {
			e.visit(this);
		}
		sb.append(getNewLine(), this.getSemiColon());
		this.sb = null;
	}
	public String getNewLine() {
		return "\n\t";
	}
	public String getSetter() {
		return "=";
	}
	public String getSemiColon() {
		return ";";
	}
	public void formatRuleName(String ruleName, Peg e) {
		sb.append(ruleName);
	}
	@Override
	public void visitNonTerminal(PegNonTerminal e) {
		this.formatRuleName(e.symbol, e);
	}
	@Override
	public void visitString(PegString e) {
		char quote = '\'';
		if(e.text.indexOf("'") != -1) {
			quote = '"';
		}
		sb.append(UCharset._QuoteString(quote, e.text, quote));
	}
	@Override
	public void visitCharacter(PegCharacter e) {
		sb.append("[" + e.charset, "]");
	}
	@Override
	public void visitAny(PegAny e) {
		sb.append(".");
	}
	@Override
	public void visitTagging(PegTagging e) {
		sb.append(e.symbol);
	}
	@Override
	public void visitMessage(PegMessage e) {
		sb.append("`", e.symbol, "`");
	}
	@Override
	public void visitIndent(PegIndent e) {
		sb.append("indent");
	}

	@Override
	public void visitIndex(PegIndex e) {
{'fraction_non_alphanumeric': 0.14897142068203784, 'fraction_numerical': 0.0016567720557779926, 'mean_word_length': 3.7501639344262294, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6587274', 'n_tokens_mistral': 3048, 'n_tokens_neox': 2823, 'n_words': 566}