-
Notifications
You must be signed in to change notification settings - Fork 117
Megular Expressions #263
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
Megular Expressions #263
Conversation
3fbfcdd
to
126f9ef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very useful to me modulo comments. See how nice the IsWebRTCDirectMultiaddr
method is now vs compared to master.
I think we should make this package Experimental / Alpha and start using this in go-libp2p. After some experience we can remove the Experimental tag, till then we can keep iterating on a satisfactory api.
493f175
to
47c55fc
Compare
126f9ef
to
6bbe24b
Compare
2a8b8af
to
be1c5ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one unaddresses comment:
#263 (comment)
Support captures export some things wip thinking about public API Think about exposing meg as a public API doc comments Finish rename Add helper for meg and add test add comment for devs
twice as fast without the copy
* much cheaper copies of captures * Add a benchmark * allocate to a slice. Use indexes as handles * cleanup * Add nocapture loop benchmark It's really fast. No surprise * cleanup * nits
* Use Matchable interface * Add Bytes to Matchable interface * feat(x/meg): Support capturing bytes * Export CaptureWithF Can be used by more specific capturers (e.g capture net.AddrIP) * Support Any match, RawValue, and multiple Concatenations * Add CaptureAddrPort
c14016b
to
ae47e22
Compare
ad1932c
to
0c5383d
Compare
"github.com/multiformats/go-multiaddr/x/meg" | ||
) | ||
|
||
func CaptureAddrPort(network *string, ipPort *netip.AddrPort) (capturePattern meg.Pattern) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this?
I'd prefer a method in manet
that returns (network string, ipPort netip.AddrPort)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This composes better. You can use this and capture other parts of the multiaddr in a single pass.
We don't need this, but I think it's helpful to demonstrate this pattern.
This looks good except for this comment: #263 (comment) I'll approve once we resolve that. |
The state machine handling was modified to deprioritize the `matchAny` path when alternatives exist, resulting in less greedy matching behavior when using Any patterns.
A very simple regular expression matcher for Multiaddr components. Supports capturing values. Matches in linear time (no back tracking).
The core logic is about 100 LOC. The sugar to make it nicer to use is about another 100 LOC.
Motivation
If we are going to treat Multiaddrs as encoding, then we need to make it more ergonomic to parse multiaddrs. Right now we have a lot of somewhat wrong manual parsers using
ForEach
. This should be able to replace those, make it cleaner, and most importantly make them obviously correct.In draft while I try this out in go-libp2p.
Example
Parsing a WebTransport Multiaddr
m
.