On this page:
shrubbery-syntax->string
shrubbery-syntax->raw
combine-shrubbery-raw
8.17.0.6

5.3 Reconstructing Shrubbery Notation🔗ℹ

 (require shrubbery/print) package: shrubbery-lib

procedure

(shrubbery-syntax->string 
  s 
  [#:use-raw? use-raw? 
  #:max-length max-length 
  #:keep-prefix? keep-prefix? 
  #:keep-suffix? keep-suffix? 
  #:inner? inner? 
  #:infer-starting-indentation? infer-starting-indentation? 
  #:register-stx-range register-stx-range 
  #:render-stx-hook render-stx-hook]) 
  string?
  s : syntax?
  use-raw? : any/c = #f
  max-length : (or/c #f exact-positive-integer?) = #f
  keep-prefix? : any/c = #f
  keep-suffix? : any/c = #f
  inner? : any/c = #f
  infer-starting-indentation? : any/c = (not keep-prefix?)
  register-stx-range : 
(syntax?
 exact-nonnegative-integer?
 exact-nonnegative-integer?
 . -> . any)
 = void
  render-stx-hook : (syntax? output-port? . -> . any/c)
   = (lambda (stx output) #f)
Converts a syntax object for an S-expression representation to a string form, potentially using raw text properties and otherwise falling back to write-shrubbery. By default, raw text reconstruction is used only if raw text is consistently available (as described below), but raw text mode can be forced by providing use-raw? as a true value. When use-raw? is true, each syntax object without raw text is printed as by write-shrubbery.

If max-length is a number, the returned string will contain no more than max-length characters. Internally, conversion to a string can take shortcuts once the first max-length characters have been determined.

When keep-suffix? are keep-suffix? are true and raw text mode is used to generate the result string, then 'raw-prefix and 'raw-suffix text on the immediate syntax object are included in the result. Otherwise, prefixes and suffixes are rendered only when they appear between 'raw text. If inner? is true, “inner” prefixes and suffixes are preserved on the immediate s form even if keep-suffix? and/or keep-suffix? are #false. If s is a group or multi-group form, then inner prefixes and suffixes are preserved in any case.

If infer-starting-indentation? is true, then a consistent amount of leading whitespace is removed from each line of the result string.

The register-stx-range and render-stx-hook arguments provide a hook to record or replace rendering of a syntax object within s. The register-stx-range procedure is called with each syntax object in s after printing, and the second and third arguments report the starting and ending locations in the string for the syntax object’s printed form. The render-stx-hook procedure is called before printing each syntax object, and if it returns a true value, then printing assumes that the syntax object has alerady been rendered to the given output port (which is ultimately delivered to a string), and it is not printed in the default way.

Raw text is consistently available when supplied by 'raw syntax properties on all atoms, except that 'raw-opaque-content and/or 'opaque-raw properties excuse nested atoms from needing 'raw properties. Also, a parsed form need not have raw text information.

procedure

(shrubbery-syntax->raw s 
  [#:use-raw? use-raw? 
  #:keep-prefix? keep-prefix? 
  #:keep-suffix? keep-suffix? 
  #:inner? inner?]) 
  
any? any? any?
  s : syntax?
  use-raw? : any/c = #f
  keep-prefix? : any/c = #f
  keep-suffix? : any/c = #f
  inner? : any/c = #f
Similar to shrubbery-syntax->string but delivers raw text encodings with the prefix, main, and suffix raw text as separate result values. If keep-prefix? or keep-suffix? is #f, the corresponding result is empty.

procedure

(combine-shrubbery-raw a b)  any/c

  a : any/c
  b : any/c
Combines a and b with cons if they are both non-empty, returns the empty list if both are empty, and otherwise returns the argument that is non-empty. In addition to normal raw text encodings, a #f argument counts as empty.