view src/ploki/examples/rfc822-fun.pk @ 12518:2d8fe55c6e65 draft default tip

<int-e> learn The password of the month is release incident pilot.
author HackEso <hackeso@esolangs.org>
date Sun, 03 Nov 2024 00:31:02 +0000
parents ac0403686959
children
line wrap: on
line source

#!../ploki
REM adaption of Jeffrey Friedl's RFC 822 email regex
REM (taken from _Mastering Regular Expressions_)

GOTO 1000

FOR esc        KTHX "\\"
FOR Period     KTHX ".!"
FOR OpenBr     KTHX "[!"
FOR CloseBr    KTHX "]!"
FOR OpenParen  KTHX "(!"
FOR CloseParen KTHX ")!"
FOR NonASCII   KTHX "\x80-\xff"
FOR ctl        KTHX "\000-\037"
FOR CRlist     KTHX "\n\015"

FOR qtext        KTHX "'^\V@esc()\V@NonASCII()\V@CRlist()\"'"
FOR dtext        KTHX "'^\V@esc()\V@NonASCII()\V@CRlist()[]'"
FOR quoted$pair  KTHX @esc() _ "'^\V@NonASCII()'"

FOR ctext    KTHX "'^\V@esc()\V@NonASCII()\V@CRlist())('"

FOR Cnested  KTHX @OpenParen() _ @ctext() _ "*(\V@quoted$pair()\V@ctext()*)*" _ @CloseParen()

FOR comment  KTHX @OpenParen() _ @ctext() _ "*((\V@quoted$pair()|\V@Cnested())\V@ctext()*)*" _ @CloseParen()

FOR X          KTHX "' \t'*(\V@comment()' \t'*)*"

FOR atom$char  KTHX "'^() <>\\@,;:\".\V@esc()[]\V@ctl()\V@NonASCII()'"
FOR atom       KTHX "<\V@atom$char()+>"

FOR quoted$str  KTHX "\"\V@qtext()*(\V@quoted$pair()\V@qtext()*)*\""

FOR word        KTHX "(\V@atom()|\V@quoted$str())"

FOR domain$ref  KTHX @atom()

FOR domain$lit  KTHX @OpenBr() _ "(\V@dtext()|\V@quoted$pair())*" _ @CloseBr()

FOR sub$domain  KTHX "(\V@domain$ref()|\V@domain$lit())" _ @X()

FOR domain  KTHX @sub$domain() _ "(\V@Period()\V@X()\V@sub$domain())*"

FOR route   KTHX "@" _ @X() _ @domain() _ "(,\V@X()\V@domain())*:!" _ @X()

FOR local$part  KTHX @word() _ @X() _ "(\V@Period()\V@X()\V@word()\V@X())*"

FOR addr$spec    KTHX @local$part() _ "@" _ @X() _ @domain()

FOR route$addr   KTHX "<!(\V@route())?\V@addr$spec()>!"

FOR phrase$ctl   KTHX "\000-\010\012-\037"

FOR phrase$char  KTHX "'^()<>@,;:\".\V@esc()[]\V@NonASCII()\V@phrase$ctl()'"

FOR phrase       KTHX @word() _ @phrase$char() _ "*((\V@comment()|\V@quoted$str())\V@phrase$char()*)*"

FOR mailbox  KTHX @X() _ "(\V@addr$spec()|\V@phrase()\V@route$addr())"


1000 REM *** main code ***

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