Module: dfmc-macro-expander Synopsis: Objects describing a pattern match specification. Author: Keith Playford Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND define abstract class () constant slot match-source-location = #f, init-keyword: source-location:; end class; define sealed domain make (subclass()); define sealed domain initialize (); define abstract class () slot match-symbol-name, required-init-keyword: symbol-name:; slot match-variable-name, required-init-keyword: variable-name:; slot match-constraint, required-init-keyword: constraint:; slot match-env-index :: = 0; end class; define class () end; define class () end; define abstract class () end; define abstract class () constant slot match-nested-pattern, required-init-keyword: nested-pattern:; end class; define class () end; define class () end; define class () end; define class () constant slot match-variable-name-pattern, required-init-keyword: variable-name-pattern:; constant slot match-type-expression-pattern, required-init-keyword: type-expression-pattern:; end class; define class () constant slot match-rest-pattern = #f, init-keyword: rest-pattern:; constant slot match-key-patterns = #(), init-keyword: key-patterns:; end class; define class () end; define class () constant slot match-default-expression = #f, init-keyword: default-expression:; end class; define class () constant slot match-default-expression = #f, init-keyword: default-expression:; end class; define class () constant slot match-nested-pattern, required-init-keyword: nested-pattern:; constant slot match-prefix :: false-or(), required-init-keyword: prefix:; constant slot match-suffix :: false-or(), required-init-keyword: suffix:; end class; define method wildcard-constraint? (constraint) constraint == #"*" end method; define method bounded-constraint? (constraint) constraint == #"body" | constraint == #"case-body" | constraint == #"body!" end method; /* // TODO: Not yet used. //// Main rule patterns. define abstract class () constant slot match-main-pattern, required-init-keyword: main-pattern:; end class; define abstract class () constant slot match-modifiers-pattern, required-init-keyword: modifiers-pattern:; end class; define class () end; define class () end; */ //// Pattern traversal. define method compute-binding-matches (m*) collecting () do-binding-matches (method (name) collect(name) end, m*); end; end method; define method compute-bound-variable-names (m*) collecting () do-binding-matches (method (name) collect(match-variable-name(name)) end, m*); end; end method; define method do-binding-matches (f, m*) for (m in m*) do-match-binding-matches(f, m) end; end method; define method do-match-binding-matches (f, m :: type-union(, )) end method; define method do-match-binding-matches (f, m :: ) f(m); end method; define method do-match-binding-matches (f, m :: ) do-binding-matches(f, match-nested-pattern(m)); end method; define method do-match-binding-matches (f, m :: ) do-match-binding-matches(f, match-variable-name-pattern(m)); do-match-binding-matches(f, match-type-expression-pattern(m)); end method; define method do-match-binding-matches (f, m :: ) do-match-binding-matches(f, match-nested-pattern(m)); end method; define method do-match-binding-matches (f, m :: ) if (match-rest-pattern(m)) do-match-binding-matches(f, match-rest-pattern(m)); end; do-binding-matches(f, match-key-patterns(m)); end method; //// Body pattern tail traversal. define method do-body-match-tails (f :: , m*) => () for (m-tail = m* then m-tail.tail, until: empty?(m-tail)) do-match-body-match-tails(f, m-tail.head, m-tail.tail); end; end method; define method do-match-body-match-tails (f :: , m :: type-union(, ), m-tail) => () end method; define method do-match-body-match-tails (f :: , m :: , m-tail) => () if (bounded-constraint?(match-constraint(m))) f(m, m-tail); end; end method; define method do-match-body-match-tails (f :: , m :: , m-tail) => () do-body-match-tails(f, match-nested-pattern(m)); end method; //// Valid constraints. define constant $valid-constraints = #[#"*", #"token", #"name", #"expression", #"variable", #"body", #"body!", #"case-body", #"macro", #"symbol"]; define function valid-match-constraint? (constraint) => (well? :: ) constraint == #f // none specified | member?(constraint, $valid-constraints); end function; // eof