Skip to content

Commit a437390

Browse files
tfidfwastakengitster
authored andcommitted
userdiff: add support for Scheme
Add a diff driver for Scheme-like languages which recognizes top level and local `define` forms, whether it is a function definition, binding, syntax definition or a user-defined `define-xyzzy` form. Also supports R6RS `library` forms, `module` forms along with class and struct declarations used in Racket (PLT Scheme). Alternate "def" syntax such as those in Gerbil Scheme are also supported, like defstruct, defsyntax and so on. The rationale for picking `define` forms for the hunk headers is because it is usually the only significant form for defining the structure of the program, and it is a common pattern for schemers to have local function definitions to hide their visibility, so it is not only the top level `define`'s that are of interest. Schemers also extend the language with macros to provide their own define forms (for example, something like a `define-test-suite`) which is also captured in the hunk header. Since it is common practice to extend syntax with variants of a form like `module+`, `class*` etc, those have been supported as well. The word regex is a best-effort attempt to conform to R7RS[1] valid identifiers, symbols and numbers. [1] https://small.r7rs.org/attachment/r7rs.pdf (section 2.1) Signed-off-by: Atharva Raykar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 84d06cd commit a437390

18 files changed

+101
-0
lines changed

Documentation/gitattributes.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,8 @@ patterns are available:
845845

846846
- `rust` suitable for source code in the Rust language.
847847

848+
- `scheme` suitable for source code in the Scheme language.
849+
848850
- `tex` suitable for source code for LaTeX documents.
849851

850852

t/t4018-diff-funcname.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ diffpatterns="
4848
python
4949
ruby
5050
rust
51+
scheme
5152
tex
5253
custom1
5354
custom2

t/t4018/scheme-class

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(define book-class%
2+
(class* () object% RIGHT
3+
(field (pages 5))
4+
(field (ChangeMe 5))
5+
(define/public (letters)
6+
(* pages 500))
7+
(super-new)))

t/t4018/scheme-def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(def (some-func x y z) RIGHT
2+
(let ((a x)
3+
(b y))
4+
(ChangeMe a b)))

t/t4018/scheme-def-variant

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(defmethod {print point} RIGHT
2+
(lambda (self)
3+
(with ((point x y) self)
4+
(printf "{ChangeMe x:~a y:~a}~n" x y))))

t/t4018/scheme-define-slash-public

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(define bar-class%
2+
(class object%
3+
(field (info 5))
4+
(define/public (foo) RIGHT
5+
(+ info 42)
6+
(* info ChangeMe))
7+
(super-new)))

t/t4018/scheme-define-syntax

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(define-syntax define-test-suite RIGHT
2+
(syntax-rules ()
3+
((_ suite-name (name test) ChangeMe ...)
4+
(define suite-name
5+
(let ((tests
6+
`((name . ,test) ...)))
7+
(lambda ()
8+
(run-suite 'suite-name tests)))))))

t/t4018/scheme-define-variant

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(define* (some-func x y z) RIGHT
2+
(let ((a x)
3+
(b y))
4+
(ChangeMe a b)))

t/t4018/scheme-library

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(library (my-helpers id-stuff) RIGHT
2+
(export find-dup)
3+
(import (ChangeMe))
4+
(define (find-dup l)
5+
(and (pair? l)
6+
(let loop ((rest (cdr l)))
7+
(cond
8+
[(null? rest) (find-dup (cdr l))]
9+
[(bound-identifier=? (car l) (car rest))
10+
(car rest)]
11+
[else (loop (cdr rest))])))))

t/t4018/scheme-local-define

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(define (higher-order)
2+
(define local-function RIGHT
3+
(lambda (x)
4+
(car "this is" "ChangeMe"))))

0 commit comments

Comments
 (0)