all.rpl 1.38 KB
Newer Older
1
2
3
4
-- -*- Mode: rpl; -*-                                                                               
--
-- all.rpl    Collections of things
--
5
-- © Copyright IBM Corporation 2017, 2018.
6
7
8
9
10
11
-- LICENSE: MIT License (https://opensource.org/licenses/mit-license.html)
-- AUTHOR: Jamie A. Jennings

package all
import ts, date, time, net, num, id, word

Jamie Jennings's avatar
Jamie Jennings committed
12
13
-- Here are some ways of distinguishing identifiers from ordinary words.  These are
-- ad hoc patterns, and they may or may not meet your needs.
14
alias special_char = [_$]
15
16
17
18
19
20
21
22
alias id_char = [[:alnum:] special_char]
alias has_special_chars = { special_char+ [:alpha:] id_char* } /
			  { [:alpha:] [:alnum:]* special_char id_char* !<":"}

-- Starts with two uppercase letters, OR, 1+ uppercase and contains numbers/special
alias starts_with_uppercase = { {[:upper:]{2,} id_char*}
			      / {[:upper:]+ [[:digit:] special_char]+ id_char*} } ~

23
24
25
alias numbers_inside = { [[:alpha:] special_char]+ [:digit:] id_char* }

identifier = starts_with_uppercase / numbers_inside / has_special_chars / id.dotted / id.guid
Jamie Jennings's avatar
Jamie Jennings committed
26

27
28
29
30
31
32
33
punct = [:punct:]
unmatched = [:^space:]+

thing = ts.any /					    -- complete timestamps
	date.any /
	time.any / 
	net.any /
34
	identifier /					    -- will match hex like 'C1'
35
	{![[a-f] [A-F]] num.any} /
36
37
38
39
	word.any /
	punct /
	unmatched

40
things = findall:thing
41
42


43
44
-- test thing includes word.any "face", "a"
-- test thing includes num.float "6.0", "-3.14"
45