Skip to content

Commit

Permalink
eval: handle the case when code only contains the #lang line
Browse files Browse the repository at this point in the history
  • Loading branch information
yfzhe committed Jan 14, 2024
1 parent db9fc9e commit dcbe7da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion eval-bot/eval.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
;; access its value as `read-syntax` which read code in interactive mode.

(define (split-code code)
(match (regexp-match #rx"^#lang (.+)\n(.+)" code)
(match (regexp-match #rx"^#lang (.+)\n?(.*)" code)
[(list _ lang body)
(values (string->symbol lang) body)]
[_
Expand Down
22 changes: 9 additions & 13 deletions eval-bot/main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
[(regexp #rx"^/help")
(help message)]
[(regexp #px"^/eval\\b(@[a-z_]+)?(.+)$" (list _ _ code))
(eval message (string-trim code))]
(eval message (string-trim code) 'racket)]
[(regexp #px"^/eval_chez\\b(@[a-z_]+)?(.+)$" (list _ _ code))
(eval-chez message (string-trim code))]
(eval message (string-trim code) 'chez)]
[_
(cond
[(equal? (ref (message : message) .chat .type)
Expand Down Expand Up @@ -72,19 +72,15 @@ END
#:parse-mode "MarkdownV2"
#:text "Not supported command"))

(define (eval message code)
(define result (eval-code code))
;; mode: 'racket or 'chez
(define (eval message code mode)
(define result
(match mode
['racket (eval-code code)]
['chez (eval-code/chez code)]))
(make-response #:chat-id (ref (message : message) .chat .id)
#:reply (make-reply-params
#:message-id (ref (message : message) .id))
#:parse-mode "HTML"
#:text result))

(define (eval-chez message code)
(define result (eval-code/chez code))
(make-response #:chat-id (ref (message : message) .chat .id)
#:reply (make-reply-params
#:message-id (ref (message : message) .id))
#:message-id (message-id message))
#:parse-mode "HTML"
#:text result))

Expand Down

0 comments on commit dcbe7da

Please sign in to comment.