Skip to content

Conversation

@c42f
Copy link
Member

@c42f c42f commented Oct 2, 2022

JuliaSyntax.parse() and JuliaSyntax.parseall() were generally pretty inconvenient to use.

This change reworks what I had called parseall() to be more similar to Meta.parse() and adds parseall() and parseatom() in analogy to the Base.Meta versions of these functions.

The lower level function parse!() is provided to work with ParseStream for cases where more control is required.

`parse()` and `parseall()` were generally pretty inconvenient to use.

This change reworks what I had called `parseall()` to be more similar to
`Meta.parse()` and adds `parseall()` and `parseatom()` in analogy to the
`Base.Meta` versions of these functions.

The lower level function `parse!()` is provided to work with
`ParseStream` for cases where more control is required.
@c42f
Copy link
Member Author

c42f commented Oct 2, 2022

I'm keen for any reviews on this. @pfitzseb if you have time? :-)

Copy link
Member

@pfitzseb pfitzseb left a comment

Choose a reason for hiding this comment

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

Looks good to me. Do you think it's worth adding a 1-arg JuliaSyntax.parse(text) = JuliaSyntax.parse(Expr, text) convenience functions?

Comment on lines 61 to 62
`(tree, diagnostics)`. The `io` position will be set to the next byte of input
after parsing.
Copy link
Member

Choose a reason for hiding this comment

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

"to the first unparsed byte of input" or something like that (is that even correct when the whole io content is consumed?)? "next byte" without any context could be kinda confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah this is so hard to word in a way which is clear and correct. How about

"When parse! returns, the stream io is positioned directly after the last byte which was consumed during parsing."

ParseStream(ptr::Ptr{UInt8}, len::Integer, index::Integer=1; version=VERSION)
Construct a `ParseStream` from source `text` which may come in various forms -
a string, an `IO` object, or a buffer of bytes. In the case that the buffer is
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we have an official IO interface. Do you think it'd make sense to list the requirements somewhere (in particular, seekability comes to mind)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it makes sense. I thought I'd done this, but it's in the docs for parse!() I'll put it here too

Co-authored-by: Sebastian Pfitzner <pfitzseb@gmail.com>
@c42f
Copy link
Member Author

c42f commented Oct 2, 2022

Thanks for taking a look!

Do you think it's worth adding a 1-arg JuliaSyntax.parse(text) = JuliaSyntax.parse(Expr, text) convenience functions?

I didn't do this because I'm not sure what the right default is. Expr is ok but doesn't offer anything more than Meta.parse() so I feel like SyntaxNode might be better.

c42f and others added 2 commits October 3, 2022 11:18
@c42f
Copy link
Member Author

c42f commented Oct 3, 2022

I did a bunch of doc cleanups and a couple of minor tweaks. Should be good to go I guess.

@c42f c42f merged commit 6465cce into main Oct 4, 2022
@c42f c42f deleted the c42f/parse-api-update branch October 4, 2022 04:28
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