Commit 92f22c85 authored by guilhermeblanco's avatar guilhermeblanco

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

parent ac5fe1f9
...@@ -263,6 +263,8 @@ class Parser ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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());
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment