From f7b18cc72dd5b2ca90b6670dbe81c3ef3204d6d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 10 Jul 2022 23:36:56 +0200 Subject: Resolve recursive macros. --- module/c/lex2.scm | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'module/c/lex2.scm') 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))))) -- cgit v1.2.3