MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / parse_pattern

Method parse_pattern

crates/hll-to-ir/src/parser.rs:2006–2051  ·  view source on GitHub ↗

A match pattern: `_`, a bare binding (lowercase), or `Variant(b0, b1)` / bare `Variant` (capitalized). `_` discards a payload slot.

(&mut self)

Source from the content-addressed store, hash-verified

2004 index,
2005 })
2006 }
2007 _ => Err(self.error("left side of assignment is not assignable")),
2008 }
2009 }
2010
2011 fn consume_terminators(&mut self) {
2012 while self.match_statement_terminator() {}
2013 }
2014
2015 fn process_string_escapes(&self, input: &str) -> String {
2016 let mut result = String::with_capacity(input.len());
2017 let mut chars = input.chars();
2018
2019 while let Some(c) = chars.next() {
2020 if c == '\\' {
2021 match chars.next() {
2022 Some('n') => result.push('\n'),
2023 Some('t') => result.push('\t'),
2024 Some('r') => result.push('\r'),
2025 Some('\\') => result.push('\\'),
2026 Some('"') => result.push('"'),
2027 Some(other) => {
2028 result.push('\\');
2029 result.push(other);
2030 }
2031 None => result.push('\\'),
2032 }
2033 } else {
2034 result.push(c);
2035 }
2036 }
2037
2038 result
2039 }
2040
2041 // An array length in type position: a literal, or a compile-time constant
2042 // expression (const decls and associated constants) folded before analysis.
2043 fn parse_array_length(&mut self) -> Result<ArrayLen, ParserError> {
2044 if let Some(Token::Integer(text)) = self.peek()
2045 && matches!(self.peek_n(1), Some(Token::RBracket))
2046 {
2047 let value = strip_separators(text)
2048 .parse::<usize>()
2049 .map_err(|_| self.error("invalid array size"))?;
2050 self.advance();
2051 return Ok(ArrayLen::Fixed(value));
2052 }
2053 match self.peek() {
2054 Some(Token::RBracket) | None => Err(self.error("expected array size")),

Callers 1

Calls 8

LiteralEnum · 0.85
expect_identMethod · 0.80
expect_lparenMethod · 0.80
check_rparenMethod · 0.80
pushMethod · 0.80
match_commaMethod · 0.80
expect_rparenMethod · 0.80

Tested by

no test coverage detected