/usr/share/doc/racket/syntax/stxparse-specifying.html is in racket-doc 6.1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>1.4 Specifying Syntax with Syntax Classes</title><link rel="stylesheet" type="text/css" href="../scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="../racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../doc-site.css" title="default"/><script type="text/javascript" src="../scribble-common.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../doc-site.js"></script><script type="text/javascript" src="../local-redirect/local-redirect.js"></script><script type="text/javascript" src="../local-redirect/local-user-redirect.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="doc-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_0");">►</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">Syntax:<span class="mywbr"> </span> Meta-<wbr></wbr>Programming Helpers</a></td></tr></table></div><div class="tocviewsublisttop" style="display: none;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1 </td><td><a href="stxparse.html" class="tocviewselflink" data-pltdoc="x">Parsing and Specifying Syntax</a></td></tr><tr><td align="right">2 </td><td><a href="syntax-helpers.html" class="tocviewlink" data-pltdoc="x">Syntax Object Helpers</a></td></tr><tr><td align="right">3 </td><td><a href="Datum_Pattern_Matching.html" class="tocviewlink" data-pltdoc="x">Datum Pattern Matching</a></td></tr><tr><td align="right">4 </td><td><a href="module-helpers.html" class="tocviewlink" data-pltdoc="x">Module-<wbr></wbr>Processing Helpers</a></td></tr><tr><td align="right">5 </td><td><a href="transformer-helpers.html" class="tocviewlink" data-pltdoc="x">Macro Transformer Helpers</a></td></tr><tr><td align="right">6 </td><td><a href="reader-helpers.html" class="tocviewlink" data-pltdoc="x">Reader Helpers</a></td></tr><tr><td align="right">7 </td><td><a href="Parsing_for_Bodies.html" class="tocviewlink" data-pltdoc="x">Parsing <span class="RktSym"><span class="RktStxLink">for</span></span> Bodies</a></td></tr><tr><td align="right">8 </td><td><a href="Unsafe_for_Clause_Transforms.html" class="tocviewlink" data-pltdoc="x">Unsafe <span class="RktSym"><span class="RktStxLink">for</span></span> Clause Transforms</a></td></tr><tr><td align="right">9 </td><td><a href="Source_Locations.html" class="tocviewlink" data-pltdoc="x">Source Locations</a></td></tr><tr><td align="right">10 </td><td><a href="Preserving_Source_Locations.html" class="tocviewlink" data-pltdoc="x">Preserving Source Locations</a></td></tr><tr><td align="right">11 </td><td><a href="toplevel.html" class="tocviewlink" data-pltdoc="x">Non-<wbr></wbr>Module Compilation And Expansion</a></td></tr><tr><td align="right">12 </td><td><a href="trusted-xforms.html" class="tocviewlink" data-pltdoc="x">Trusting Standard Recertifying Transformers</a></td></tr><tr><td align="right">13 </td><td><a href="docprovide.html" class="tocviewlink" data-pltdoc="x">Attaching Documentation to Exports</a></td></tr><tr><td align="right"></td><td><a href="doc-index.html" class="tocviewlink" data-pltdoc="x">Index</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_1");">▼</a></td><td>1 </td><td><a href="stxparse.html" class="tocviewlink" data-pltdoc="x">Parsing and Specifying Syntax</a></td></tr></table><div class="tocviewsublist" style="display: block;" id="tocview_1"><table cellspacing="0" cellpadding="0"><tr><td align="right">1.1 </td><td><a href="stxparse-intro.html" class="tocviewlink" data-pltdoc="x">Introduction</a></td></tr><tr><td align="right">1.2 </td><td><a href="stxparse-examples.html" class="tocviewlink" data-pltdoc="x">Examples</a></td></tr><tr><td align="right">1.3 </td><td><a href="Parsing_Syntax.html" class="tocviewlink" data-pltdoc="x">Parsing Syntax</a></td></tr><tr><td align="right">1.4 </td><td><a href="" class="tocviewselflink" data-pltdoc="x">Specifying Syntax with Syntax Classes</a></td></tr><tr><td align="right">1.5 </td><td><a href="stxparse-patterns.html" class="tocviewlink" data-pltdoc="x">Syntax Patterns</a></td></tr><tr><td align="right">1.6 </td><td><a href="Defining_Simple_Macros.html" class="tocviewlink" data-pltdoc="x">Defining Simple Macros</a></td></tr><tr><td align="right">1.7 </td><td><a href="Literal_Sets_and_Conventions.html" class="tocviewlink" data-pltdoc="x">Literal Sets and Conventions</a></td></tr><tr><td align="right">1.8 </td><td><a href="Library_Syntax_Classes_and_Literal_Sets.html" class="tocviewlink" data-pltdoc="x">Library Syntax Classes and Literal Sets</a></td></tr><tr><td align="right">1.9 </td><td><a href="Debugging_and_Inspection_Tools.html" class="tocviewlink" data-pltdoc="x">Debugging and Inspection Tools</a></td></tr><tr><td align="right">1.10 </td><td><a href="Experimental.html" class="tocviewlink" data-pltdoc="x">Experimental</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_2");">►</a></td><td>1.4 </td><td><a href="" class="tocviewselflink" data-pltdoc="x">Specifying Syntax with Syntax Classes</a></td></tr></table><div class="tocviewsublistbottom" style="display: none;" id="tocview_2"><table cellspacing="0" cellpadding="0"><tr><td align="right">1.4.1 </td><td><a href="#%28part._.Pattern_.Directives%29" class="tocviewlink" data-pltdoc="x">Pattern Directives</a></td></tr><tr><td align="right">1.4.2 </td><td><a href="#%28part._stxparse-attrs%29" class="tocviewlink" data-pltdoc="x">Pattern Variables and Attributes</a></td></tr></table></div></div></div><div class="tocsub"><div class="tocsubtitle">On this page:</div><table class="tocsublist" cellspacing="0"><tr><td><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-syntax-class%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">define-<wbr></wbr>syntax-<wbr></wbr>class</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-splicing-syntax-class%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">define-<wbr></wbr>splicing-<wbr></wbr>syntax-<wbr></wbr>class</span></span></a></td></tr><tr><td><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._pattern%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">pattern</span></span></a></td></tr><tr><td><span class="tocsublinknumber">1.4.1<tt> </tt></span><a href="#%28part._.Pattern_.Directives%29" class="tocsubseclink" data-pltdoc="x">Pattern Directives</a></td></tr><tr><td><span class="tocsublinknumber">1.4.2<tt> </tt></span><a href="#%28part._stxparse-attrs%29" class="tocsubseclink" data-pltdoc="x">Pattern Variables and Attributes</a></td></tr><tr><td><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._attribute%29%29" class="tocsubnonseclink" data-pltdoc="x"><span class="RktSym"><span class="RktStxLink">attribute</span></span></a></td></tr></table></div></div><div class="maincolumn"><div class="main"><div class="navsettop"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, "6.1", "../");" onfocus="this.style.color="black"; this.style.textAlign="left"; if (this.value == "...search manuals...") this.value="";" onblur="if (this.value.match(/^ *$/)) { this.style.color="#888"; this.style.textAlign="center"; this.value="...search manuals..."; }"/></form> <a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("6.1");">top</a></span><span class="navright"> <a href="Parsing_Syntax.html" title="backward to "1.3 Parsing Syntax"" data-pltdoc="x">← prev</a> <a href="stxparse.html" title="up to "1 Parsing and Specifying Syntax"" data-pltdoc="x">up</a> <a href="stxparse-patterns.html" title="forward to "1.5 Syntax Patterns"" data-pltdoc="x">next →</a></span> </div><h4 x-source-module="(lib "syntax/scribblings/syntax.scrbl")" x-part-tag=""stxparse-specifying"">1.4<tt> </tt><a name="(part._stxparse-specifying)"></a>Specifying Syntax with Syntax Classes</h4><p>Syntax classes provide an abstraction mechanism for <a href="stxparse-patterns.html#%28tech._syntax._pattern%29" class="techoutside" data-pltdoc="x"><span class="techinside">syntax
patterns</span></a>. Built-in syntax classes are supplied that recognize basic
classes such as <span class="RktSym"><a href="Library_Syntax_Classes_and_Literal_Sets.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._identifier%29%29" class="RktStxLink" data-pltdoc="x">identifier</a></span> and <span class="RktSym"><a href="Library_Syntax_Classes_and_Literal_Sets.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._keyword%29%29" class="RktStxLink" data-pltdoc="x">keyword</a></span>. Programmers
can compose basic syntax classes to build specifications of more
complex syntax, such as lists of distinct identifiers and formal
arguments with keywords. Macros that manipulate the same syntactic
structures can share syntax class definitions.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><table cellspacing="0" cellpadding="0" class="RktBlk RForeground"><tr><td><span class="RktPn">(</span><a name="(form._((lib._syntax/parse..rkt)._define-syntax-class))"></a><span title="Provided from: syntax/parse | Package: base"><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-syntax-class%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">define-syntax-class</a></span></span><span class="hspace"> </span><span class="RktVar">name-id</span><span class="hspace"> </span><span class="RktVar">stxclass-option</span><span class="hspace"> </span><span class="RktMeta">...</span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">stxclass-variant</span><span class="hspace"> </span><span class="RktMeta">...+</span><span class="RktPn">)</span></td></tr></table></blockquote></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-syntax-class%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">define-syntax-class</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">name-id</span><span class="hspace"> </span><span class="RktPn">. </span><span class="RktVar">kw-formals</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktVar">stxclass-option</span><span class="hspace"> </span><span class="RktMeta">...</span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">stxclass-variant</span><span class="hspace"> </span><span class="RktMeta">...+</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><span class="stt"> </span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="specgrammar"><tr><td align="right" valign="baseline"><span class="RktVar">stxclass-option</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:attributes</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">attr-arity-decl</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:description</span><span class="hspace"> </span><span class="RktVar">description-expr</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:opaque</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:commit</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:no-delimit-cut</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:literals</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">literal-entry</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:datum-literals</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">datum-literal-entry</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:literal-sets</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">literal-set</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:conventions</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">convention-id</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:local-conventions</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">convention-rule</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:disable-colon-notation</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td></tr><tr><td align="right" valign="baseline"><span class="RktVar">attr-arity-decl</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktVar">attr-name-id</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">(</span><span class="RktVar">attr-name-id</span><span class="hspace"> </span><span class="RktVar">depth</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td></tr><tr><td align="right" valign="baseline"><span class="RktVar">stxclass-variant</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._pattern%29%29" class="RktStxLink" data-pltdoc="x">pattern</a></span><span class="hspace"> </span><span class="RktVar">syntax-pattern</span><span class="hspace"> </span><span class="RktVar">pattern-directive</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><span class="stt"> </span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="argcontract"><tr><td><span class="hspace"> </span></td><td><span class="RktVar">description-expr</span></td><td><span class="hspace"> </span></td><td>:</td><td><span class="hspace"> </span></td><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528def._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._or%252Fc%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">or/c</a></span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=strings.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._string%7E3f%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">string?</a></span><span class="hspace"> </span><span class="RktVal">#f</span><span class="RktPn">)</span></td></tr></table></td></tr></table></blockquote></div><div class="SIntrapara">Defines <span class="RktVar">name-id</span> as a <a name="(tech._syntax._clas)"></a><span style="font-style: italic">syntax class</span>, which
encapsulates one or more <a href="stxparse-patterns.html#%28tech._single._term._pattern%29" class="techoutside" data-pltdoc="x"><span class="techinside">single-term patterns</span></a>.</div></p><p>A syntax class may have formal parameters, in which case they are
bound as variables in the body. Syntax classes support optional
arguments and keyword arguments using the same syntax as
<span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=lambda.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._lambda%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">lambda</a></span>. The body of the syntax-class definition contains a
non-empty sequence of <span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._pattern%29%29" class="RktStxLink" data-pltdoc="x">pattern</a></span> variants.</p><p>The following options are supported:</p><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:attributes</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">attr-arity-decl</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="stt"> </span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="specgrammar"><tr><td align="right" valign="baseline"><span class="RktVar">attr-arity-decl</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktVar">attr-id</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">(</span><span class="RktVar">attr-id</span><span class="hspace"> </span><span class="RktVar">depth</span><span class="RktPn">)</span></td></tr></table></td></tr></table></blockquote><p>Declares the attributes of the syntax class. An attribute arity
declaration consists of the attribute name and optionally its ellipsis
depth (zero if not explicitly specified).</p><p>If the attributes are not explicitly listed, they are inferred as the
set of all <a href="stxparse-patterns.html#%28tech._pattern._variable%29" class="techoutside" data-pltdoc="x"><span class="techinside">pattern variables</span></a> occurring in every variant of the
syntax class. Pattern variables that occur at different ellipsis
depths are not included, nor are nested attributes from
<a href="stxparse-patterns.html#%28tech._annotated._pattern._variable%29" class="techoutside" data-pltdoc="x"><span class="techinside">annotated pattern variables</span></a>.</p></blockquote><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:description</span><span class="hspace"> </span><span class="RktVar">description-expr</span></td></tr><tr><td><span class="stt"> </span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="argcontract"><tr><td><span class="hspace"> </span></td><td><span class="RktVar">description-expr</span></td><td><span class="hspace"> </span></td><td>:</td><td><span class="hspace"> </span></td><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528def._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._or%252Fc%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">or/c</a></span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=strings.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._string%7E3f%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">string?</a></span><span class="hspace"> </span><span class="RktVal">#f</span><span class="RktPn">)</span></td></tr></table></td></tr></table></blockquote><p>The <span class="RktSym">description</span> argument is evaluated in a scope containing
the syntax class’s parameters. If the result is a string, it is used
in error messages involving the syntax class. For example, if a term
is rejected by the syntax class, an error of the form
<span class="RktVal">"expected <span class="RktSym">description</span>"</span> may be synthesized. If
the result is <span class="RktVal">#f</span>, the syntax class is skipped in the search
for a description to report.</p><p>If the option is not given, the name of the syntax class is
used instead.</p></blockquote><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:opaque</span></td></tr></table></blockquote><p>Indicates that errors should not be reported with respect to the
internal structure of the syntax class.</p></blockquote><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:commit</span></td></tr></table></blockquote><p>Directs the syntax class to “commit” to the first successful
match. When a variant succeeds, all choice points within the syntax
class are discarded. See also <span class="RktSym"><a href="stxparse-patterns.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7ecommit%29%29" class="RktStxLink" data-pltdoc="x">~commit</a></span>.</p></blockquote><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:no-delimit-cut</span></td></tr></table></blockquote><p>By default, a cut (<span class="RktSym"><a href="stxparse-patterns.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7e%21%29%29" class="RktStxLink" data-pltdoc="x">~!</a></span>) within a syntax class only discards
choice points within the syntax class. That is, the body of the syntax
class acts as though it is wrapped in a <span class="RktSym"><a href="stxparse-patterns.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7edelimit-cut%29%29" class="RktStxLink" data-pltdoc="x">~delimit-cut</a></span> form. If
<span class="RktPn">#:no-delimit-cut</span> is specified, a cut may affect choice points
of the syntax class’s calling context (another syntax class’s patterns
or a <span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span> form).</p><p>It is an error to use both <span class="RktPn">#:commit</span> and
<span class="RktPn">#:no-delimit-cut</span>.</p></blockquote><p><div class="SIntrapara"><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:literals</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">literal-entry</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr></table></blockquote></blockquote></div><div class="SIntrapara"><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:datum-literals</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">datum-literal-entry</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr></table></blockquote></blockquote></div><div class="SIntrapara"><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:literal-sets</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">literal-set</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr></table></blockquote></blockquote></div><div class="SIntrapara"><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:conventions</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">convention-id</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr></table></blockquote><p>Declares the literals and conventions that apply to the syntax class’s
variant patterns and their immediate <span class="RktPn">#:with</span> clauses. Patterns
occuring within subexpressions of the syntax class (for example, on
the right-hand side of a <span class="RktPn">#:fail-when</span> clause) are not
affected.</p><p>These options have the same meaning as in <span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span>.</p></blockquote></div></p><p>Each variant of a syntax class is specified as a separate
<span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._pattern%29%29" class="RktStxLink" data-pltdoc="x">pattern</a></span>-form whose syntax pattern is a <a href="stxparse-patterns.html#%28tech._single._term._pattern%29" class="techoutside" data-pltdoc="x"><span class="techinside">single-term
pattern</span></a>.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><table cellspacing="0" cellpadding="0" class="RktBlk RForeground"><tr><td><span class="RktPn">(</span><a name="(form._((lib._syntax/parse..rkt)._define-splicing-syntax-class))"></a><span title="Provided from: syntax/parse | Package: base"><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-splicing-syntax-class%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">define-splicing-syntax-class</a></span></span><span class="hspace"> </span><span class="RktVar">name-id</span><span class="hspace"> </span><span class="RktVar">stxclass-option</span><span class="hspace"> </span><span class="RktMeta">...</span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">stxclass-variant</span><span class="hspace"> </span><span class="RktMeta">...+</span><span class="RktPn">)</span></td></tr></table></blockquote></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-splicing-syntax-class%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">define-splicing-syntax-class</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktVar">name-id</span><span class="hspace"> </span><span class="RktVar">kw-formals</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktVar">stxclass-option</span><span class="hspace"> </span><span class="RktMeta">...</span></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">stxclass-variant</span><span class="hspace"> </span><span class="RktMeta">...+</span><span class="RktPn">)</span></td></tr></table></td></tr></table></blockquote></div><div class="SIntrapara">Defines <span class="RktVar">name-id</span> as a <a name="(tech._splicing._syntax._clas)"></a><span style="font-style: italic">splicing syntax class</span>,
analogous to a <a href="#%28tech._syntax._clas%29" class="techoutside" data-pltdoc="x"><span class="techinside">syntax class</span></a> but encapsulating <a href="stxparse-patterns.html#%28tech._head._pattern%29" class="techoutside" data-pltdoc="x"><span class="techinside">head
patterns</span></a> rather than <a href="stxparse-patterns.html#%28tech._single._term._pattern%29" class="techoutside" data-pltdoc="x"><span class="techinside">single-term patterns</span></a>.</div></p><p>The options are the same as for <span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-syntax-class%29%29" class="RktStxLink" data-pltdoc="x">define-syntax-class</a></span>.</p><p>Each variant of a splicing syntax class is specified as a separate
<span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._pattern%29%29" class="RktStxLink" data-pltdoc="x">pattern</a></span>-form whose syntax pattern is a <a href="stxparse-patterns.html#%28tech._head._pattern%29" class="techoutside" data-pltdoc="x"><span class="techinside">head pattern</span></a>.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._syntax/parse..rkt)._pattern))"></a><span title="Provided from: syntax/parse | Package: base"><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._pattern%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">pattern</a></span></span><span class="hspace"> </span><span class="RktVar">syntax-pattern</span><span class="hspace"> </span><span class="RktVar">pattern-directive</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">Used to indicate a variant of a syntax class or splicing syntax
class. The variant accepts syntax matching the given syntax pattern
with the accompanying <a href="#%28tech._pattern._directive%29" class="techoutside" data-pltdoc="x"><span class="techinside">pattern directives</span></a>.</div></p><p>When used within <span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-syntax-class%29%29" class="RktStxLink" data-pltdoc="x">define-syntax-class</a></span>, <span class="RktVar">syntax-pattern</span>
should be a <a href="stxparse-patterns.html#%28tech._single._term._pattern%29" class="techoutside" data-pltdoc="x"><span class="techinside">single-term pattern</span></a>; within
<span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-splicing-syntax-class%29%29" class="RktStxLink" data-pltdoc="x">define-splicing-syntax-class</a></span>, it should be a <a href="stxparse-patterns.html#%28tech._head._pattern%29" class="techoutside" data-pltdoc="x"><span class="techinside">head
pattern</span></a>.</p><p>The attributes of the variant are the attributes of the pattern
together with all attributes bound by <span class="RktPn">#:with</span> clauses,
including nested attributes produced by syntax classes associated with
the pattern variables.</p><h5 x-source-module="(lib "syntax/scribblings/syntax.scrbl")" x-part-tag=""Pattern_Directives"">1.4.1<tt> </tt><a name="(part._.Pattern_.Directives)"></a><a name="(idx._(gentag._0._(lib._syntax/scribblings/syntax..scrbl)))"></a>Pattern Directives</h5><p>Both the parsing forms and syntax class definition forms support
<a name="(tech._pattern._directive)"></a><span style="font-style: italic">pattern directives</span> for annotating syntax patterns and
specifying side conditions. The grammar for pattern directives
follows:</p><p><table cellspacing="0" cellpadding="0"><tr><td align="right" valign="baseline"><span class="hspace"> </span><span class="RktVar">pattern-directive</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:declare</span><span class="hspace"> </span><span class="RktVar">pattern-id</span><span class="hspace"> </span><span class="RktVar">stxclass</span><span class="hspace"> </span><span class="RktVar">maybe-role</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:with</span><span class="hspace"> </span><span class="RktVar">syntax-pattern</span><span class="hspace"> </span><span class="RktVar">expr</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:attr</span><span class="hspace"> </span><span class="RktVar">attr-arity-decl</span><span class="hspace"> </span><span class="RktVar">expr</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:fail-when</span><span class="hspace"> </span><span class="RktVar">condition-expr</span><span class="hspace"> </span><span class="RktVar">message-expr</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:fail-unless</span><span class="hspace"> </span><span class="RktVar">condition-expr</span><span class="hspace"> </span><span class="RktVar">message-expr</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:when</span><span class="hspace"> </span><span class="RktVar">condition-expr</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:do</span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktVar">def-or-expr</span><span class="hspace"> </span><span class="RktSym">...</span><span class="RktPn">]</span></td></tr></table></p><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:declare</span><span class="hspace"> </span><span class="RktVar">pvar-id</span><span class="hspace"> </span><span class="RktVar">stxclass</span><span class="hspace"> </span><span class="RktVar">maybe-role</span></td></tr><tr><td><span class="stt"> </span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="specgrammar"><tr><td align="right" valign="baseline"><span class="RktVar">stxclass</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktVar">syntax-class-id</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">(</span><span class="RktVar">syntax-class-id</span><span class="hspace"> </span><span class="RktVar">arg</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">)</span></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td></tr><tr><td align="right" valign="baseline"><span class="RktVar">maybe-role</span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">=</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td></td></tr></table></td></tr><tr><td align="right" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="center" valign="baseline">|</td><td align="left" valign="baseline"><span class="stt"> </span></td><td align="left" valign="baseline"><span class="RktPn">#:role</span><span class="hspace"> </span><span class="RktVar">role-expr</span></td></tr></table></td></tr></table></blockquote><p>Associates <span class="RktVar">pvar-id</span> with a syntax class and possibly a role,
equivalent to replacing each occurrence of <span class="RktVar">pvar-id</span> in the
pattern with <span class="RktPn">(</span><span class="RktSym"><a href="stxparse-patterns.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7evar%29%29" class="RktStxLink" data-pltdoc="x">~var</a></span><span class="stt"> </span><span class="RktVar">pvar-id</span><span class="stt"> </span><span class="RktVar">stxclass</span><span class="stt"> </span><span class="RktVar">maybe-role</span><span class="RktPn">)</span>.
The second form of <span class="RktVar">stxclass</span> allows the use of parameterized
syntax classes, which cannot be expressed using the “colon”
notation. The <span class="RktVar">arg</span>s are evaluated in the scope where the
<span class="RktVar">pvar-id</span> occurs in the pattern. Keyword arguments are
supported, using the same syntax as in <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=application.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._%7E23%7E25app%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">#%app</a></span>.</p><p>If a <span class="RktPn">#:with</span> directive appears between the main pattern (e.g., in a
<span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span> or <span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-syntax-class%29%29" class="RktStxLink" data-pltdoc="x">define-syntax-class</a></span> clause) and a
<span class="RktPn">#:declare</span>, then only pattern variables from the <span class="RktPn">#:with</span>
pattern may be declared.</p><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><p>Examples:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktSym">P</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym">x</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">#:declare</span><span class="hspace"> </span><span class="RktSym">x</span><span class="hspace"> </span><span class="RktSym"><a href="Library_Syntax_Classes_and_Literal_Sets.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._id%29%29" class="RktStxLink" data-pltdoc="x">id</a></span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">#<syntax:68:0 P></span></p></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktSym">L</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym">x</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">#:with</span><span class="hspace"> </span><span class="RktSym">y</span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktSym">x</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">#:declare</span><span class="hspace"> </span><span class="RktSym">x</span><span class="hspace"> </span><span class="RktSym"><a href="Library_Syntax_Classes_and_Literal_Sets.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._id%29%29" class="RktStxLink" data-pltdoc="x">id</a></span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktErr">syntax-parse: identifier in #:declare clause does not appear</span></p></td></tr><tr><td><p><span class="RktErr">in pattern;</span></p></td></tr><tr><td><p><span class="RktErr"></span><span class="hspace"> </span><span class="RktErr">this #:declare clause affects only the preceding #:with</span></p></td></tr><tr><td><p><span class="RktErr">pattern at: x</span></p></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktSym">T</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym">x</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">#:with</span><span class="hspace"> </span><span class="RktSym">y</span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktSym">x</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">#:declare</span><span class="hspace"> </span><span class="RktSym">y</span><span class="hspace"> </span><span class="RktSym"><a href="Library_Syntax_Classes_and_Literal_Sets.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._id%29%29" class="RktStxLink" data-pltdoc="x">id</a></span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">#<syntax:70:0 T></span></p></td></tr></table></blockquote></td></tr></table></blockquote><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:with</span><span class="hspace"> </span><span class="RktVar">syntax-pattern</span><span class="hspace"> </span><span class="RktVar">stx-expr</span></td></tr></table></blockquote><p>Evaluates the <span class="RktVar">stx-expr</span> in the context of all previous
attribute bindings and matches it against the pattern. If the match
succeeds, the pattern’s attributes are added to environment for the
evaluation of subsequent side conditions. If the <span class="RktPn">#:with</span> match
fails, the matching process backtracks. Since a syntax object may
match a pattern in several ways, backtracking may cause the same
clause to be tried multiple times before the next clause is reached.</p><p>If the value of <span class="RktVar">stx-expr</span> is not a syntax object, it is
implicitly converted to a syntax object. If the the conversion would
produce <a name="(tech._3d._syntax)"></a><span style="font-style: italic">3D syntax</span>—<wbr></wbr>that is, syntax that contains unwritable
values such as procedures, non-prefab structures, etc—<wbr></wbr>then an
exception is raised instead.</p></blockquote><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:attr</span><span class="hspace"> </span><span class="RktVar">attr-arity-decl</span><span class="hspace"> </span><span class="RktVar">expr</span></td></tr></table></blockquote><p>Evaluates the <span class="RktVar">expr</span> in the context of all previous attribute
bindings and binds it to the given attribute. The value of
<span class="RktVar">expr</span> need not be, or even contain, syntax—<wbr></wbr>see
<span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._attribute%29%29" class="RktStxLink" data-pltdoc="x">attribute</a></span> for details.</p></blockquote><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:fail-when</span><span class="hspace"> </span><span class="RktVar">condition-expr</span><span class="hspace"> </span><span class="RktVar">message-expr</span></td></tr><tr><td><span class="stt"> </span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="argcontract"><tr><td><span class="hspace"> </span></td><td><span class="RktVar">message-expr</span></td><td><span class="hspace"> </span></td><td>:</td><td><span class="hspace"> </span></td><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528def._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._or%252Fc%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">or/c</a></span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=strings.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._string%7E3f%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">string?</a></span><span class="hspace"> </span><span class="RktVal">#f</span><span class="RktPn">)</span></td></tr></table></td></tr></table></blockquote><p>Evaluates the <span class="RktVar">condition-expr</span> in the context of all previous
attribute bindings. If the value is any true value (not <span class="RktVal">#f</span>),
the matching process backtracks (with the given message); otherwise,
it continues. If the value of the condition expression is a syntax
object, it is indicated as the cause of the error.</p><p>If the <span class="RktVar">message-expr</span> produces a string it is used as the
failure message; otherwise the failure is reported in terms of the
enclosing descriptions.</p></blockquote><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:fail-unless</span><span class="hspace"> </span><span class="RktVar">condition-expr</span><span class="hspace"> </span><span class="RktVar">message-expr</span></td></tr><tr><td><span class="stt"> </span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="argcontract"><tr><td><span class="hspace"> </span></td><td><span class="RktVar">message-expr</span></td><td><span class="hspace"> </span></td><td>:</td><td><span class="hspace"> </span></td><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=data-structure-contracts.html%23%2528def._%2528%2528lib._racket%252Fcontract%252Fbase..rkt%2529._or%252Fc%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">or/c</a></span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=strings.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._string%7E3f%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">string?</a></span><span class="hspace"> </span><span class="RktVal">#f</span><span class="RktPn">)</span></td></tr></table></td></tr></table></blockquote><p>Like <span class="RktPn">#:fail-when</span> with the condition negated.</p></blockquote><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:when</span><span class="hspace"> </span><span class="RktVar">condition-expr</span></td></tr></table></blockquote><p>Evaluates the <span class="RktVar">condition-expr</span> in the context of all previous
attribute bindings. If the value is <span class="RktVal">#f</span>, the matching process
backtracks. In other words, <span class="RktPn">#:when</span> is like
<span class="RktPn">#:fail-unless</span> without the message argument.</p></blockquote><blockquote class="leftindent"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><span class="RktPn">#:do</span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktVar">def-or-expr</span><span class="hspace"> </span><span class="RktMeta">...</span><span class="RktPn">]</span></td></tr></table></blockquote><p>Takes a sequence of definitions and expressions, which may be
intermixed, and evaluates them in the scope of all previous attribute
bindings. The names bound by the definitions are in scope in
the expressions of subsequent patterns and clauses.</p><p>There is currently no way to bind attributes using a <span class="RktPn">#:do</span>
block. It is an error to shadow an attribute binding with a definition
in a <span class="RktPn">#:do</span> block.</p></blockquote><h5 x-source-module="(lib "syntax/scribblings/syntax.scrbl")" x-part-tag=""stxparse-attrs"">1.4.2<tt> </tt><a name="(part._stxparse-attrs)"></a>Pattern Variables and Attributes</h5><p>An <a name="(tech._attribute)"></a><span style="font-style: italic">attribute</span> is a name bound by a syntax pattern. An
attribute can be a <a href="stxparse-patterns.html#%28tech._pattern._variable%29" class="techoutside" data-pltdoc="x"><span class="techinside">pattern variable</span></a> itself, or it can be a
<a href="stxparse-patterns.html#%28tech._nested._attribute%29" class="techoutside" data-pltdoc="x"><span class="techinside">nested attribute</span></a> bound by an <a href="stxparse-patterns.html#%28tech._annotated._pattern._variable%29" class="techoutside" data-pltdoc="x"><span class="techinside">annotated pattern
variable</span></a>. The name of a nested attribute is computed by concatenating
the pattern variable name with the syntax class’s exported attribute’s
name, separated by a dot (see the example below).</p><p>Attributes can be used in two ways: with the <span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._attribute%29%29" class="RktStxLink" data-pltdoc="x">attribute</a></span> form,
and inside syntax templates via <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._syntax%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">syntax</a></span>, <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fqqstx..rkt%2529._quasisyntax%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">quasisyntax</a></span>,
etc. Attribute names cannot be used directly as expressions; that is,
attributes are not variables.</p><p>A <a name="(tech._syntax._valued._attribute)"></a><span style="font-style: italic">syntax-valued attribute</span> is an attribute whose value is a
syntax object, a syntax list of the appropriate <a href="#%28tech._ellipsis._depth%29" class="techoutside" data-pltdoc="x"><span class="techinside">ellipsis depth</span></a>,
or a tree containing <a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=Delayed_Evaluation.html%23%2528tech._promise%2529&version=6.1" class="techoutside Sq" data-pltdoc="x"><span class="techinside">promises</span></a> that when
completely forced produces a suitable syntax object or syntax
list. Syntax-valued attributes can be used within <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._syntax%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">syntax</a></span>,
<span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fqqstx..rkt%2529._quasisyntax%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">quasisyntax</a></span>, etc as part of a syntax template. If an
attribute is used inside a syntax template but it is not
syntax-valued, an error is signaled.</p><p>The value of an attribute is not required to be syntax.
Non-syntax-valued attributes can be used to return a parsed
representation of a subterm or the results of an analysis on the
subterm. A non-syntax-valued attribute should be bound using the
<span class="RktPn">#:attr</span> directive or a <span class="RktSym"><a href="stxparse-patterns.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7ebind%29%29" class="RktStxLink" data-pltdoc="x">~bind</a></span> pattern; <span class="RktPn">#:with</span>
and <span class="RktSym"><a href="stxparse-patterns.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7eparse%29%29" class="RktStxLink" data-pltdoc="x">~parse</a></span> will convert the right-hand side to a (possibly
3D) syntax object.</p><p><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><p>Example:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-syntax-class%29%29" class="RktStxLink" data-pltdoc="x">define-syntax-class</a></span><span class="hspace"> </span><span class="RktSym">table</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._pattern%29%29" class="RktStxLink" data-pltdoc="x">pattern</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">key</span><span class="hspace"> </span><span class="RktSym">value</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">#:attr</span><span class="hspace"> </span><span class="RktSym">hashtable</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=for.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._for%252Fhash%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">for/hash</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">k</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stxops.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._syntax-%7E3edatum%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">syntax->datum</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktPn">(</span><span class="RktSym">key</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym">v</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stxops.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._syntax-%7E3edatum%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">syntax->datum</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktPn">(</span><span class="RktSym">value</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=values.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._values%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">values</a></span><span class="hspace"> </span><span class="RktSym">k</span><span class="hspace"> </span><span class="RktSym">v</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">#:attr</span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym">sorted-kv</span><span class="hspace"> </span><span class="RktVal">1</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">delay</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=Writing.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._printf%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">printf</a></span><span class="hspace"> </span><span class="RktVal">"sorting!\n"</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=pairs.html%23%2528def._%2528%2528lib._racket%252Fprivate%252Flist..rkt%2529._sort%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">sort</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stxops.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._syntax-%7E3elist%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">syntax->list</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">key</span><span class="hspace"> </span><span class="RktSym">value</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=generic-numbers.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._%7E3c%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x"><</a></span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">#:key</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=lambda.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fbase..rkt%2529._lambda%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">lambda</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">kv</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._cadr%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">cadr</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stxops.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._syntax-%7E3edatum%2529%2529&version=6.1" class="RktValLink Sq" data-pltdoc="x">syntax->datum</a></span><span class="hspace"> </span><span class="RktSym">kv</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></td></tr></table></blockquote></td></tr></table></p><p>The <span class="RktSym">table</span> syntax class provides four attributes:
<span class="RktSym">key</span>, <span class="RktSym">value</span>, <span class="RktSym">hashtable</span>, and
<span class="RktSym">sorted-kv</span>. The <span class="RktSym">hashtable</span> attribute has
<a href="#%28tech._ellipsis._depth%29" class="techoutside" data-pltdoc="x"><span class="techinside">ellipsis depth</span></a> 0 and the rest have depth 1; all but
<span class="RktSym">hashtable</span> are syntax-valued. The <span class="RktSym">sorted-kv</span>
attribute’s value is a promise; it will be automatically forced if
used in a syntax template.</p><p>Syntax-valued attributes can be used in syntax templates:</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace"> </span><span class="RktVal">3</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">b</span><span class="hspace"> </span><span class="RktVal">2</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">c</span><span class="hspace"> </span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym">t:table</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktPn">(</span><span class="RktSym">t.key</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">#<syntax:72:0 (a b c)></span></p></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace"> </span><span class="RktVal">3</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">b</span><span class="hspace"> </span><span class="RktVal">2</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">c</span><span class="hspace"> </span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym">t:table</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktPn">(</span><span class="RktSym">t.sorted-kv</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktOut">sorting!</span></p></td></tr><tr><td><p><span class="RktRes">#<syntax:73:0 ((c 1) (b 2) (a 3))></span></p></td></tr></table></blockquote><p>But non-syntax-valued attributes cannot:</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace"> </span><span class="RktVal">3</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">b</span><span class="hspace"> </span><span class="RktVal">2</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">c</span><span class="hspace"> </span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym">t:table</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktSym">t.hashtable</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktErr">t.hashtable: bad attribute value for syntax template</span></p></td></tr><tr><td><p><span class="RktErr"></span><span class="hspace"> </span><span class="RktErr">attribute value: '#hash((b . 2) (a . 3) (c . 1))</span></p></td></tr><tr><td><p><span class="RktErr"></span><span class="hspace"> </span><span class="RktErr">expected for attribute: syntax</span></p></td></tr><tr><td><p><span class="RktErr"></span><span class="hspace"> </span><span class="RktErr">sub-value: '#hash((b . 2) (a . 3) (c . 1))</span></p></td></tr><tr><td><p><span class="RktErr"></span><span class="hspace"> </span><span class="RktErr">expected for sub-value: syntax at: t.hashtable</span></p></td></tr></table></blockquote><p>Use the <span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._attribute%29%29" class="RktStxLink" data-pltdoc="x">attribute</a></span> form to get the value of an attribute
(syntax-valued or not).</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace"> </span><span class="RktVal">1</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">b</span><span class="hspace"> </span><span class="RktVal">2</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">c</span><span class="hspace"> </span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym">t:table</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._attribute%29%29" class="RktStxLink" data-pltdoc="x">attribute</a></span><span class="hspace"> </span><span class="RktSym">t.hashtable</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">'#hash((b<span class="stt"> </span>. 2)<span class="stt"> </span>(a<span class="stt"> </span>. 1)<span class="stt"> </span>(c<span class="stt"> </span>. 3))</span></p></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace"> </span><span class="RktVal">3</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">b</span><span class="hspace"> </span><span class="RktVal">2</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">c</span><span class="hspace"> </span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktSym">t:table</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._attribute%29%29" class="RktStxLink" data-pltdoc="x">attribute</a></span><span class="hspace"> </span><span class="RktSym">t.sorted-kv</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">#<promise:sorted-kv183></span></p></td></tr></table></blockquote><p>Every attribute has an associated <a name="(tech._ellipsis._depth)"></a><span style="font-style: italic">ellipsis depth</span> that
determines how it can be used in a syntax template (see the discussion
of ellipses in <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._syntax%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">syntax</a></span>). For a pattern variable, the ellipsis
depth is the number of ellipses the pattern variable “occurs under”
in the pattern. An attribute bound by <span class="RktPn">#:attr</span> has depth 0
unless declared otherwise. For a nested attribute the depth is the sum
of the annotated pattern variable’s depth and the depth of the
attribute exported by the syntax class.</p><p>Consider the following code:</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._define-syntax-class%29%29" class="RktStxLink" data-pltdoc="x">define-syntax-class</a></span><span class="hspace"> </span><span class="RktSym">quark</span></td></tr><tr><td><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._pattern%29%29" class="RktStxLink" data-pltdoc="x">pattern</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace"> </span><span class="RktSym">b</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span><span class="hspace"> </span><span class="RktSym">some-term</span></td></tr><tr><td><span class="hspace"> </span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">y:quark</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="hspace"> </span><span class="RktSym">z:quark</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="RktSym">some-code</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote><p>The syntax class <span class="RktSym">quark</span> exports two attributes: <span class="RktSym">a</span> at
depth 0 and <span class="RktSym">b</span> at depth 1. The <span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span> pattern
has three pattern variables: <span class="RktSym">x</span> at depth 0, <span class="RktSym">y</span> at
depth 2, and <span class="RktSym">z</span> at depth 0. Since <span class="RktSym">x</span> and <span class="RktSym">y</span>
are annotated with the <span class="RktSym">quark</span> syntax class, the pattern also
binds the following nested attributes: <span class="RktSym">y.a</span> at depth 2,
<span class="RktSym">y.b</span> at depth 3, <span class="RktSym">z.a</span> at depth 0, and <span class="RktSym">z.b</span> at
depth 1.</p><p>An attribute’s ellipsis nesting depth is <span style="font-style: italic">not</span> a guarantee that
it is syntax-valued. In particular, <span class="RktSym"><a href="stxparse-patterns.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7eor%29%29" class="RktStxLink" data-pltdoc="x">~or</a></span> and
<span class="RktSym"><a href="stxparse-patterns.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7eoptional%29%29" class="RktStxLink" data-pltdoc="x">~optional</a></span> patterns may result in attributes with fewer than
expected levels of list nesting, and <span class="RktPn">#:attr</span> and
<span class="RktSym"><a href="stxparse-patterns.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7ebind%29%29" class="RktStxLink" data-pltdoc="x">~bind</a></span> can be used to bind attributes to arbitrary values.</p><p><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><p>Example:</p></td></tr><tr><td><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="Parsing_Syntax.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._syntax-parse%29%29" class="RktStxLink" data-pltdoc="x">syntax-parse</a></span><span class="hspace"> </span><span class="RktRdr">#'</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace"> </span><span class="RktSym">b</span><span class="hspace"> </span><span class="RktVal">3</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><a href="stxparse-patterns.html#%28form._%28%28lib._syntax%2Fparse..rkt%29._~7eor%29%29" class="RktStxLink" data-pltdoc="x">~or</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">x:id</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529._......%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">...</a></span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.1/html/local-redirect/index.html?doc=reference&rel=stx-patterns.html%23%2528form._%2528%2528lib._racket%252Fprivate%252Fstxcase-scheme..rkt%2529.__%2529%2529&version=6.1" class="RktStxLink Sq" data-pltdoc="x">_</a></span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._attribute%29%29" class="RktStxLink" data-pltdoc="x">attribute</a></span><span class="hspace"> </span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><p><span class="RktRes">#f</span></p></td></tr></table></blockquote></td></tr></table></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>syntax</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(form._((lib._syntax/parse..rkt)._attribute))"></a><span title="Provided from: syntax/parse | Package: base"><span class="RktSym"><a href="#%28form._%28%28lib._syntax%2Fparse..rkt%29._attribute%29%29" class="RktStxDef RktStxLink" data-pltdoc="x">attribute</a></span></span><span class="hspace"> </span><span class="RktVar">attr-id</span><span class="RktPn">)</span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">Returns the value associated with the <a href="#%28tech._attribute%29" class="techoutside" data-pltdoc="x"><span class="techinside">attribute</span></a> named
<span class="RktVar">attr-id</span>. If <span class="RktVar">attr-id</span> is not bound as an attribute, an
error is raised.</div></p><div class="navsetbottom"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, "6.1", "../");" onfocus="this.style.color="black"; this.style.textAlign="left"; if (this.value == "...search manuals...") this.value="";" onblur="if (this.value.match(/^ *$/)) { this.style.color="#888"; this.style.textAlign="center"; this.value="...search manuals..."; }"/></form> <a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("6.1");">top</a></span><span class="navright"> <a href="Parsing_Syntax.html" title="backward to "1.3 Parsing Syntax"" data-pltdoc="x">← prev</a> <a href="stxparse.html" title="up to "1 Parsing and Specifying Syntax"" data-pltdoc="x">up</a> <a href="stxparse-patterns.html" title="forward to "1.5 Syntax Patterns"" data-pltdoc="x">next →</a></span> </div></div></div><div id="contextindicator"> </div></body></html>
|