<commit_before>%{
#include <stdio.h>
#include <string.h>
#include "../dom/node.h"

extern int yylex(void);
extern int yyparse(void);
 
doc* document;

void yyerror(const char *str)
{
        fprintf(stderr,"error: %s\n",str);
}
 
int yywrap()
{
        return 1;
} 
  
%}

%union{
  char * string;
  struct snode* dn;
 }

%token START_EL END_EL SLASH
%token <string> WORD TEXT CDATA_TOK 
%type <string> value end_tag
%type <dn> attr node prop inner attrs declaration start_tag
%start document

%%
document: node             {document = new_document(NULL); set_doc_root(document, $1);}
	| declaration node {document = new_document($1); set_doc_root(document, $2);}
	;

declaration: START_EL '?' WORD attrs '?' END_EL {
						  if(strcmp($3, "xml") != 0){
						    yyerror("Declaration does not begin with xml.\n");
						    exit(-1);
						  }
						  $$ = $4;
						  set_name($$, $3);
						}
	;


node:	start_tag inner end_tag	 {				 
				  if(strcmp(get_name($1),$3) != 0){
				    yyerror("Start tag does not match end tag.\n");
				    exit(-1);
                                  }
				  append_children($1, $2->children);
				  free($2);
				  $$ = $1;
				  }
	;

inner:			{$$ = new_element_node("~dummy~");}
        | inner prop	{ $$ = $1;
			  append_child($$, $2);
			}
	;

prop:	CDATA_TOK  {$$ = new_cdata($1);}
	| TEXT {$$ = new_text_node($1);}
	| node {$$ = $1;}
	;

start_tag: START_EL WORD attrs END_EL {
					$$ = $3;
				       set_name($$, $2);
				      }
	;

end_tag: START_EL SLASH WORD END_EL {$$ = $3;}
	;

attrs: 		     {$$ = new_element_node("~dummy~");}
	| attrs attr {
		      $$ = $1;
		      add_attribute($$, $2);
		     }
	;

attr:	WORD '=' value {$$ = new_attribute($1, $3);}
	;

value:	'"' TEXT '"' {$$ = $2;}
	;<commit_msg>partial build of selector meta object<commit_after>%{
#include <stdio.h>
#include <string.h>
#include "../dom/node.h"

extern int yylex(void);
extern int yyparse(void);
 
doc* document;

void yyerror(const char *str)
{
        fprintf(stderr,"error: %s\n",str);
}
 
int yywrap()
{
        return 1;
} 
  
%}

%union{
  char * string;
  struct snode* dn;
 }

%token START_EL END_EL SLASH
%token <string> WORD TEXT CDATA_TOK 
%type <string> value end_tag
%type <dn> attr node prop inner attrs declaration start_tag
%start document

%%
document: node             {document = new_document(NULL); set_doc_root(document, $1);}
	| declaration node {document = new_document($1); set_doc_root(document, $2);}
	;

declaration: START_EL '?' WORD attrs '?' END_EL {
						  if(strcmp($3, "xml") != 0){
						    yyerror("Declaration does not begin with xml.\n");
						    exit(-1);
						  }
						  $$ = $4;
						  set_name($$, $3);
						}
	;


node:	start_tag inner end_tag	 				{
								  if(strcmp(get_name($1),$3) != 0){
								    yyerror("Start tag does not match end tag.\n");
								    exit(1);
								  }
								  append_children($1, $2->children);
								  free($2);
								  $$ = $1;
								}
	;

inner:								{$$ = new_element_node("~dummy~");}
     | inner prop						{ $$ = $1;
								  append_child($$, $2);
								}
     ;

prop: CDATA_TOK 						{$$ = new_cdata($1);}
    | TEXT 							{$$ = new_text_node($1);}
    | node 							{$$ = $1;}
    ;

start_tag: START_EL WORD attrs END_EL 				{
								  $$ = $3;
								  set_name($$, $2);
								}
	 ;

end_tag: START_EL SLASH WORD END_EL 				{$$ = $3;}
       ;

attrs: 								{$$ = new_element_node("~dummy~");}
	| attrs attr 						{
								  $$ = $1;
								  add_attribute($$, $2);
								}
     ;

attr:	WORD '=' value 						{$$ = new_attribute($1, $3);}
								;

value:	'"' TEXT '"' 						{$$ = $2;}
     ;
{'fraction_non_alphanumeric': 0.18069646284617494, 'fraction_numerical': 0.016451878256100904, 'mean_word_length': 2.169417897480452, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1251892', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1391, 'n_words': 297}