Skip to content

Instantly share code, notes, and snippets.

@drgomesp
Last active December 14, 2015 18:09
Show Gist options
  • Save drgomesp/5126867 to your computer and use it in GitHub Desktop.
Save drgomesp/5126867 to your computer and use it in GitHub Desktop.
XML Shallow Parsing using Greppy API
<?php
// [^<]+
$textScanningExpression =
p()->not('<')->more;
// [^-]*-
$untilHyphen =
p()->not('-')->until->literal('-');
// $untilHyphen(?:[^-]$untilHyphen)*-
$untilTwoHyphens =
$untilHyphen .
p()->silent(
p()->not('-') .
$untilHyphen
) . p()->until->literal('-');
// $untilTwoHyphens>?
$commentCompletionExpression =
$untilTwoHyphens .
p()->literal('>')->optional;
// [^\]]*]([^\]]+])*]+
$rightSquareBrackets =
p()->not(']')->until->capture(
p()->not(']')->literal(']')->more
) . p()->any->literal(']')->more;
@alganet
Copy link

alganet commented Mar 11, 2013

PS: Don't give up on p()! We could have $p() with pure PSR-0 compatibility, or Greppy::autodefine('function_name') based on the autodefine RFC https://wiki.php.net/rfc/autodefine

@drgomesp
Copy link
Author

Thanks for the contribution.

The gist is updated.

About the p() function, yes, I do want to provide that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment