From 62528db6533dbc1c82b4efba24b54295c3ae6a3a Mon Sep 17 00:00:00 2001 From: Jack Firth Date: Wed, 15 Jul 2020 00:12:43 -0700 Subject: [PATCH 1/2] Use racket/base instead of scheme/base --- scribble-lib/scribble/private/manual-tech.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribble-lib/scribble/private/manual-tech.rkt b/scribble-lib/scribble/private/manual-tech.rkt index 3779a824b3..16c0186874 100644 --- a/scribble-lib/scribble/private/manual-tech.rkt +++ b/scribble-lib/scribble/private/manual-tech.rkt @@ -1,4 +1,4 @@ -#lang scheme/base +#lang racket/base (require racket/contract/base "../decode.rkt" "../struct.rkt" From 6a5038b414f9156fe77b6c14fa5f6280e53d5f56 Mon Sep 17 00:00:00 2001 From: Jack Firth Date: Wed, 15 Jul 2020 00:40:41 -0700 Subject: [PATCH 2/2] Improve tech normalization of plural words Motivating use case: `@tech{syntax classes}` should normalize the same as `@tech{syntax class}`. --- .../scribblings/scribble/manual.scrbl | 5 ++++- scribble-lib/scribble/private/manual-tech.rkt | 21 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/scribble-doc/scribblings/scribble/manual.scrbl b/scribble-doc/scribblings/scribble/manual.scrbl index e7cf59c3e4..073833dfcc 100644 --- a/scribble-doc/scribblings/scribble/manual.scrbl +++ b/scribble-doc/scribblings/scribble/manual.scrbl @@ -1791,7 +1791,10 @@ normalized as follows: @item{A trailing ``ies'' is replaced by ``y''.} - @item{A trailing ``s'' is removed.} + @item{A trailing ``es'' is removed if it was preceded by an ``s'', ``x'', + ``z'', ``ch'', or an ``sh''.} + + @item{A trailing ``s'' is removed if it was not preceded by an ``s''.} @item{Consecutive hyphens and whitespaces are all replaced by a single space.} diff --git a/scribble-lib/scribble/private/manual-tech.rkt b/scribble-lib/scribble/private/manual-tech.rkt index 16c0186874..40dc6141d7 100644 --- a/scribble-lib/scribble/private/manual-tech.rkt +++ b/scribble-lib/scribble/private/manual-tech.rkt @@ -28,13 +28,7 @@ (define (*tech make-elem style doc prefix s key normalize?) (let* ([c (decode-content s)] [s (or key (content->string c))] - [s (if normalize? - (let* ([s (string-foldcase s)] - [s (regexp-replace #rx"ies$" s "y")] - [s (regexp-replace #rx"s$" s "")] - [s (regexp-replace* #px"[-\\s]+" s " ")]) - s) - s)] + [s (if normalize? (normalize s) s)] [s (datum-intern-literal s)]) (make-elem style c (list 'tech (doc-prefix doc prefix s))))) @@ -74,3 +68,16 @@ #:normalize? [normalize? #t] . s) (*tech make-link-element #f doc prefix s key normalize?)) + +(define (normalize raw-string) + (define folded (string-foldcase raw-string)) + ;; This logic was derived from the rules for singular and plural words + ;; described here: https://www.ef.com/wwen/english-resources/english-grammar/singular-and-plural-nouns/ + (define singular + (cond + [(regexp-match? #rx"ies$" folded) (regexp-replace #rx"ies$" folded "y")] + [(regexp-match? #rx"(s|x|z|ch|sh)es$" folded) + (regexp-replace #rx"es$" folded "")] + [(regexp-match? #rx"[^s]s%" folded) (regexp-replace #rx"s$" folded "")] + [else folded])) + (regexp-replace* #px"[-\\s]+" singular " "))