diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-10 23:36:56 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-07-10 23:36:56 +0200 |
commit | f7b18cc72dd5b2ca90b6670dbe81c3ef3204d6d9 (patch) | |
tree | dcc40399f08285a9a308079098e735fb5bf192bd /module/c/lex2.scm | |
parent | Add of-type? to (hnh util type). (diff) | |
download | calp-f7b18cc72dd5b2ca90b6670dbe81c3ef3204d6d9.tar.gz calp-f7b18cc72dd5b2ca90b6670dbe81c3ef3204d6d9.tar.xz |
Resolve recursive macros.
Diffstat (limited to 'module/c/lex2.scm')
-rw-r--r-- | module/c/lex2.scm | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/module/c/lex2.scm b/module/c/lex2.scm index 6083190f..e1784541 100644 --- a/module/c/lex2.scm +++ b/module/c/lex2.scm @@ -1,6 +1,14 @@ (define-module (c lex2) :use-module (ice-9 peg) - :export (lex)) + :use-module (ice-9 match) + :use-module (hnh util object) + :use-module (hnh util type) + :use-module (srfi srfi-88) + :export (lex + lexeme lexeme? + (type . lexeme-type) + (body . lexeme-body) + (noexpand . lexeme-noexpand))) ;;; A.1 Lexical grammar ;;; A.1.1 Lexical elements @@ -321,6 +329,22 @@ preprocessing-token))) +(define-type (lexeme) + (type type: (memv '(whitespace comment preprocessing-token))) + (body type: (or string? list?)) + (noexpand type: (list-of string?) + default: '())) + +(define (lex-output->lexeme-object x) + (match x + (`(whitespace ,body) + (lexeme body: body type: 'whitespace )) + (`(comment ,body) + (lexeme body: body type: 'comment )) + (`(preprocessing-token ,body) + (lexeme body: body type: 'preprocessing-token)))) + ;; returns a list of lexemes (define (lex string) - (cdr (peg:tree (match-pattern preprocessing-tokens string)))) + (map lex-output->lexeme-object + (cdr (peg:tree (match-pattern preprocessing-tokens string))))) |