hello,
i try to write a regex since yesterday afternoon, but not sure it could be done with regex as they are built on automata theory and somethings can not be done in this theory.
It is not i'm lazy , but on this sunny saturday i prefer to be outdoor than having a headache on regular expressions .
Then i want to skip, this expression in a Scheme file:
#! /usr/bin/env racket
i thought of something like that for testing:
> (regexp-match #px"^#![[:blank:]]*/[[:alpha:]|/]*racket[[:blank:]]*\n" "#! /usr/local racket\n zut alors un autre racket \n")
(regexp-match
(pregexp "^#![[:blank:]]*/[[:alpha:]|/]*racket[[:blank:]]*\n")
"#! /usr/local racket\n zut alors un autre racket \n")
#f
the problem is that i do not want to skip all 'racket' expression as it is the start of a program and racket is a keyword in the module ,see:
#! /usr/bin/env racket
#lang reader SRFI-105
;; interpolate field caller
;; Damien MATTEI
;; export PATH=/Applications/Racket/bin:$PATH
;; TODO: use Makefile
(module interpolate-field-caller racket
(require Scheme+)
(require setup/dirs)
(require racket/date)
(require srfi/13) ; for at least string-contains
(require xml
(except-in 2htdp/batch-io xexpr?)) ; for: read-lines
(display "Scheme+ : interpole_fields") (newline)
if i do it like that,my parser got:
|(#! /usr/bin/env racket
#lang reader SRFI-105
;; interpolate field caller
;; Damien MATTEI
;; export PATH=/Applications/Racket/bin:$PATH
;; TODO: use Makefile
(module interpolate-field-caller racket
)|
cutting the program in the middle of code...
my previous parser looks like that:
(skip-comments-and-empty-lines in)
(let loop ()
(define try-read (regexp-try-match #px"^#![[:blank:]]*/[[:ascii:]]*racket[[:blank:]]*\n" in))
(when try-read
;;(display "executable") (newline)
(display "|" stderr) (display try-read stderr) (display "|" stderr) (newline stderr)
(display (car try-read) (current-output-port))
(loop)))
(skip-comments-and-empty-lines in)
(let loop ()
(when (regexp-try-match #px"^#!curly-infix[[:blank:]]*\n" in)
(loop)))
(skip-comments-and-empty-lines in)
(let loop ()
(when (regexp-try-match #px"^#lang reader SRFI-105[[:blank:]]*\n" in)
;;(display "srfi 105") (newline)
(loop)))
(skip-comments-and-empty-lines in)
(when (regexp-try-match #px"^#!r6rs[[:blank:]]*\n" in)
(set! flag-r6rs #t)
(display "Detected R6RS code: #!r6rs" stderr) (newline stderr) (newline stderr))
if i can find a way in posix regex to define alpha character and / but not newline it could be ok but in the doc i only find 'ascii' which is too global....