Thanks to visit codestin.com
Credit goes to github.com

Skip to content

parse.ts now exports parseFromEvents [API change].#112

Open
jgm wants to merge 1 commit intomainfrom
parseFromEvents
Open

parse.ts now exports parseFromEvents [API change].#112
jgm wants to merge 1 commit intomainfrom
parseFromEvents

Conversation

@jgm
Copy link
Owner

@jgm jgm commented May 9, 2025

This takes an Event[] parameter, which can be produced from an EventParser using Array.from().

parse is now defined in terms of parseFromEvents.

This will help users who need both the parsed content and the event stream. Previously they had to do the parsing twice, once using parseEvents and once with parse (which itself calls parseEvents). This can now be avoided; parseEvents can be called once and then parseFromEvents can be called using the extracted events.

Users of the old parse function should not see any changes.

Note: it is possible that there could be performance effects due to the reification of the Event array, since the previous version of parse consumed Events as they were streamedfrom parseEvents rather than taking an array of all the Events as parameter. However, in our own benchmarks we don't see any significant differences.

Closes #111.

This takes an `Event[]` parameter, which can be produced from
an `EventParser` using `Array.from()`.

`parse` is now defined in terms of `parseFromEvents`.

This will help users who need both the parsed content and the
event stream. Previously they had to do the parsing twice, once
using `parseEvents` and once with `parse` (which itself calls
`parseEvents`). This can now be avoided; `parseEvents` can be
called once and then `parseFromEvents` can be called using the
extracted events.

Users of the old `parse` function should not see any changes.

Note: it is possible that there could be performance effects due to the
reification of the Event array, since the previous version of `parse`
consumed Events as they were streamedfrom `parseEvents` rather than
taking an array of all the Events as parameter. However, in our own
benchmarks we don't see any significant differences.

Closes #111.
Copy link
Contributor

@matklad matklad left a comment

Choose a reason for hiding this comment

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

LGTM! If we worry about performance, we can type events as Iterable<Event>, so that both an array and a parser work, but personally I'd be happier with array as that is simpler.

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.

Unified djot.parse() to optionally return both - ast and events

2 participants

Comments