diff src/ploki/examples/rfc822.pk @ 4223:ac0403686959

<oerjan> rm -rf src/ploki; mv ploki src
author HackBot
date Fri, 20 Dec 2013 22:18:50 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ploki/examples/rfc822.pk	Fri Dec 20 22:18:50 2013 +0000
@@ -0,0 +1,75 @@
+#!../ploki
+REM adaption of Jeffrey Friedl's RFC 822 email regex
+REM (taken from _Mastering Regular Expressions_)
+
+LET $esc        "\\"
+LET $Period     ".!"
+LET $OpenBr     "[!"
+LET $CloseBr    "]!"
+LET $OpenParen  "(!"
+LET $CloseParen ")!"
+LET $NonASCII   "\x80-\xff"
+LET $ctl        "\000-\037"
+LET $CRlist     "\n\015"
+
+LET $qtext        "'^\V$esc\V$NonASCII\V$CRlist\"'"
+LET $dtext        "'^\V$esc\V$NonASCII\V$CRlist[]'"
+LET $quoted$pair  $esc _ "'^\V$NonASCII'"
+
+LET $ctext    "'^\V$esc\V$NonASCII\V$CRlist)('"
+
+LET $Cnested  $OpenParen _ $ctext _ "*(\V$quoted$pair\V$ctext*)*" _ $CloseParen
+
+LET $comment  $OpenParen _ $ctext _ "*((\V$quoted$pair|\V$Cnested)\V$ctext*)*" _ $CloseParen
+
+LET $X          "' \t'*(\V$comment' \t'*)*"
+
+LET $atom$char  "'^() <>\\@,;:\".\V$esc[]\V$ctl\V$NonASCII'"
+LET $atom       "<\V$atom$char+>"
+
+LET $quoted$str  "\"\V$qtext*(\V$quoted$pair\V$qtext*)*\""
+
+LET $word        "(\V$atom|\V$quoted$str)"
+
+LET $domain$ref  $atom
+
+LET $domain$lit  $OpenBr _ "(\V$dtext|\V$quoted$pair)*" _ $CloseBr
+
+LET $sub$domain  "(\V$domain$ref|\V$domain$lit)" _ $X
+
+LET $domain  $sub$domain _ "(\V$Period\V$X\V$sub$domain)*"
+
+LET $route   "@" _ $X _ $domain _ "(,\V$X\V$domain)*:!" _ $X
+
+LET $local$part  $word _ $X _ "(\V$Period\V$X\V$word\V$X)*"
+
+LET $addr$spec    $local$part _ "@" _ $X _ $domain
+
+LET $route$addr   "<!(\V$route)?\V$addr$spec>!"
+
+LET $phrase$ctl   "\000-\010\012-\037"
+
+LET $phrase$char  "'^()<>@,;:\".\V$esc[]\V$NonASCII\V$phrase$ctl'"
+
+LET $phrase       $word _ $phrase$char _ "*((\V$comment|\V$quoted$str)\V$phrase$char*)*"
+
+LET $mailbox  $X _ "(\V$addr$spec|\V$phrase\V$route$addr)"
+
+
+REM ******************
+REM ** test snippet **
+REM ******************
+
+LET status 0
+LET i 1
+FOR main-loop IF i < \ARG
+		IF \ARG:i ~ ("^" _ $mailbox _ "$")
+			"`\V\ARG:i' is syntactically valid.
+		ELSE
+			"`\V\ARG:i' is syntactically invalid.
+			LET status @NEG 1
+		FI
+		LET i += 1
+		NEXT main-loop
+	FI
+	END status