/usr/share/axiom-20170501/src/algebra/CCLASS.spad is in axiom-source 20170501-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | )abbrev domain CCLASS CharacterClass
++ Author: Stephen M. Watt
++ Date Created: July 1986
++ Date Last Updated: June 20, 1991
++ Description:
++ This domain allows classes of characters to be defined and manipulated
++ efficiently.
CharacterClass() : SIG == CODE where
SIG ==> Join(SetCategory, ConvertibleTo String,
FiniteSetAggregate Character, ConvertibleTo List Character)
with
charClass: String -> %
++ charClass(s) creates a character class which contains
++ exactly the characters given in the string s.
charClass: List Character -> %
++ charClass(l) creates a character class which contains
++ exactly the characters given in the list l.
digit: constant -> %
++ digit() returns the class of all characters
++ for which digit? is true.
hexDigit: constant -> %
++ hexDigit() returns the class of all characters for which
++ hexDigit? is true.
upperCase: constant -> %
++ upperCase() returns the class of all characters for which
++ upperCase? is true.
lowerCase: constant -> %
++ lowerCase() returns the class of all characters for which
++ lowerCase? is true.
alphabetic : constant -> %
++ alphabetic() returns the class of all characters for which
++ alphabetic? is true.
alphanumeric: constant -> %
++ alphanumeric() returns the class of all characters for which
++ alphanumeric? is true.
CODE ==> add
Rep := IndexedBits(0)
N := size()$Character
a, b: %
digit() == charClass "0123456789"
hexDigit() == charClass "0123456789abcdefABCDEF"
upperCase() == charClass "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lowerCase() == charClass "abcdefghijklmnopqrstuvwxyz"
alphabetic() == union(upperCase(), lowerCase())
alphanumeric() == union(alphabetic(), digit())
a = b == a =$Rep b
member?(c, a) == a(ord c)
union(a,b) == Or(a, b)
intersect (a,b) == And(a, b)
difference(a,b) == And(a, Not b)
complement a == Not a
convert(cl):String ==
construct(convert(cl)@List(Character))
convert(cl:%):List(Character) ==
[char(i) for i in 0..N-1 | cl.i]
charClass(s: String) ==
cl := new(N, false)
for i in minIndex(s)..maxIndex(s) repeat cl(ord s.i) := true
cl
charClass(l: List Character) ==
cl := new(N, false)
for c in l repeat cl(ord c) := true
cl
coerce(cl):OutputForm == (convert(cl)@String)::OutputForm
-- Stuff to make a legal SetAggregate view
# a == (n := 0; for i in 0..N-1 | a.i repeat n := n+1; n)
empty():% == charClass []
brace():% == charClass []
insert_!(c, a) == (a(ord c) := true; a)
remove_!(c, a) == (a(ord c) := false; a)
inspect(a) ==
for i in 0..N-1 | a.i repeat
return char i
error "Cannot take a character from an empty class."
extract_!(a) ==
for i in 0..N-1 | a.i repeat
a.i := false
return char i
error "Cannot take a character from an empty class."
map(f, a) ==
b := new(N, false)
for i in 0..N-1 | a.i repeat b(ord f char i) := true
b
temp: % := new(N, false)$Rep
map_!(f, a) ==
fill_!(temp, false)
for i in 0..N-1 | a.i repeat temp(ord f char i) := true
copyInto_!(a, temp, 0)
parts a ==
[char i for i in 0..N-1 | a.i]
|