Merge pull request #7 from bennn/no-colon

[no-colon] re-export bindings without the colon
This commit is contained in:
Benjamin Greenman 2015-12-16 03:38:50 -05:00
commit 6d5902db3a
7 changed files with 52 additions and 3 deletions

View File

@ -2,6 +2,7 @@ trivial
===
[![Build Status](https://travis-ci.org/bennn/trivial.svg)](https://travis-ci.org/bennn/trivial)
[![Coverage Status](https://coveralls.io/repos/bennn/trivial/badge.svg?branch=master&service=github)](https://coveralls.io/github/bennn/trivial?branch=master)
[![Scribble](https://img.shields.io/badge/Docs-Scribble-blue.svg)](http://pkg-build.racket-lang.org/doc/trivial/index.html)
This library provides "smarter" versions of Typed Racket standard library functions.
For example:

7
format/no-colon.rkt Normal file
View File

@ -0,0 +1,7 @@
#lang typed/racket/base
(provide (all-from-out trivial/format))
(require (rename-in trivial/format
[format: format]
[printf: printf]))

9
math/no-colon.rkt Normal file
View File

@ -0,0 +1,9 @@
#lang typed/racket/base
(provide (all-from-out trivial/math))
(require (rename-in trivial/math
[+: +]
[-: -]
[*: *]
[/: /]))

14
no-colon.rkt Normal file
View File

@ -0,0 +1,14 @@
#lang typed/racket/base
;; Provides the same bindings as `trivial/main`,
;; but without the trailing colon.
(provide
(all-from-out trivial/format/no-colon)
(all-from-out trivial/math/no-colon)
(all-from-out trivial/regexp/no-colon))
(require
trivial/format/no-colon
trivial/math/no-colon
trivial/regexp/no-colon)

View File

@ -106,7 +106,7 @@
(define-for-syntax (group-error str reason)
(raise-argument-error
errloc-key
(format "Valid regexp pattern (contains unmatched ~a)" reason)
(format "Valid regexp pattern (unmatched ~a)" reason)
str))
;; Dispatch for counting groups

14
regexp/no-colon.rkt Normal file
View File

@ -0,0 +1,14 @@
#lang typed/racket/base
(provide (all-from-out trivial/regexp))
(require (rename-in trivial/regexp
[regexp-match: regexp-match]
[regexp: regexp]
[pregexp: pregexp]
[byte-regexp: byte-regexp]
[byte-pregexp: byte-pregexp]
[define-regexp: define-regexp]
[define-pregexp: define-pregexp]
[define-byte-regexp: define-byte-regexp]
[define-byte-pregexp: define-byte-pregexp]))

View File

@ -3,14 +3,17 @@
@require[scribble/eval]
@require[scriblib/footnote]
@title[#:tag "top"]{@bold{Trivial: Solving the easiest type-checking problems}}
@title[#:tag "top"]{Trivial: Solving the easiest type-checking problems}
@author[@hyperlink["https://github.com/bennn"]{Ben Greenman}]
@defmodule[trivial]
@(define trivial-eval (make-base-eval #:lang 'typed/racket/base '(begin (require trivial))))
This library exports a collection of @hyperlink["http://www.greghendershott.com/fear-of-macros/"]{macros} that implement statically-checked interfaces to standard library functions.
All exported macros are named with a trailing colon (meant as a hint that some extra type-checking may happen at the call site).
All exported macros are named with a trailing colon (meant as a hint that some extra type-checking may happen at the call site).@note{
Not a fan of the colon convention? @racket[trivial/no-colon] provides the same identifiers, colon-free.
Same goes for each sub-collection, for instance you can require @racket[trivial/math/no-colon].
}
@emph{Hidden Agenda:}
@ -67,6 +70,7 @@ In other words, the result is one string for the matched substring and an unknow
(U #f (List String String)))
(ann (regexp-match: #"(la(m*)bda)" #"lam")
(U #f (List Bytes Bytes Bytes)))
(regexp-match: "(bad))group" "")
]
@emph{Note:} the regular expression @racket{|} operator is not currently supported because it can nullify some groups.