Skip to content

Conversation

@aochagavia
Copy link
Contributor

No description provided.

@aochagavia
Copy link
Contributor Author

As part of this PR I am trying to use a visitor instead of casting, but for some reason this version returns no character validation errors. Am I missing something? Maybe I am using the visitor the wrong way...

@aochagavia
Copy link
Contributor Author

(I was under the idea that a visitor would visit the descendants of the node as well, but maybe that isn't the case?)

errors

if !components.has_closing_quote {
errors.push(SyntaxError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to create a helper funciton for construction SyntaxError.

@aochagavia aochagavia changed the title WIP - Validate character escapes Introduce SyntaxErrorKind and TextRange to SyntaxError Nov 4, 2018
@aochagavia
Copy link
Contributor Author

I started working on SyntaxError and it became bigger than I anticipated, so I changed the title of the PR. Once this one is merged I want to finish the work on characters and maybe start with strings.

ParseError(msg) => write!(f, "{}", msg.0),
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, moving this to separate file makes sense!

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SyntaxError {
pub kind: SyntaxErrorKind,
pub range: TextRange,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am slightly worried that we know expose a rather elaborate internal structure of the error. Let's make these fields private, but add

enum Location {
    Offest(TextUnit),
    Range(TextRange),
}

impl SyntaxError {
    fn location() -> ErrorLocation
}

I think it maybe make sense to distinguish between offset/range for location, because there are errors for which range does not make sense, due to error recovery. Consider, for example, this snippet:

fn

fn foo() {}

Here, we should report expected ident. However, the fn foo() {} is correctly parsed as a function, so we can't mark fn token as an error. I think the expected behavior is to say that the error happened after the fn token, and let it to the UI layer to select the most appropriate presentation, which, in this case, is a single-character range after \n.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None that we don't need fn message() -> String, because SyntaxError: fmt::Display

@aochagavia
Copy link
Contributor Author

Just pushed a commit with the suggested changes. Any additional comments?

@matklad
Copy link
Contributor

matklad commented Nov 5, 2018

LGTM!

bors r+

bors bot added a commit that referenced this pull request Nov 5, 2018
188: Introduce `SyntaxErrorKind` and `TextRange` to `SyntaxError` r=matklad a=aochagavia



Co-authored-by: Adolfo Ochagavía <[email protected]>
Co-authored-by: Adolfo Ochagavía <[email protected]>
@bors
Copy link
Contributor

bors bot commented Nov 5, 2018

Build succeeded

@bors bors bot merged commit 59405bf into rust-lang:master Nov 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants