ldthomas / apg-js2-exp Goto Github PK
View Code? Open in Web Editor NEWDeprecated. Use the updated apg-js instead. A pattern-matching engine similar to RegExp but uses an ABNF pattern syntax and APG parsers.
Deprecated. Use the updated apg-js instead. A pattern-matching engine similar to RegExp but uses an ABNF pattern syntax and APG parsers.
Since the dependencies was specified as *
, the new release of these libs breaks all the 1.x versions of this library. I would advise to publish a new 1.x release with the dependencies looked to a version that works, e.g. "apg": "^2.2.2", "apg-lib": "^2.1.5"
.
LPT: if you just use npm install --save _
and never modify the package.json manually, this will be provided automatically for you
Hi!
I'm trying to use this package in a react native app but due to the dependency on apg
, this won't work. However, I don't see that package being used in the code (only app-lib
).
Could we make the dependency on apg
a dev dependency, or maybe remove it altogether?
It would be nice if leading whitespace could be automatically stripped so that you can use it with ES6 template strings in a nice way.
e.g.
new ApgExp(`
number = [ "-" ] int [ frac ] [ exp ]
digit0-9 = %x30-39
digit1-9 = %x31-39
exp = ( "e" / "E" ) [ "-" / "+" ] 1*digit0-9
frac = "." 1*digit0-9
int = "0" / ( digit1-9 *digit0-9 )
`)
Hi, I'm trying to parse XRIs with this library. I create an ApgExp
instance with following grammar (mostly copy-and-pasted from the XRI 3.0 ABNF spec):
xri = xri-hier-part [ "?" iquery ] [ "#" ifragment ]
xri-reference = xri
/ relative-xri-ref
relative-xri-ref = relative-xri-part [ "?" iquery ] [ "#" ifragment ]
relative-xri-part = xri-path-abs
/ xri-path-noscheme
/ ipath-empty
xri-hier-part = xri-authority xri-path-abempty
xri-authority = global-subseg *subseg
subseg = global-subseg
/ local-subseg
/ xref
global-subseg = gcs-char [ local-subseg / xref / literal ]
local-subseg = lcs-char [ xref / literal ]
gcs-char = "=" / "@" / "+" / "$"
lcs-char = "*" / "!"
literal = 1*xri-pchar
literal-nc = 1*xri-pchar-nc
xref = "(" [ xref-value ] ")"
xref-value = xri-reference
/ IRI;iri
xri-path = xri-path-abempty
/ xri-path-abs
/ xri-path-noscheme
/ ipath-empty
xri-path-abempty = *( "/" xri-segment )
xri-path-abs = "/" [ xri-segment-nz *( "/" xri-segment ) ]
xri-path-noscheme = xri-segment-nc *( "/" xri-segment )
xri-segment = [ literal ] *subseg
xri-segment-nz = ( literal / subseg ) *subseg
xri-segment-nc = ( literal-nc / subseg ) *subseg
xri-pchar = iunreserved / pct-encoded / xri-sub-delims / ":"
xri-pchar-nc = iunreserved / pct-encoded / xri-sub-delims
xri-reserved = xri-gen-delims / xri-sub-delims
xri-gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "(" / ")"
/ gcs-char / lcs-char
xri-sub-delims = "&" / ";" / "," / "'"
IRI = scheme ":" ihier-part [ "?" iquery ]
[ "#" ifragment ]
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
ihier-part = "//" iauthority ipath-abempty
/ ipath-abs
/ ipath-rootless
/ ipath-empty
iauthority = [ iuserinfo "@" ] ihost [ ":" port ]
iuserinfo = *( iunreserved / pct-encoded / sub-delims / ":" )
ihost = IP-literal / IPv4address / ireg-name
IP-literal = "[" ( IPv6address / IPvFuture ) "]"
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
IPv6address = 6( h16 ":" ) ls32
/ "::" 5( h16 ":" ) ls32
/ [ h16 ] "::" 4( h16 ":" ) ls32
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
/ [ *4( h16 ":" ) h16 ] "::" ls32
/ [ *5( h16 ":" ) h16 ] "::" h16
/ [ *6( h16 ":" ) h16 ] "::"
ls32 = ( h16 ":" h16 ) / IPv4address
h16 = 1*4HEXDIG
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet = DIGIT ; 0-9
/ %x31-39 DIGIT ; 10-99
/ "1" 2DIGIT ; 100-199
/ "2" %x30-34 DIGIT ; 200-249
/ "25" %x30-35 ; 250-255
ireg-name = *( iunreserved / pct-encoded / sub-delims )
port = *DIGIT
ipath-abempty = *( "/" isegment )
ipath-abs = "/" [ isegment-nz *( "/" isegment ) ]
ipath-rootless = isegment-nz *( "/" isegment )
ipath-empty = 0ipchar;0<ipchar>
isegment = *ipchar
isegment-nz = 1*ipchar
iquery = *( ipchar / iprivate / "/" / "?" )
iprivate = %xE000-F8FF / %xF0000-FFFFD / %x100000-10FFFD
ifragment = *( ipchar / "/" / "?" )
ipchar = iunreserved / pct-encoded / sub-delims / ":" / "@"
iunreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" / ucschar
pct-encoded = "%" HEXDIG HEXDIG
ucschar = %xA0-D7FF / %xF900-FDCF / %xFDF0-FFEF
/ %x10000-1FFFD / %x20000-2FFFD / %x30000-3FFFD
/ %x40000-4FFFD / %x50000-5FFFD / %x60000-6FFFD
/ %x70000-7FFFD / %x80000-8FFFD / %x90000-9FFFD
/ %xA0000-AFFFD / %xB0000-BFFFD / %xC0000-CFFFD
/ %xD0000-DFFFD / %xE1000-EFFFD
reserved = gen-delims / sub-delims
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
ALPHA = %d97-122 / %d65-90
DIGIT = %d48-57
HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
Then passing some valid XRIs into exec
:
argument for exec |
result[0] |
result.input |
---|---|---|
@example/(@example/foo) |
@example/(@example/foo) |
@example/(@example/foo) |
@example/(@example/foo?query) |
@example/ |
@example/(@example/foo?query) |
@example/(@example/foo)?query |
@example/(@example/foo)?query |
@example/(@example/foo)?query |
@example/(@example/foo?query)?query |
@example/ |
@example/(@example/foo?query)?query |
I expect that result[0]
and result.input
are the same string, but as for 2nd and 4th XRIs, those are not same.
Why? Am I misunderstanding the grammar or the apg-exp
's API?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.