<commit_before>/*
 * @LANG: c++
 * @CFLAGS: -I../aapl
 */

#include <iostream>
#include <string.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

%%{
	machine mailbox;

	action prn_char { cout << *p; }
	action prn_space { cout << ' '; }
	action prn_word { cout.write(ws, p-ws); cout << ' '; }
	action prn_addr1 { cout << "| "; cout.write(ws+1, p-ws-2); }
	action prn_addr2 { cout << "| "; cout.write(ws, p-ws); }
	action prn_tab { cout << '\t'; }
	action prn_nl { cout << '\n'; }
	action prn_separator { cout << "------\n"; } 
	action prn_from { cout << "FROM\n"; }
	action prn_to { cout << "TO\n"; }
	action prn_subj { cout << "SUBJECT\n"; }

	action start_word { ws = p; }
	action start_headers { preserve = p; }
	action end_headers {preserve = 0;}

	day = upper lower{2};
	month = upper lower{2};
	year = digit{4};
	time = digit{2} ':' digit{2} 
		( ':' digit{2} )?;
	letterZone = upper{3};
	numZone = [+\-] digit{4};
	zone = letterZone | numZone;
	dayNum = ( digit | ' ' ) digit;

	date = day ' ' month ' ' 
		dayNum ' ' time ' '
		( 
			year | 
			year ' ' zone | 
			zone ' ' year
		);

	fromLine = 'From ' [^\n]* ' ' 
		date '\n' @start_headers;

	headerChar = print - [ :];
	headersToPrint = 'From' | 
		'To' | 'Subject';
	headersToConsume = 
		headerChar+ - headersToPrint;

	consumeHeader = 
		headersToConsume ':'
		( 
			[^\n] | 
			( '\n' [ \t] )
		)*
		'\n';

	addrWS = ( [ \t]+ | '\n' [ \t]+ );
	addrComment = '(' [^)]* ')';
	addrWord = [^"'@,<>() \t\n]+;
	addrAddr1 = '<' [^>]* '>';
	addrAddr2 = addrWord '@' addrWord;
	addrString = 
		'"' [^"]* '"' |
		"'" [^']* "'";

	addrItem = (
			addrAddr1 %prn_addr1 |
			addrAddr2 %prn_addr2 |
			addrWord %prn_word |
			addrString %prn_word
		) >start_word;

	address = ( 
			addrWS |
			addrComment |
			addrItem 
		)** >prn_tab;

	addrHeader = ( 
			'From' %prn_from | 
			'To' %prn_to
		) ':'
		address ( ',' @prn_nl address )*
		'\n' %prn_nl;

	subjectHeader = 
		'Subject:' @prn_subj @prn_tab
		' '* <:
		( 
			[^\n] @prn_char  | 
			( '\n' [ \t]+ ) %prn_space
		)**
		'\n' %prn_nl;

	header = consumeHeader | 
		addrHeader | subjectHeader;

	messageLine = 
		( [^\n]* '\n' - fromLine );

	main := (
			fromLine %prn_separator
			header* 
			'\n' @end_headers
			messageLine*
		)*;
 }%%
 
%% write data;

#define BUFSIZE 8192

void test( const char *buf )
{
	int cs, len = strlen( buf );
	const char *preserve = 0, *ws = 0;

	%% write init;
	const char *p = buf;
	const char *pe = p + len;
	%% write exec;

	if ( cs == mailbox_error )
		cerr << "ERROR" << endl;

	if ( cs < mailbox_first_final )
		cerr << "DID NOT FINISH IN A FINAL STATE" << endl;
}

int main()
{
	test(
		"From <EMAIL> Wed Nov 28 13:30:05 2001\n"
		"From: \"<NAME>\" <<EMAIL>>\n"<commit_msg>fixed warning in mailbox2.rl test case<commit_after>/*
 * @LANG: c++
 * @CFLAGS: -I../aapl
 */

#include <iostream>
#include <string.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

%%{
	machine mailbox;

	action prn_char { cout << *p; }
	action prn_space { cout << ' '; }
	action prn_word { cout.write(ws, p-ws); cout << ' '; }
	action prn_addr1 { cout << "| "; cout.write(ws+1, p-ws-2); }
	action prn_addr2 { cout << "| "; cout.write(ws, p-ws); }
	action prn_tab { cout << '\t'; }
	action prn_nl { cout << '\n'; }
	action prn_separator { cout << "------\n"; } 
	action prn_from { cout << "FROM\n"; }
	action prn_to { cout << "TO\n"; }
	action prn_subj { cout << "SUBJECT\n"; }

	action start_word { ws = p; }
	action start_headers { }
	action end_headers { }

	day = upper lower{2};
	month = upper lower{2};
	year = digit{4};
	time = digit{2} ':' digit{2} 
		( ':' digit{2} )?;
	letterZone = upper{3};
	numZone = [+\-] digit{4};
	zone = letterZone | numZone;
	dayNum = ( digit | ' ' ) digit;

	date = day ' ' month ' ' 
		dayNum ' ' time ' '
		( 
			year | 
			year ' ' zone | 
			zone ' ' year
		);

	fromLine = 'From ' [^\n]* ' ' 
		date '\n' @start_headers;

	headerChar = print - [ :];
	headersToPrint = 'From' | 
		'To' | 'Subject';
	headersToConsume = 
		headerChar+ - headersToPrint;

	consumeHeader = 
		headersToConsume ':'
		( 
			[^\n] | 
			( '\n' [ \t] )
		)*
		'\n';

	addrWS = ( [ \t]+ | '\n' [ \t]+ );
	addrComment = '(' [^)]* ')';
	addrWord = [^"'@,<>() \t\n]+;
	addrAddr1 = '<' [^>]* '>';
	addrAddr2 = addrWord '@' addrWord;
	addrString = 
		'"' [^"]* '"' |
		"'" [^']* "'";

	addrItem = (
			addrAddr1 %prn_addr1 |
			addrAddr2 %prn_addr2 |
			addrWord %prn_word |
			addrString %prn_word
		) >start_word;

	address = ( 
			addrWS |
			addrComment |
			addrItem 
		)** >prn_tab;

	addrHeader = ( 
			'From' %prn_from | 
			'To' %prn_to
		) ':'
		address ( ',' @prn_nl address )*
		'\n' %prn_nl;

	subjectHeader = 
		'Subject:' @prn_subj @prn_tab
		' '* <:
		( 
			[^\n] @prn_char  | 
			( '\n' [ \t]+ ) %prn_space
		)**
		'\n' %prn_nl;

	header = consumeHeader | 
		addrHeader | subjectHeader;

	messageLine = 
		( [^\n]* '\n' - fromLine );

	main := (
			fromLine %prn_separator
			header* 
			'\n' @end_headers
			messageLine*
		)*;
 }%%
 
%% write data;

#define BUFSIZE 8192

void test( const char *buf )
{
	int cs, len = strlen( buf );
	const char *ws = 0;

	%% write init;
	const char *p = buf;
	const char *pe = p + len;
	%% write exec;

	if ( cs == mailbox_error )
		cerr << "ERROR" << endl;

	if ( cs < mailbox_first_final )
		cerr << "DID NOT FINISH IN A FINAL STATE" << endl;
}

int main()
{
	test(
		"From <EMAIL> Wed Nov 28 13:30:05 2001\n"
		"From: \"<NAME>\" <<EMAIL>>\n"
{'fraction_non_alphanumeric': 0.2089116143170197, 'fraction_numerical': 0.013330898466033601, 'mean_word_length': 2.7258503401360543, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 25, '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': '5239906', 'n_tokens_mistral': 2568, 'n_tokens_neox': 2307, 'n_words': 514}