diff options
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))))) |