fn peek<K: Peek>(cursor: Cursor) -> Result<bool> { // This is a little fancy because when parsing something like: // // (type (component (type $foo))) // // we need to disambiguate that from // // (type (component (type $foo (func)))) // // where the first is a type reference and the second is an inline // component type defining a type internally. The peek here not only // peeks for `K` but also for the index and possibly trailing // strings.
// Peek for the given keyword type if !K::peek(cursor)? { return Ok(false);
}
// Move past the given keyword let cursor = match cursor.keyword()? {
Some((_, c)) => c,
_ => return Ok(false),
};
// Peek an id or integer index, followed by `)` or string to disambiguate let cursor = match cursor.id()? {
Some((_, cursor)) => Some(cursor),
None => cursor.integer()?.map(|p| p.1),
};
Ok(match cursor {
Some(cursor) => cursor.rparen()?.is_some() || cursor.string()?.is_some(),
None => false,
})
}
/// Parses core item references. #[derive(Clone, Debug)] pubstruct CoreItemRef<'a, K> { /// The item kind being parsed. pub kind: K, /// The item or instance reference. pub idx: Index<'a>, /// Export name to resolve the item from. pub export_name: Option<&'a str>,
}
impl<'a, K: Parse<'a>> Parse<'a> for CoreItemRef<'a, K> { fn parse(parser: Parser<'a>) -> Result<Self> { // This does not parse the surrounding `(` and `)` because // core prefix is context dependent and only the caller knows if it should be // present for core references; therefore, the caller parses the parens and any core prefix let kind = parser.parse::<K>()?; let idx = parser.parse()?; let export_name = parser.parse()?;
Ok(Self {
kind,
idx,
export_name,
})
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.