Parser - Index
Indexing now parswer the Identifier first as a Path, and then it converts it to an Identifier, if possible
@@ -5,9 +5,12 @@ pub struct IndexParser;
impl IndexParser {
pub fn parse(parser: &mut Parser, collection_name: Expression) -> ParserExprKindResult {
- let collection_name_string = match collection_name.kind {
- ExpressionKind::Ident(x) => x,
- _ => return Err(ParserErrorKind::UnstructuredError{message: format!("Expected an identifier for the collection name. Arbitrary expressions are yet to arrive"), span : collection_name.span}.into_err(parser.file_id))
+ let err = ParserErrorKind::UnstructuredError{message: format!("Expected an identifier for the collection name. Arbitrary expressions are yet to arrive"), span : collection_name.span}.into_err(parser.file_id);
+ let collection_name = match collection_name.kind {
+ ExpressionKind::Path(path) => {
+ path.into_ident().ok_or(err)?
+ },
+ _=> return Err(err)
};
// Current token is now the left bracket that sits between the name of the collection
@@ -21,7 +24,7 @@ impl IndexParser {
parser.peek_check_variant_advance(&Token::RightBracket)?;
let index_expr = IndexExpression {
- collection_name: collection_name_string.into(),
+ collection_name: collection_name.clone(),
index: index,
};
