Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Started working on the Parser #21

Merged
merged 2 commits into from
Jan 25, 2018

Conversation

Michael-F-Bryan
Copy link
Contributor

This is the first instalment towards #13. I'm planning to do a quick high-level overview of the parser and libsyntax and mentioning the major players (Parser, ParseSess, etc) and what they do.


- lexical analysis - turn a stream of characters into a stream of token trees
- macro expansion - run `proc-macros` and expand `macro_rules` macros
- parsing - turn the token trees into an AST
Copy link
Contributor

Choose a reason for hiding this comment

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

Here I think I would link to the relevant chapter of the guide -- oh, wait, do we not have a chapter for the AST? We should add one =)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking the AST would fall under the parser section, maybe as a short sub-chapter.


The parser is responsible for converting raw Rust source code into a structured
form which is easier for the compiler to work with, usually called an *Abstract
Syntax Tree*. The bulk of the parser lives in the [libsyntax] crate.
Copy link
Contributor

Choose a reason for hiding this comment

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

Link to wikipedia? Maybe pointless?

@Michael-F-Bryan
Copy link
Contributor Author

I just added another commit which points out a couple of (what I perceive to be) the key players in libsyntax. I wasn't really sure what to link to when mentioning the specific modules/types, so I linked to their source files.

What things would someone need to know when either working on the parser or trying to use the parser (e.g. because you're using rustc as a library)? Also, are there any easy-ish issues relating to the parser I can work on to get a better feel for libsyntax and how it is used?

@nikomatsakis
Copy link
Contributor

I wasn't really sure what to link to when mentioning the specific modules/types, so I linked to their source files.

Yeah, that's tricky. For now let's do that. Eventually rustdoc would probably be better.

What things would someone need to know when either working on the parser or trying to use the parser

Hmm, good question. I imagine it'd be good to look at a few PRs that modified the parser to see what they had to do. Actually, it might be worth just including a link to those PRs in the guide to help people get oriented.

rust-lang/rust#45047 is such a PR, and here is a link to some of the relevant content.

Some things immediately jump out as worth explaining:

  • What is this eat function?
    • It consumes a token, and queues up the next token as lookahead
  • How do you handle identifiers and keywords?
    • Actually, this PR didn't have to do anything around that. I'd have to find a good example (cc @petrochenkov -- thoughts?)
  • What about constructing spans?
  • What is this crazy pretty printer?
    • It dumps out the AST in human readable form.
    • We have tests that will parse each file in run-pass, pretty print it, and then test that the resulting pretty printed file type checks, so you have to implement this.

@nikomatsakis nikomatsakis mentioned this pull request Jan 25, 2018
8 tasks
@nikomatsakis nikomatsakis merged commit 3b4fab4 into rust-lang:master Jan 25, 2018
@Michael-F-Bryan Michael-F-Bryan deleted the parser branch January 25, 2018 14:50
@nikomatsakis nikomatsakis mentioned this pull request Feb 23, 2018
6 tasks
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