diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81aa0e72..8985191f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -157,12 +157,14 @@ jobs: components: rustfmt, clippy - name: cargo +${{ matrix.rust_toolchain }} fmt + if: ${{ always() }} uses: actions-rs/cargo@v1 with: command: fmt args: --all -- --check - name: cargo +${{ matrix.rust_toolchain }} clippy + if: ${{ always() }} uses: actions-rs/cargo@v1 with: command: clippy @@ -188,6 +190,7 @@ jobs: components: rustfmt, clippy - name: cargo +${{ matrix.rust_toolchain }} clippy + if: ${{ always() }} uses: actions-rs/cargo@v1 with: command: clippy diff --git a/src/parser.rs b/src/parser.rs index a9a7e4af..db245d1d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1282,55 +1282,59 @@ where ))), } } - _ => match self.cur_token.in_standard_prelude() { - Some(s) => { - let ident = self.identifier_from_ident_token((s, None)); - self.parser_position.range = self.lexer_position.range; - self.parser_position.line = self.lexer_position.line; - - Ok(Type2::Typename { - ident, - generic_args: None, - span: ( - self.parser_position.range.0, - self.parser_position.range.1, - self.parser_position.line, - ), - }) - } - None => { - self.parser_position.line = self.lexer_position.line; - self.parser_position.range = self.lexer_position.range; + _ => { + self.collect_comments()?; - if self.cur_token_is(Token::COLON) || self.cur_token_is(Token::ARROWMAP) { - self.errors.push(ParserError { - position: self.parser_position, - msg: MissingGroupEntryMemberKey.into(), - }); + match self.cur_token.in_standard_prelude() { + Some(s) => { + let ident = self.identifier_from_ident_token((s, None)); + self.parser_position.range = self.lexer_position.range; + self.parser_position.line = self.lexer_position.line; - return Err(Error::PARSER); + Ok(Type2::Typename { + ident, + generic_args: None, + span: ( + self.parser_position.range.0, + self.parser_position.range.1, + self.parser_position.line, + ), + }) } + None => { + self.parser_position.line = self.lexer_position.line; + self.parser_position.range = self.lexer_position.range; + + if self.cur_token_is(Token::COLON) || self.cur_token_is(Token::ARROWMAP) { + self.errors.push(ParserError { + position: self.parser_position, + msg: MissingGroupEntryMemberKey.into(), + }); + + return Err(Error::PARSER); + } + + if self.cur_token_is(Token::RBRACE) + || self.cur_token_is(Token::RBRACKET) + || self.cur_token_is(Token::RPAREN) + { + self.errors.push(ParserError { + position: self.parser_position, + msg: MissingGroupEntry.into(), + }); + + return Err(Error::PARSER); + } - if self.cur_token_is(Token::RBRACE) - || self.cur_token_is(Token::RBRACKET) - || self.cur_token_is(Token::RPAREN) - { self.errors.push(ParserError { position: self.parser_position, - msg: MissingGroupEntry.into(), + msg: InvalidGroupEntrySyntax.into(), }); - return Err(Error::PARSER); + Err(Error::PARSER) } - - self.errors.push(ParserError { - position: self.parser_position, - msg: InvalidGroupEntrySyntax.into(), - }); - - Err(Error::PARSER) } - }, + } }; self.parser_position.range.1 = self.lexer_position.range.1; @@ -2462,9 +2466,7 @@ pub fn cddl_from_str<'a>( pub fn cddl_from_str(input: &str) -> result::Result { match Parser::new(Lexer::new(input).iter(), input) { Ok(mut p) => match p.parse_cddl() { - Ok(c) => JsValue::from_serde(&c) - .map_err(|e| JsValue::from(e.to_string())) - .map(|c| c), + Ok(c) => JsValue::from_serde(&c).map_err(|e| JsValue::from(e.to_string())), Err(Error::PARSER) => { if !p.errors.is_empty() { return Err(JsValue::from_serde(&p.errors).map_err(|e| JsValue::from(e.to_string()))?);