aboutsummaryrefslogtreecommitdiff
path: root/module/c/parse.scm
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-06-30 00:22:46 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-07 21:17:22 +0200
commite0b3406a8c0fa27345883adb94fd55e1955febd7 (patch)
tree74ba6df94470f2d8467060ed20ad9cd1535cf684 /module/c/parse.scm
parentC-parser #define without body. (diff)
downloadcalp-e0b3406a8c0fa27345883adb94fd55e1955febd7.tar.gz
calp-e0b3406a8c0fa27345883adb94fd55e1955febd7.tar.xz
C-parser add strings.
Diffstat (limited to 'module/c/parse.scm')
-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)))))