Just for fun, here’s an example with lex/yacc-style parsing: #lang racket
(require parser-tools/lex
(prefix-in : parser-tools/lex-sre)
parser-tools/yacc)
(module+ test
(require rackunit))
(define-empty-tokens delim-tokens (open close eof))
(define-tokens atom-tokens (int))
(define lex
(lexer
[(:+ whitespace)
(lex input-port)]
[(:+ numeric)
(token-int (string->number lexeme))]
[#\(
(token-open)]
[#\)
(token-close)]))
(define parse
(parser
[tokens delim-tokens atom-tokens]
[start Element]
[end eof]
[error (λ (tok-ok? name val)
(error "parse error"))]
[grammar
(Element
[(int)
$1]
[(open Element* close)
$2])
(Element*
[() '()]
[(Element Element*)
(cons $1 $2)])]))
(define (lex+parse-string str)
(define in (open-input-string str))
(parse (λ () (lex in))))
(module+ test
(check-equal? (lex+parse-string "(1 2 (3 4 (5 6)) 7)")
'(1 2 (3 4 (5 6)) 7)))
Awesome - thanks!
@philip.mcgrath thanks for the example :) Does the first rule for Element* match if there are no elements left, so as to “complete” a list in a way similar to: (if (null? ls)
'()
;recur)
?
#lang racket
(module A racket
...)
(module B racket
(require 'A)
...)
; ==> require: unknown module module name: #<resolved-module-path:'A>
I’ve tried a few different variations such as (module* B #f
etc. to no avail.
Of course, I’d also want to `(require ’B) at the top level to use it.
“A submodule declared with module can import any preceding submodule declared with module.” Searching for import
in the docs came up with odd results.
@badkins “import” = require
, and you need to do (require (submod ".." 'A))
I think
@notjack thanks, you were close :slightly_smiling_face: (require (submod ".." A))
apparently no need to quote in this case, where I do need to quote (require 'B)
for some reason
…weird
I guess the ".." makes sense like going up a directory then back down
This is the kind of thing that makes me wish module names were just URLs so I could reuse my knowledge of relative url syntax instead of learning the strange racket-specific notation
Yes, that’s right.