itais ics parser framework

A

Anonymous

Guest
Hi!
Here with a new parsing framework after a rewrite of my previous one due to the fact that I rewrote the whole software because it was incredibly messy and inconsistent.

This time it is complete with inline tags and error reporting.

Here's a simple example:
Code:
<?php
$parser = new \itais\ics\parser\Parser;

$parser->code         = "<red>The time is: </red> <time>";
$parser->callback    function ($tag)
{
    if ($tag->type == \itais\ics\parser\TagType::Start)
    {
        if ($tag->command == "time")
        {
       		$signal = new \itais\ics\parser\Signal;
       		
        	$signal->inline      = true; //this is an inlined tag
        	$signal->output    = time(); //and it represents the time
        	
        	return $signal;
        }
        else
        {
        	$signal = new \itais\ics\parser\Signal;
        	$signal->inline    = false;
        	
        	return $signal;
        }
    }
    else
    {
    	if ($tag->command == "color")
    	{
    	    $signal = new \itais\ics\parser\Signal;
    	    
    	    $signal->output    = "<span style=\"color: red\">{$tag->content}</span>";
    	    
    	    return $signal;
    	}
    }
    
    //if we haven't handled it yet
    $signal = new \itais\ics\parser\Signal;
    	    
    $signal->output    = $tag->content;
    	    
    return $signal;
}

$parser->Parse();

echo $parser->output;

However, this is just the tip of the iceberg. Look through the source to find out more.
 

Attachments

  • parser.7z
    3.2 KB · Views: 456
Back
Top