Skip to content

Commit 546cc9c

Browse files
committed
added r6rs grammar
1 parent 91367fa commit 546cc9c

File tree

4 files changed

+228
-11
lines changed

4 files changed

+228
-11
lines changed

lib/linguist/heuristics.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,8 @@ disambiguations:
718718
rules:
719719
- language: Scheme
720720
pattern:
721-
- '(?:''[\(\*#]|\w->\w|\.\.\.[\s\)]|\([+\-:<>\/=~\)]|~>|\s:\w|#\()'
722-
- '^\s*\((?:define|import|library|let|set)'
721+
- '(?:''[\(\*#]|\w->\w|\.\.\.[\s\)]|\([+\-:<>\/=~\)]|~>|\s:\w|#\()|#:\w'
722+
- '^\s*\((?:define|import|library|lambda)'
723723
negative_pattern:
724724
- '\(#[\w-]+[!\?]'
725725
- '[\)\]"_]\s+[\*\+\?@]'

samples/Scheme/r6rs.scm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(define-module (statprof)
2+
#:use-module (srfi srfi-1)
3+
#:use-module (srfi srfi-9)
4+
#:use-module (srfi srfi-9 gnu)
5+
#:use-module (ice-9 format)
6+
#:export (statprof-active?
7+
statprof-start
8+
statprof-stop
9+
statprof
10+
gcprof))
11+
12+
13+
(define (sample-stack-procs state stack)
14+
(set-sample-count! state (+ (sample-count state) 1))
15+
16+
(let lp ((frame (stack-ref stack 0))
17+
(len (stack-length stack))
18+
(buffer (buffer state))
19+
(pos (buffer-pos state)))
20+
(define (write-sample sample)
21+
(vector-set! buffer pos sample))
22+
(define (continue pos)
23+
(lp (frame-previous frame) (1- len) buffer pos))
24+
(define (write-sample-and-continue sample)
25+
(write-sample sample)
26+
(continue (1+ pos)))
27+
(cond
28+
((= pos (vector-length buffer))
29+
(lp frame len (expand-buffer buffer) pos))
30+
((or (zero? len) (not frame))
31+
(write-sample #f)
32+
(set-buffer! state buffer)
33+
(set-buffer-pos! state (1+ pos)))
34+
(else
35+
(write-sample-and-continue (frame-instruction-pointer frame))))))
36+
37+
(define* (statprof-display-anomalies #:optional (state
38+
(existing-profiler-state)))

samples/Scheme/r7rs.scm

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
(import (scheme base)
2+
(scheme read)
3+
(scheme write)
4+
(srfi 18)
5+
)
6+
7+
(thread-start!
8+
(make-thread
9+
(lambda ()
10+
(thread-sleep! 1.2)
11+
(display "started thread, this should be written to console")
12+
(newline)
13+
(display "thread done")
14+
(newline)
15+
(flush-output-port (current-output-port)))))
16+
17+
(thread-sleep! 1) ;; Prevent race condition replacing stdout before thread is spawned
18+
(write `(1 2 3))
19+
(define fp (open-output-file "tmp.txt"))
20+
(parameterize
21+
((current-output-port fp))
22+
(write `(4 5 6))
23+
(thread-sleep! 3)
24+
)
25+
(close-port fp)
26+
(write `(7 8 9))
27+
28+
;;; The game of life example from r7rs.
29+
;;; Main program
30+
31+
(import (scheme base)
32+
(only (example life) life)
33+
(rename (prefix (example grid) grid-)
34+
(grid-make make-grid)))
35+
;; Initialize a grid with a glider.
36+
(define grid (make-grid 24 24))
37+
(grid-put! grid 1 1 #t)
38+
(grid-put! grid 2 2 #t)
39+
(grid-put! grid 3 0 #t)
40+
(grid-put! grid 3 1 #t)
41+
(grid-put! grid 3 2 #t)
42+
;; Run for x iterations.
43+
(life grid 80)
44+
45+
46+
(define-library (example life)
47+
(import (except (scheme base) set!))
48+
(cond-expand
49+
(cyclone
50+
(import (scheme write))
51+
(import (example grid))
52+
53+
))
54+
55+
(cond-expand
56+
(cyclone
57+
(export life)
58+
))
59+
60+
(cond-expand
61+
(cyclone
62+
(begin
63+
(define (life-count grid i j)
64+
(define (count i j)
65+
(if (ref grid i j) 1 0))
66+
(+ (count (- i 1) (- j 1))
67+
(count (- i 1) j)
68+
(count (- i 1) (+ j 1))
69+
(count i (- j 1))
70+
(count i (+ j 1))
71+
(count (+ i 1) (- j 1))
72+
(count (+ i 1) j)
73+
(count (+ i 1) (+ j 1))))
74+
)
75+
(begin
76+
(define (life-alive? grid i j)
77+
(case (life-count grid i j)
78+
((3) #t)
79+
((2) (ref grid i j))
80+
(else #f)))
81+
)
82+
83+
)
84+
)
85+
(begin
86+
(define (clear-vt100)
87+
(display
88+
(string
89+
(integer->char #x1B)
90+
#\[
91+
#\H
92+
(integer->char #x1B)
93+
#\[
94+
#\J)))
95+
(define (life-print grid)
96+
(clear-vt100)
97+
(each grid
98+
(lambda (i j v)
99+
(display (if v "*" " "))
100+
(if (= j (- (cols grid) 1))
101+
;(when (= j (- (cols grid) 1))
102+
(newline)))))
103+
(define (life grid iterations)
104+
(do ((i 0 (+ i 1))
105+
(grid0 grid grid1)
106+
(grid1 (make (rows grid) (cols grid))
107+
grid0))
108+
((= i iterations))
109+
(each grid0
110+
(lambda (j k v)
111+
(let ((a (life-alive? grid0 j k)))
112+
(put! grid1 j k a))))
113+
;(set! grid1 j k a))))
114+
(life-print grid1)))))
Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,74 @@
1-
((macro_invocation
2-
(token_tree) @injection.content)
3-
(#set! injection.language "rust")
4-
(#set! injection.include-children))
5-
6-
((macro_rule
7-
(token_tree) @injection.content)
8-
(#set! injection.language "rust")
9-
(#set! injection.include-children))
1+
((comment) @injection.content
2+
(#set! injection.language "comment"))
3+
4+
5+
((regex_literal
6+
(_) @injection.content)
7+
(#set! injection.language "regex"))
8+
9+
(recipe_body
10+
!shebang
11+
(#set! injection.language "bash")
12+
(#set! injection.include-children)) @injection.content
13+
14+
(external_command
15+
(command_body) @injection.content
16+
(#set! injection.language "bash"))
17+
18+
(source_file
19+
(setting "shell" ":=" "[" (string) @_langstr
20+
(#match? @_langstr ".*(powershell|pwsh|cmd).*")
21+
(#set! injection.language "powershell"))
22+
[
23+
(recipe
24+
(recipe_body
25+
!shebang
26+
(#set! injection.include-children)) @injection.content)
27+
28+
(assignment
29+
(expression
30+
(value
31+
(external_command
32+
(command_body) @injection.content))))
33+
])
34+
35+
(source_file
36+
(setting "shell" ":=" "[" (string) @injection.language
37+
(#not-match? @injection.language ".*(powershell|pwsh|cmd).*"))
38+
[
39+
(recipe
40+
(recipe_body
41+
!shebang
42+
(#set! injection.include-children)) @injection.content)
43+
44+
(assignment
45+
(expression
46+
(value
47+
(external_command
48+
(command_body) @injection.content))))
49+
])
50+
51+
(recipe_body
52+
(shebang
53+
(language) @injection.language)
54+
(#not-any-of? @injection.language "python3" "nodejs" "node" "uv")
55+
(#set! injection.include-children)) @injection.content
56+
57+
(recipe_body
58+
(shebang
59+
(language) @_lang)
60+
(#any-of? @_lang "python3" "uv")
61+
(#set! injection.language "python")
62+
(#set! injection.include-children)) @injection.content
63+
64+
(recipe_body
65+
(shebang
66+
(language) @_lang)
67+
(#any-of? @_lang "node" "nodejs")
68+
(#set! injection.language "javascript")
69+
(#set! injection.include-children)) @injection.content
70+
71+
(recipe_body
72+
(shebang) @injection.shebang
73+
(#set! injection.include-children)) @injection.content
74+

0 commit comments

Comments
 (0)