<commit_before><?php
/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com
 * @copyright  Copyright &copy; 2004-2009 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html
 */

/**
 * class lmbMacroTagParsingState.
 *
 * @package macro
 * @version $Id$
 */
class lmbMacroTagParsingState extends lmbMacroBaseParsingState implements lmbMacroTokenizerListener
{
  protected $tag_dictionary;

  function __construct(lmbMacroParser $parser, lmbMacroTreeBuilder $tree_builder, lmbMacroTagDictionary $tag_dictionary)
  {
    parent :: __construct($parser, $tree_builder);
    $this->tag_dictionary = $tag_dictionary;
  }
  
  function raiseNotSuchTagException($tag, $location)
  {
    $params = array('file', $location->getFile(),
                    'line', $location->getLine());
    
    throw new lmbMacroException("Tag '$tag' not found in dictionary", $params);
  }

  function startElement($tag, $attrs)
  {
    $location = $this->parser->getCurrentLocation();

    $lower_attributes = $this->normalizeAttributes($attrs, $location);

    if(!$tag_info = $this->tag_dictionary->findTagInfo($tag))
      $this->raiseNotSuchTagException($tag, $location);

    if($tag_info->isEndTagForbidden())
    {
      $tag_node = $this->buildTagNode($tag_info, $tag, $attrs);
      $tag_node->setHasClosingTag(false);
      $this->tree_builder->pushNode($tag_node); // for cases like {{include}} we do pushNode() and popNode() here.
      $this->tree_builder->popNode();
    }
    else
    {
      $this->tree_builder->pushExpectedTag($tag, $location);
      $tag_node = $this->buildTagNode($tag_info, $tag, $attrs, $self_closed_tag = false);
      $result = $this->tree_builder->pushNode($tag_node);
    }
  }

  function endElement($tag)
  {
    if(!$tag_info = $this->tag_dictionary->findTagInfo($tag))
      $this->raiseNotSuchTagException($tag, $location);
    
    $location = $this->parser->getCurrentLocation();

    if($tag_info->isEndTagForbidden())
    {
      throw new lmbMacroException('Closing tag forbidden',
                              array('tag' => $tag_info->getTag(),<commit_msg>Getting current location before raiseNotSuchTagException<commit_after><?php
/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com
 * @copyright  Copyright &copy; 2004-2009 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html
 */

/**
 * class lmbMacroTagParsingState.
 *
 * @package macro
 * @version $Id$
 */
class lmbMacroTagParsingState extends lmbMacroBaseParsingState implements lmbMacroTokenizerListener
{
  protected $tag_dictionary;

  function __construct(lmbMacroParser $parser, lmbMacroTreeBuilder $tree_builder, lmbMacroTagDictionary $tag_dictionary)
  {
    parent :: __construct($parser, $tree_builder);
    $this->tag_dictionary = $tag_dictionary;
  }
  
  function raiseNotSuchTagException($tag, $location)
  {
    $params = array('file', $location->getFile(),
                    'line', $location->getLine());
    
    throw new lmbMacroException("Tag '$tag' not found in dictionary", $params);
  }

  function startElement($tag, $attrs)
  {
    $location = $this->parser->getCurrentLocation();

    $lower_attributes = $this->normalizeAttributes($attrs, $location);

    if(!$tag_info = $this->tag_dictionary->findTagInfo($tag))
      $this->raiseNotSuchTagException($tag, $location);

    if($tag_info->isEndTagForbidden())
    {
      $tag_node = $this->buildTagNode($tag_info, $tag, $attrs);
      $tag_node->setHasClosingTag(false);
      $this->tree_builder->pushNode($tag_node); // for cases like {{include}} we do pushNode() and popNode() here.
      $this->tree_builder->popNode();
    }
    else
    {
      $this->tree_builder->pushExpectedTag($tag, $location);
      $tag_node = $this->buildTagNode($tag_info, $tag, $attrs, $self_closed_tag = false);
      $result = $this->tree_builder->pushNode($tag_node);
    }
  }

  function endElement($tag)
  {
    $location = $this->parser->getCurrentLocation();
	
    if(!$tag_info = $this->tag_dictionary->findTagInfo($tag))
      $this->raiseNotSuchTagException($tag, $location);
    
    if($tag_info->isEndTagForbidden())
    {
      throw new lmbMacroException('Closing tag forbidden',
                              array('tag' => $tag_info->getTag(),
{'fraction_non_alphanumeric': 0.15069767441860465, 'fraction_numerical': 0.0037209302325581397, 'mean_word_length': 3.821748878923767, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7244392', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1360, 'n_words': 231}