mirror of
https://github.com/danog/parser.git
synced 2024-11-27 04:14:55 +01:00
parser: reorganise poor expression handling
This commit is contained in:
parent
30afcce2d5
commit
a6fc1b58f1
@ -1,4 +1,3 @@
|
||||
<?php
|
||||
|
||||
$foo['foo'] = 'bar';
|
||||
$foo['foo']['bar'] = 'baz';
|
||||
$foo['foo'];
|
@ -709,20 +709,42 @@ impl Parser {
|
||||
}
|
||||
|
||||
let mut lhs = match &self.current.kind {
|
||||
TokenKind::Variable(v) => Expression::Variable(v.to_string()),
|
||||
TokenKind::Int(i) => Expression::Int(*i),
|
||||
TokenKind::Identifier(i) => Expression::Identifier(i.to_string()),
|
||||
TokenKind::ConstantString(s) => Expression::ConstantString(s.to_string()),
|
||||
TokenKind::True => Expression::Bool(true),
|
||||
TokenKind::False => Expression::Bool(false),
|
||||
TokenKind::Variable(v) => {
|
||||
let e = Expression::Variable(v.to_string());
|
||||
self.next();
|
||||
e
|
||||
},
|
||||
TokenKind::Int(i) => {
|
||||
let e = Expression::Int(*i);
|
||||
self.next();
|
||||
e
|
||||
},
|
||||
TokenKind::Identifier(i) => {
|
||||
let e = Expression::Identifier(i.to_string());
|
||||
self.next();
|
||||
e
|
||||
},
|
||||
TokenKind::ConstantString(s) => {
|
||||
let e = Expression::ConstantString(s.to_string());
|
||||
self.next();
|
||||
e
|
||||
},
|
||||
TokenKind::True => {
|
||||
let e = Expression::Bool(true);
|
||||
self.next();
|
||||
e
|
||||
},
|
||||
TokenKind::False => {
|
||||
let e = Expression::Bool(false);
|
||||
self.next();
|
||||
e
|
||||
},
|
||||
TokenKind::LeftParen => {
|
||||
self.next();
|
||||
|
||||
let e = self.expression(0)?;
|
||||
|
||||
if self.current.kind != TokenKind::RightParen {
|
||||
return Err(ParseError::ExpectedToken("expected right paren".into(), self.current.span));
|
||||
}
|
||||
self.rparen()?;
|
||||
|
||||
e
|
||||
},
|
||||
@ -748,6 +770,8 @@ impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
self.rbracket()?;
|
||||
|
||||
Expression::Array(items)
|
||||
},
|
||||
TokenKind::Function => {
|
||||
@ -901,7 +925,7 @@ impl Parser {
|
||||
return Ok(lhs);
|
||||
}
|
||||
|
||||
self.next();
|
||||
// self.next();
|
||||
|
||||
loop {
|
||||
let kind = match &self.current {
|
||||
|
@ -29,4 +29,14 @@ impl Parser {
|
||||
expect!(self, TokenKind::RightParen, (), "expected )");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn lbracket(&mut self) -> ParseResult<()> {
|
||||
expect!(self, TokenKind::LeftBracket, (), "expected [");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn rbracket(&mut self) -> ParseResult<()> {
|
||||
expect!(self, TokenKind::RightBracket, (), "expected ]");
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user