Added automatic markup of method arguments.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11138 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2001-10-14 10:39:23 +00:00
parent 69fd54f1fa
commit c5df5288f5
4 changed files with 126 additions and 49 deletions

View file

@ -28,6 +28,7 @@
NSCharacterSet *identStart; // Legit initial char of identifier NSCharacterSet *identStart; // Legit initial char of identifier
NSCharacterSet *spaces; // All blank characters NSCharacterSet *spaces; // All blank characters
NSCharacterSet *spacenl; // Blanks excluding newline NSCharacterSet *spacenl; // Blanks excluding newline
NSArray *args; // Not retained.
} }
- (unsigned) fitWords: (NSArray*)a - (unsigned) fitWords: (NSArray*)a

View file

@ -32,7 +32,7 @@ static BOOL snuggleEnd(NSString *t)
} }
if (set == nil) if (set == nil)
{ {
set = [NSCharacterSet characterSetWithCharactersInString: @"]}).,;"]; set = [NSCharacterSet characterSetWithCharactersInString: @"]}).,;?!"];
RETAIN(set); RETAIN(set);
} }
return [set characterIsMember: [t characterAtIndex: 0]]; return [set characterIsMember: [t characterAtIndex: 0]];
@ -388,7 +388,6 @@ static BOOL snuggleStart(NSString *t)
*/ */
- (void) outputMethod: (NSDictionary*)d to: (NSMutableString*)str - (void) outputMethod: (NSDictionary*)d to: (NSMutableString*)str
{ {
NSArray *args = [d objectForKey: @"Args"];
NSArray *sels = [d objectForKey: @"Sels"]; NSArray *sels = [d objectForKey: @"Sels"];
NSArray *types = [d objectForKey: @"Types"]; NSArray *types = [d objectForKey: @"Types"];
NSString *name = [d objectForKey: @"Name"]; NSString *name = [d objectForKey: @"Name"];
@ -398,6 +397,8 @@ static BOOL snuggleStart(NSString *t)
NSString *override = nil; NSString *override = nil;
NSString *standards = nil; NSString *standards = nil;
args = [d objectForKey: @"Args"]; // Used when splitting.
tmp = [d objectForKey: @"Comment"]; tmp = [d objectForKey: @"Comment"];
/** /**
@ -527,6 +528,7 @@ static BOOL snuggleStart(NSString *t)
[self reformat: standards withIndent: 10 to: str]; [self reformat: standards withIndent: 10 to: str];
} }
[str appendString: @" </method>\n"]; [str appendString: @" </method>\n"];
args = nil;
} }
- (void) outputUnit: (NSDictionary*)d to: (NSMutableString*)str - (void) outputUnit: (NSDictionary*)d to: (NSMutableString*)str
@ -747,12 +749,13 @@ static BOOL snuggleStart(NSString *t)
unichar *buf; unichar *buf;
/** /**
* Phase 1 ... we take the supplied string andcheck for white space. * Phase 1 ... we take the supplied string and check for white space.
* Any white space sequence is deleted and treated as a word separator * Any white space sequence is deleted and treated as a word separator
* except within xml element markup. The format of element start and * except within xml element markup. The format of element start and
* end marks is tidied for consistency. The resulting data is made * end marks is tidied for consistency. The resulting data is made
* into an array of strings, each containing either an element start * into an array of strings, each containing either an element start
* or end tag, or one of the whitespace separated words. * or end tag, or one of the whitespace separated words.
* What about str?
*/ */
data = [[NSMutableData alloc] initWithLength: l * sizeof(unichar)]; data = [[NSMutableData alloc] initWithLength: l * sizeof(unichar)];
ptr = buf = [data mutableBytes]; ptr = buf = [data mutableBytes];
@ -895,75 +898,145 @@ static BOOL snuggleStart(NSString *t)
for (l = 0; l < [a count]; l++) for (l = 0; l < [a count]; l++)
{ {
static NSArray *constants = nil; static NSArray *constants = nil;
static unsigned cCount = 0; unsigned count;
NSString *tmp = [a objectAtIndex: l]; NSString *tmp = [a objectAtIndex: l];
unsigned pos; unsigned pos;
NSRange r; NSRange r;
BOOL hadMethod = NO; BOOL hadMethod = NO;
/*
* Ensure that well known constants are rendered as 'code'
*/
if (constants == nil) if (constants == nil)
{ {
constants = [[NSArray alloc] initWithObjects: constants = [[NSArray alloc] initWithObjects:
@"YES", @"NO", @"nil", nil]; @"YES", @"NO", @"nil", nil];
cCount = [constants count];
} }
for (pos = 0; pos < cCount; pos++)
if (l == 0 || [[a objectAtIndex: l-1] isEqual: @"<code>"] == NO)
{ {
NSString *c = [constants objectAtIndex: pos]; /*
* Ensure that well known constants are rendered as 'code'
r = [tmp rangeOfString: c]; */
count = [constants count];
if (r.length > 0) for (pos = 0; pos < count; pos++)
{ {
NSString *start; NSString *c = [constants objectAtIndex: pos];
NSString *end;
if (r.location > 0) r = [tmp rangeOfString: c];
{
start = [tmp substringToIndex: r.location];
}
else
{
start = nil;
}
if (NSMaxRange(r) < [tmp length])
{
end = [tmp substringFromIndex: NSMaxRange(r)];
}
else
{
end = nil;
}
if ((start == nil || snuggleStart(start) == YES)
&& (end == nil || snuggleEnd(end) == YES))
{
NSString *sub;
if (start != nil || end != nil) if (r.length > 0)
{
NSString *start;
NSString *end;
if (r.location > 0)
{ {
sub = [tmp substringWithRange: r]; start = [tmp substringToIndex: r.location];
} }
else else
{ {
sub = nil; start = nil;
} }
if (start != nil) if (NSMaxRange(r) < [tmp length])
{ {
[a insertObject: start atIndex: l++]; end = [tmp substringFromIndex: NSMaxRange(r)];
} }
[a insertObject: @"<code>" atIndex: l++]; else
if (sub != nil)
{ {
[a replaceObjectAtIndex: l withObject: sub]; end = nil;
} }
l++; if ((start == nil || snuggleStart(start) == YES)
[a insertObject: @"</code>" atIndex: l]; && (end == nil || snuggleEnd(end) == YES))
if (end != nil)
{ {
[a insertObject: end atIndex: ++l]; NSString *sub;
if (start != nil || end != nil)
{
sub = [tmp substringWithRange: r];
}
else
{
sub = nil;
}
if (start != nil)
{
[a insertObject: start atIndex: l++];
}
[a insertObject: @"<code>" atIndex: l++];
if (sub != nil)
{
[a replaceObjectAtIndex: l withObject: sub];
}
l++;
[a insertObject: @"</code>" atIndex: l];
if (end != nil)
{
[a insertObject: end atIndex: ++l];
}
}
}
}
}
/*
* Ensure that method arguments are rendered as 'var'
*/
if (l == 0 || [[a objectAtIndex: l-1] isEqual: @"<var>"] == NO)
{
count = [args count];
for (pos = 0; pos < count; pos++)
{
NSString *c = [args objectAtIndex: pos];
r = [tmp rangeOfString: c];
if (r.length > 0)
{
NSString *start;
NSString *end;
if (r.location > 0)
{
start = [tmp substringToIndex: r.location];
}
else
{
start = nil;
}
if (NSMaxRange(r) < [tmp length])
{
end = [tmp substringFromIndex: NSMaxRange(r)];
}
else
{
end = nil;
}
if ((start == nil || snuggleStart(start) == YES)
&& (end == nil || snuggleEnd(end) == YES))
{
NSString *sub;
if (start != nil || end != nil)
{
sub = [tmp substringWithRange: r];
}
else
{
sub = nil;
}
if (start != nil)
{
[a insertObject: start atIndex: l++];
}
[a insertObject: @"<var>" atIndex: l++];
if (sub != nil)
{
[a replaceObjectAtIndex: l withObject: sub];
}
l++;
[a insertObject: @"</var>" atIndex: l];
if (end != nil)
{
[a insertObject: end atIndex: ++l];
}
} }
} }
} }

View file

@ -127,6 +127,9 @@
<item>Certain well known constants such as YES, NO, and nil are <item>Certain well known constants such as YES, NO, and nil are
enclosed in &lt;code&gt; ... &lt;/code&gt; markup. enclosed in &lt;code&gt; ... &lt;/code&gt; markup.
</item> </item>
<item>The names of method arguments within method descriptions are
enclosed in &lt;var&gt; ... &lt;/var&gt; markup.
</item>
<item>Method names (beginning with a plus or minus) are enclosed <item>Method names (beginning with a plus or minus) are enclosed
in &lt;ref...&gt; ... &lt;/ref&gt; markup. in &lt;ref...&gt; ... &lt;/ref&gt; markup.
</item> </item>

View file

@ -86,7 +86,7 @@
<!--***** Phrase elements. *****--> <!--***** Phrase elements. *****-->
<!-- The content is a metasyntactic variable name. --> <!-- The content is a metasyntactic variable or argument name. -->
<!ELEMENT var (%text;)*> <!ELEMENT var (%text;)*>
<!-- The content is a metasyntactic ivariable name. --> <!-- The content is a metasyntactic ivariable name. -->