MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / bracket

Method bracket

aiscript-vm/src/parser/mod.rs:1756–1801  ·  view source on GitHub ↗
(&mut self, _can_assign: bool)

Source from the content-addressed store, hash-verified

1754 }
1755
1756 fn bracket(&mut self, _can_assign: bool) -> Option<Expr<'gc>> {
1757 let mut elements = Vec::new();
1758 let line = self.previous.line;
1759
1760 // A flag to only check CloseBucket once to determine the Expr::EvaluateVariant
1761 let mut once = iter::once(1);
1762 if !self.check(TokenType::CloseBracket) {
1763 loop {
1764 let item = self.expression()?;
1765 if once.next().is_some()
1766 // EvaluateVariant can only perform on those three Expr.
1767 // We allow [self] syntax in enum's method.
1768 && matches!(item, Expr::EnumVariant { .. } | Expr::Variable { .. } | Expr::Self_ { .. })
1769 && self.match_token(TokenType::CloseBracket)
1770 {
1771 // Evaluate expression value
1772 return Some(Expr::EvaluateVariant {
1773 expr: Box::new(item),
1774 line,
1775 });
1776 }
1777
1778 elements.push(item);
1779 if !self.check(TokenType::Comma) && !self.check(TokenType::CloseBracket) {
1780 self.error_at_current("Expect ',' after array element.");
1781 return None;
1782 }
1783
1784 if !self.match_token(TokenType::Comma) {
1785 break;
1786 }
1787
1788 // Check for trailing comma
1789 if self.check(TokenType::CloseBracket) {
1790 break;
1791 }
1792 }
1793 }
1794
1795 self.consume(TokenType::CloseBracket, "Expect ']' after array elements.");
1796 Some(Expr::List {
1797 elements,
1798 kind: ListKind::Array,
1799 line,
1800 })
1801 }
1802
1803 fn call(&mut self, _can_assign: bool) -> Option<Expr<'gc>> {
1804 let callee = Box::new(self.previous_expr.take()?);

Callers

nothing calls this directly

Calls 7

checkMethod · 0.80
expressionMethod · 0.80
match_tokenMethod · 0.80
pushMethod · 0.80
error_at_currentMethod · 0.80
nextMethod · 0.45
consumeMethod · 0.45

Tested by

no test coverage detected