Compare commits

...

3 Commits

Author SHA1 Message Date
madpwnhammer 497c6b6b0b Added extension passing in mtg_parse_meta
Publish PHP Package / docker (push) Successful in 6s Details
2025-04-08 17:19:48 +03:00
Pavel Shevaev 2802fc0345 Fixing typos
Publish PHP Package / docker (push) Successful in 6s Details
2025-02-03 17:23:18 +03:00
Pavel Shevaev c330fda0cf Adding initial support for services only events
Publish PHP Package / docker (push) Successful in 7s Details
2025-01-20 20:12:20 +03:00
3 changed files with 55 additions and 7 deletions

View File

@ -586,6 +586,7 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope
private $name;
private $parent_scope;
private $rpcs = array();
private $events = array();
private $user_types = array();
function __construct($name, mtgScope $parent_scope, array $tokens = array())
@ -615,7 +616,7 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope
return $this->parent_scope->findSymbol($name);
}
function getRPCs()
function getRPCs() : array
{
return $this->rpcs;
}
@ -646,14 +647,14 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope
return $this->rpcs[$name];
}
function getUserTypes()
function getUserTypes() : array
{
return $this->user_types;
}
function addUserType(mtgUserType $utype)
{
if($this->hasRPC($utype->getName()))
if($this->hasRPC($utype->getName()) || $this->hasUserType($utype->getName()))
throw new Exception("Service '{$this->name}' already has type '{$utype->getName()}'");
$this->user_types[$utype->getName()] = $utype;
@ -671,6 +672,17 @@ class mtgMetaService extends mtgMetaUnit implements mtgScope
return $this->user_types[$name];
}
function addEvent(mtgMetaStruct $evt)
{
$this->events[] = $evt;
$this->addUserType($evt);
}
function getEvents() : array
{
return $this->events;
}
function getClassId()
{
if($this->hasToken('class_id'))

View File

@ -54,7 +54,7 @@ class mtgMetaParsedModule implements mtgScope
}
}
function mtg_parse_meta(array $meta_srcs, $valid_tokens = null, $inc_path = null, $version = null)
function mtg_parse_meta(array $meta_srcs, $valid_tokens = null, $inc_path = null, $version = null, string $extension = '.meta')
{
if($inc_path === null)
{
@ -91,7 +91,7 @@ function mtg_parse_meta(array $meta_srcs, $valid_tokens = null, $inc_path = null
$meta = new mtgMetaInfo();
foreach($meta_srcs as $src)
mtg_load_meta($meta, $meta_parser, $src);
mtg_load_meta($meta, $meta_parser, $src, $extension);
$meta->validate();

View File

@ -31,6 +31,7 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
const T_bool = 1030;
const T_blob = 1031;
const T_Service = 1032;
const T_Event = 1033;
const T_MaxType = 1034; //built-in types end mark
private array $config = array();
@ -95,6 +96,7 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
"extends" => self::T_Extends,
"implements" => self::T_Implements,
"func" => self::T_Func,
"event" => self::T_Event,
];
$this->T2descr = array_flip($this->symbol2T);
@ -113,6 +115,7 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
$this->T2descr[self::T_Extends] = '<extends>';
$this->T2descr[self::T_Implements] = '<implements>';
$this->T2descr[self::T_Func] = '<func>';
$this->T2descr[self::T_Event] = '<Event>';
}
private static function _addDefaultTokens(array &$config)
@ -355,7 +358,7 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
return $values;
}
private function _parseEnum($is_global = true)
private function _parseEnum($is_global = true) : mtgMetaEnum
{
$this->_nextT();
$name = $this->_parseDotName();
@ -574,6 +577,37 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
$this->_addUnit(new mtgMetaInfoUnit($this->module, $fn));
}
private function _parseEvent() : mtgMetaStruct
{
$this->_nextT();
$struct_origin = new mtgOrigin($this->file, $this->line);
$name = $this->_parseDotName();
$this->_checkThenNext(ord('{'));
$s = new mtgMetaStruct($name, array(), null, array(), array());
$s->setOrigin($struct_origin);
$tokens = $this->shared_tokens;
if($this->T == self::T_Prop)
$tokens = array_merge($tokens, $this->_parsePropTokens());
$s->setTokens($tokens);
$flds = $this->_parseFields(
function()
{
if($this->_nextIf(ord('}')))
return true;
if($this->_nextIf(self::T_Func))
$this->_error("Events don't support functions");
}
);
foreach($flds as $fld)
$s->addField($fld);
return $s;
}
private function _parseStruct()
{
$this->_nextT();
@ -660,7 +694,7 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
$this->_nextT();
}
private function _parseRPC($is_global = true)
private function _parseRPC($is_global = true) : mtgMetaRPC
{
$this->_nextT();
$code = $this->T_value;
@ -719,6 +753,8 @@ class mtgMetaInfoParser2 implements mtgIMetaInfoParser
$service->addRPC($this->_parseRPC(false));
else if($this->T == self::T_Enum)
$service->addUserType($this->_parseEnum(false));
else if($this->T == self::T_Event)
$service->addEvent($this->_parseEvent());
else
$this->_error("Unsupported type");
}