1
0
mirror of synced 2024-12-13 06:46:03 +03:00

[2.0] More optimizations on Annotations parser. More docblocks also

This commit is contained in:
guilhermeblanco 2009-08-08 04:36:58 +00:00
parent ac5fe1f91b
commit 92f22c8567

View File

@ -263,6 +263,8 @@ class Parser
/** /**
* Values ::= Value {"," Value}* * Values ::= Value {"," Value}*
*
* @return array
*/ */
public function Values() public function Values()
{ {
@ -292,49 +294,12 @@ class Parser
} }
return $values; return $values;
/*if ($this->_lexer->isNextToken(')')) {
// Single value
if (is_array($value)) {
$k = key($value);
$v = $value[$k];
if (is_string($k)) {
// FieldAssignment
$values[$k] = $v;
} else {
$values['value']= $value;
}
} else {
$values['value'] = $value;
}
return $values;
} else {
// FieldAssignment
$k = key($value);
$v = $value[$k];
$values[$k] = $v;
}
while ($this->_lexer->isNextToken(',')) {
$this->match(',');
$value = $this->Value();
if ( ! is_array($value)) {
$this->syntaxError('FieldAssignment', $value);
}
$k = key($value);
$v = $value[$k];
$values[$k] = $v;
}
return $values;*/
} }
/** /**
* Value ::= PlainValue | FieldAssignment * Value ::= PlainValue | FieldAssignment
*
* @return mixed
*/ */
public function Value() public function Value()
{ {
@ -349,6 +314,8 @@ class Parser
/** /**
* PlainValue ::= integer | string | float | Array | Annotation * PlainValue ::= integer | string | float | Array | Annotation
*
* @return mixed
*/ */
public function PlainValue() public function PlainValue()
{ {
@ -388,8 +355,10 @@ class Parser
} }
/** /**
* fieldAssignment ::= fieldName "=" plainValue * FieldAssignment ::= FieldName "=" PlainValue
* fieldName ::= identifier * FieldName ::= identifier
*
* @return array
*/ */
public function FieldAssignment() public function FieldAssignment()
{ {
@ -402,20 +371,33 @@ class Parser
/** /**
* Array ::= "{" ArrayEntry {"," ArrayEntry}* "}" * Array ::= "{" ArrayEntry {"," ArrayEntry}* "}"
*
* @return array
*/ */
public function Arrayx() public function Arrayx()
{ {
$array = $values = array();
$this->match('{'); $this->match('{');
$array = array(); $values[] = $this->ArrayEntry();
$this->ArrayEntry($array);
while ($this->_lexer->isNextToken(',')) { while ($this->_lexer->isNextToken(',')) {
$this->match(','); $this->match(',');
$this->ArrayEntry($array); $values[] = $this->ArrayEntry();
} }
$this->match('}'); $this->match('}');
foreach ($values as $value) {
$key = key($value);
if (is_string($key)) {
$array[$key] = $value[$key];
} else {
$array[] = $value[$key];
}
}
return $array; return $array;
} }
@ -423,8 +405,10 @@ class Parser
* ArrayEntry ::= Value | KeyValuePair * ArrayEntry ::= Value | KeyValuePair
* KeyValuePair ::= Key "=" Value * KeyValuePair ::= Key "=" Value
* Key ::= string | integer * Key ::= string | integer
*
* @return array
*/ */
public function ArrayEntry(array &$array) public function ArrayEntry()
{ {
$peek = $this->_lexer->glimpse(); $peek = $this->_lexer->glimpse();
@ -438,9 +422,9 @@ class Parser
$key = $this->_lexer->token['value']; $key = $this->_lexer->token['value'];
$this->match('='); $this->match('=');
return $array[$key] = $this->Value(); return array($key => $this->Value());
} }
return $array[] = $this->Value(); return array($this->Value());
} }
} }