-- -*- Mode: rpl; -*-                                                                               
--
-- id.rpl
--
-- © Copyright IBM Corporation 2017.
-- LICENSE: MIT License (https://opensource.org/licenses/mit-license.html)
-- AUTHOR: Jamie A. Jennings

package id

id1 = { [:alpha:] [[_][:alnum:]]* }			    -- allows dashes
id2 = { [:alpha:] [[_\-][:alnum:]]* }			    -- ... and underscores
id3 = { [:alpha:] [[$_\-][:alnum:]]* }			    -- ... and dollar signs

id = id3
dotted = { id {"." id}+ }

local alias h = [:xdigit:]
guid = {h{8} "-" {h{4} "-"}{3} h{12}}

any = dotted / id / guid

-- test id1 accepts "h", "www", "w1", "w_", "w_w"
-- test id1 rejects "1h", "_www", "w-1", "w$"
-- test id2 accepts "h", "www", "w1", "w_", "w_w", "w-", "w-w", "w-9"
-- test id2 rejects "1h", "_www", "w$"
-- test id3 accepts "h", "www", "w1", "w_", "w_w", "w-", "w-w", "w-9", "w$", "a$b", "a54$d"
-- test id3 rejects "1h", "_www"

-- test dotted accepts "a.b", "a.b.c.d", "charlie.delta_.ep$ilon"
-- test dotted rejects "a", "a..", ".", "_abc", "3x", "abc."

-- test guid accepts "b7ffaed1-a372-4119-bd19-324c7ba52f6a", "aae02a32-fcd1-4fac-9be7-c6d3936b9c51"
-- test guid accepts "b7ffAED1-a372-4119-bd19-324c7ba52f6a"  uppercase hex chars are OK
-- test guid rejects "b7ffaed1X-a372-4119-bd19-324c7ba52f6a" extra char in first group
-- test guid rejects "b7ffaed1-a372-4119X-bd19-324c7ba52f6a" extra char in third group
-- test guid rejects "b7ffaed1-a372-4119-bd1-324c7ba52f6a"   missing char in fourth group
-- test guid rejects "b7ffaed1-a372-4119-bd19-24c7ba52f6a"   missing char in last group
-- test guid rejects "b7ffaed1_a372-4119-bd19-324c7ba52f6a"  underscore not dash
-- test guid rejects "b7fgaed1-a372-4119-bd19-324c7ba52f6a"  non-hex char in first group



