Skip to content

Commit

Permalink
Merge pull request #81 from anweiss/fix-newline-parsing-bug
Browse files Browse the repository at this point in the history
Fix newline parsing bug
  • Loading branch information
anweiss authored Jan 25, 2021
2 parents 2ebc705 + e731ce8 commit 7b6e97d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -188,6 +190,7 @@ jobs:
components: rustfmt, clippy

- name: cargo +${{ matrix.rust_toolchain }} clippy
if: ${{ always() }}
uses: actions-rs/cargo@v1
with:
command: clippy
Expand Down
86 changes: 44 additions & 42 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2462,9 +2466,7 @@ pub fn cddl_from_str<'a>(
pub fn cddl_from_str(input: &str) -> result::Result<JsValue, JsValue> {
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()))?);
Expand Down

0 comments on commit 7b6e97d

Please sign in to comment.