| | |
| | |
| | |
| | |
| |
|
| | import regex ; |
| |
|
| |
|
| | |
| | .whitespace-chars = " " " " " |
| | " ; |
| |
|
| | |
| | .whitespace = $(.whitespace-chars:J="") ; |
| |
|
| |
|
| | |
| | |
| | rule whitespace-chars ( ) |
| | { |
| | return $(.whitespace-chars) ; |
| | } |
| |
|
| |
|
| | |
| | |
| | rule whitespace ( ) |
| | { |
| | return $(.whitespace) ; |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | rule chars ( |
| | string |
| | ) |
| | { |
| | local result ; |
| | while $(string) |
| | { |
| | local s = [ MATCH (.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.*) : $(string) ] ; |
| | string = $(s[9]) ; |
| | result += $(s[1-8]) ; |
| | } |
| |
|
| | |
| | while $(result[1]) && ! $(result[-1]) |
| | { |
| | result = $(result[1--2]) ; |
| | } |
| |
|
| | return $(result) ; |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | rule abbreviate ( string ) |
| | { |
| | local r = $(.abbreviated-$(string)) ; |
| | if $(r) |
| | { |
| | return $(r) ; |
| | } |
| | |
| | else if ! [ MATCH (....) : $(string) ] |
| | { |
| | .abbreviated-$(string) = $(string) ; |
| | return $(string) ; |
| | } |
| | else |
| | { |
| | |
| | local s1 = [ MATCH ^(.)(.*) : $(string) ] ; |
| |
|
| | |
| | local s2 = [ MATCH ^(.*)ing$ : $(s1[2]) ] ; |
| | s2 ?= $(s1[2]) ; |
| |
|
| | |
| | local last = "" ; |
| | for local c in [ chars $(s2) ] |
| | { |
| | if $(c) != $(last) |
| | { |
| | r += $(c) ; |
| | last = $(c) ; |
| | } |
| | } |
| | s2 = $(r:J="") ; |
| |
|
| | |
| | s2 = [ regex.replace $(s2) [AEIOUaeiou] "" ] ; |
| |
|
| | |
| | s2 = [ MATCH ^(.?.?.?.?) : $(s2) ] ; |
| |
|
| | |
| | s2 = $(s1[1])$(s2) ; |
| |
|
| | .abbreviated-$(string) = $(s2) ; |
| | return $(s2) ; |
| | } |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | rule join ( |
| | strings * |
| | : separator ? |
| | ) |
| | { |
| | separator ?= "" ; |
| | return $(strings:J=$(separator)) ; |
| | } |
| |
|
| |
|
| | |
| | |
| | rule words ( |
| | string |
| | : whitespace * |
| | ) |
| | { |
| | whitespace = $(whitespace:J="") ; |
| | whitespace ?= $(.whitespace) ; |
| | local w = ; |
| | while $(string) |
| | { |
| | string = [ MATCH "^[$(whitespace)]*([^$(whitespace)]*)(.*)" : $(string) ] ; |
| | if $(string[1]) && $(string[1]) != "" |
| | { |
| | w += $(string[1]) ; |
| | } |
| | string = $(string[2]) ; |
| | } |
| | return $(w) ; |
| | } |
| |
|
| |
|
| | |
| | |
| | rule is-whitespace ( |
| | string ? |
| | ) |
| | { |
| | if ! $(string) { return true ; } |
| | else if $(string) = "" { return true ; } |
| | else if [ MATCH "^([$(.whitespace)]+)$" : $(string) ] { return true ; } |
| | else { return ; } |
| | } |
| |
|
| | rule __test__ ( ) |
| | { |
| | import assert ; |
| | assert.result a b c : chars abc ; |
| |
|
| | assert.result rntm : abbreviate runtime ; |
| | assert.result ovrld : abbreviate overload ; |
| | assert.result dbg : abbreviate debugging ; |
| | assert.result async : abbreviate asynchronous ; |
| | assert.result pop : abbreviate pop ; |
| | assert.result aaa : abbreviate aaa ; |
| | assert.result qck : abbreviate quack ; |
| | assert.result sttc : abbreviate static ; |
| |
|
| | |
| | assert.result a : chars a ; |
| | assert.result : chars "" ; |
| | assert.result a b c d e f g h : chars abcdefgh ; |
| | assert.result a b c d e f g h i : chars abcdefghi ; |
| | assert.result a b c d e f g h i j : chars abcdefghij ; |
| | assert.result a b c d e f g h i j k : chars abcdefghijk ; |
| |
|
| | assert.result a//b/c/d : join a "" b c d : / ; |
| | assert.result abcd : join a "" b c d ; |
| |
|
| | assert.result a b c : words "a b c" ; |
| |
|
| | assert.true is-whitespace " " ; |
| | assert.false is-whitespace " a b c " ; |
| | assert.true is-whitespace "" ; |
| | assert.true is-whitespace ; |
| | } |
| |
|