aboutsummaryrefslogtreecommitdiff
path: root/module/c/parse.scm
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--module/c/parse.scm19
1 files changed, 19 insertions, 0 deletions
diff --git a/module/c/parse.scm b/module/c/parse.scm
index d923e5b1..ad716132 100644
--- a/module/c/parse.scm
+++ b/module/c/parse.scm
@@ -3,6 +3,9 @@
:use-module (srfi srfi-1)
:use-module (srfi srfi-71)
:use-module (ice-9 match)
+ :use-module ((rnrs io ports)
+ :select (string->bytevector make-transcoder utf-8-codec))
+ :use-module (rnrs bytevectors)
:export (parse-lexeme-tree))
;;; Rename this
@@ -52,6 +55,14 @@
(list else vars) #f)))
vars)))
+;; Converts string to a null-terminated bytevector
+(define* (string->c-string str optional: (transcoder (make-transcoder (utf-8-codec))))
+ (let* ((bv* (string->bytevector str transcoder))
+ (bv (make-bytevector (1+ (bytevector-length bv*)))))
+ (bytevector-copy! bv* 0 bv 0 (bytevector-length bv*))
+ (bytevector-u8-set! bv (bytevector-length bv*) 0)
+ bv))
+
(define (parse-lexeme-tree tree)
(match tree
['() '()]
@@ -149,6 +160,14 @@
,(parse-lexeme-tree b)
,(parse-lexeme-tree c))]
+
+
+
+ ['string #vu8(0)]
+ [('string str) (string->c-string str)]
+ [(('string str) ...)
+ (string->c-string (string-concatenate str))]
+
[('infix args ...)
(let ((r (resolve-order-of-operations
(flatten-infix (cons 'infix args)))))