IParseSink::CodeSpan Method
Called for each region that contains executable code.
HRESULT CodeSpan (
long startLine,
long startIdx,
long endLine,
long endIdx
);
Parameters
startLine
[in] Specifies the starting line for the code region.startIdx
[in] Specifies the starting index position on startLine for the first character in the region.endLine
[in] Specifies the ending line for the code region.endIdx
[in] Specifies the ending index position on endLine for the last character in the region.
Return Value
If the method succeeds, it returns S_OK. If it fails, it returns an error code.
Remarks
Call this method only if your IBabelService::ParseSource Method implementation is called with the ParseReason Enumeration value of ReasonCodeSpan in the reason parameter. You should call IParseSink::CodeSpan once for each code region containing executable code that is found in the span of text passed to you in the text parameter of IBabelService::ParseSource Method.
This method is used to validate breakpoints. Comments, and so on, are automatically taken care of. Normally this method is called on procedure or method blocks.
The Default Babel Implementation in the Language Service Package, this method is called from the StdService::codeSpan method that in turn can be called from within your grammar file. The Example in this topic shows how the codeSpan method is called when a span of code is parsed.
For a more detailed example of using the StdService::codeSpan, see the "Code Spans" section of How to: Enable Debugger Autos Window Support.
Example
This is an edited fragment from the default parser.y grammar file that is created using the Visual Studio Language Service Wizard. This fragment shows how a block, both empty and with code content, is parsed; specifically, how and when calls are made to the codeSpan method on the language service (g_service). The codeSpan method eventually calls the IParseSink::CodeSpan method.
Block
: '{' '}' { $$ = $2;
g_service->matchPair($1,$2);
g_service->codeSpan($1,$2);
g_service->addScopeText( $1, $2, ScopeBlock, AccessPublic, StorageNone); }
| '{' BlockContent1 '}'
{ $$ = $3;
g_service->matchPair($1,$3);
g_service->codeSpan($1,$3);
g_service->addScopeText( $1, $3, ScopeBlock, AccessPublic, StorageNone); }
| '{' BlockContent1 error
{ $$ = @3;
g_service->codeSpan($1,$3);
g_service->expectError( "block", "}" );
g_service->addScopeText( $1, @3, ScopeBlock, AccessPublic, StorageNone); }
| '{' error '}'
{ $$ = $3;
g_service->codeSpan($1,$3);
g_service->matchPair($1,$3);
g_service->syntaxError( "block", &@2 );
g_service->addScopeText( $1, $3, ScopeBlock, AccessPublic, StorageNone ); }
;
See Also
Concepts
How to: Enable Debugger Autos Window Support