diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-03 12:36:35 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-07 21:31:32 +0200 |
commit | cba504b509cd59f376063f6e590362b197147a2c (patch) | |
tree | 954e90b0053ab4c0247ef242607654c862d02e48 /module/c/trigraph.scm | |
parent | Merge branch 'new-object-system' into c-parser (diff) | |
download | calp-cba504b509cd59f376063f6e590362b197147a2c.tar.gz calp-cba504b509cd59f376063f6e590362b197147a2c.tar.xz |
Major work.
Diffstat (limited to 'module/c/trigraph.scm')
-rw-r--r-- | module/c/trigraph.scm | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/module/c/trigraph.scm b/module/c/trigraph.scm new file mode 100644 index 00000000..197e01a4 --- /dev/null +++ b/module/c/trigraph.scm @@ -0,0 +1,24 @@ +(define-module (c trigraph) + :use-module (ice-9 regex) + :export (replace-trigraphs)) + +(define rx (make-regexp "\\?\\?([=\\(\\)'!<>/-])")) + +(define (proc m) + (case (string-ref (match:substring m 2) 0) + ((#\=) "#") + ((#\() "[") + ((#\)) "]") + ((#\') "^") + ((#\<) "{") + ((#\>) "}") + ((#\!) "|") + ((#\-) "~") + ((#\/) "\\"))) + +(define (replace-trigraphs string) + (call-with-output-string + (lambda (port) + (regexp-substitute/global + port rx string + 'pre proc 'post)))) |