4 Lexp Implementation - Unstable
Lexp-implementation.rkt contains the base functions and macros for building literate experssions.It [more or less] follows the implementation for Racket VerbalExpressions.
Because I am not sure how well it aligns with the goals of LiterateExpressions, this should be considered untsable
<lexp-implementation-requires> <exports> <implementation-variables> <implementation-accessors> <beginCapture> <endCapture> <regex> <withAnyCase> <matchCase> <OR>
(require "Lexp-structures.rkt")
4.1 Variables
The base variables are string. These store the various parts of the string representing the Regex as it is built up. Because this implementation uses mutation and strings, it is likely to change
Each variable is initialized to the empty string.
(define ve-prefix "") (define ve-source "") (define ve-suffix "") (define ve-modifiers "")
These variables are not exported.
(provide (except-out (all-defined-out) ve-prefix ve-source ve-suffix ve-modifiers))
Each variable has an accessor.
(define (ve-prefix! v) (set! ve-prefix v)) (define (ve-source! v) (set! ve-source v)) (define (ve-suffix! v) (set! ve-suffix v)) (define (ve-modifiers! v) (set! ve-modifiers v))
4.2 Macros
The use of Macros is one of the areas where a Racket Implementation will differ substantially from implementations in many other languages. On the other hand, it offers a template for anyone Implementing LiterateExpressions on another Lisp.
Starts the collection of string data.
(listof Function) -> String SideEffects
(define-syntax-rule (beginCapture a ...) (begin (reset) a ...))
Returns the string representing the LiterateExpression.
_ -> String
(define-syntax-rule (endCapture) (string-append ve-prefix ve-source ve-suffix ve-modifiers))
endCapture has an alias to be consistent with VerbalExpressions:
(define (regex) (endCapture))
Modifier flag to make pattern matching case insensitive.
(listof fn) -> String
(define-syntax-rule (withAnyCase a ...) (let ((src ve-source)) (ve-source! (string-append src "(?i:" (begin a ... (regex)) ")"))))
Modifier flag to make pattern matching case sensitive.
(listof fn) -> String
(define-syntax-rule (matchCase a ...) (let ((src ve-source)) (ve-source! (string-append src "(?-i:" (begin a ... (regex)) ")"))))
4.2.1 Alternative Expressions
These were renamed from the original VerbalExpression implementation in JavaScript
Renamed from "or" to "OR" to avoid conflict with Racket’s built-in or special form. It’s a bit of a kludge, perhaps, but there are not a lot of simple alternatives.
(listof Function) -> String SideEffects
(define-syntax-rule (OR a ...) (let ((src (regex))) (reset) (ve-source! (string-append "(" src ")|(" (begin a ...) ")"))))