Share via


IBabelService::ParseSource Method

Parses a specified block of text for the specified reason.

HRESULT ParseSource ( 
   BSTR text,
   IParseSink* sink,
   ParseReason reason,
   long reserved,
   IScope** scope
);

Parameters

  • text
    [in] Block of text to parse.

  • sink
    [in] Specifies the parse sink. For more information, see the IParseSink Interface.

  • reason
    [in] Specifies the reason for parsing, such as matching braces, error checking, and so on. See ParseReason.

  • reserved
    [in] Reserved for future use.

  • scope
    [out] Specifies the scope, that is, the symbol tree for the block of text specified in the text parameter. A scope object is only required when a value of ReasonCheck is specified in the reason parameter. ReasonCheck is only called at idle time.

    You can either implement the IScope Interface yourself, or use the default IScope implementation provided by the default Babel implementation. If you are using the default implementation, then return a value of NULL for the scope parameter.

Return Value

If the method succeeds, it returns S_OK. If it fails, it returns an error code.

Remarks

The reason for calling this method is passed in the reason parameter. Use the IParseSink Interface object to provide information to the Babel Package from your parser regarding where error markers, matching braces, and so on reside in the given span of text specified in the text parameter.

If the reason parameter is equal to a value of ReasonCheck (see ParseReason Enumeration), then an IScope Interface object (that is, a symbol tree) should be built and returned in the scope parameter. A default implementation of the IScope interface is provided with the Babel package. If you choose to use the default IScope object, you can call methods on the IParseSink Interface object to add information to that default scope. For example, to add information about a token or statement, call the IParseSink::AddScope Method with information describing that token. Then return NULL for the scope parameter and the Babel Package uses the default scope.

However, if you need to implement your own version of the IScope object, you must return an instance of that IScope object in the scope parameter and you must not call the IParseSink::AddScope method, IParseSink::AddInclude Method, or the IParseSink::AddExtern Method as those methods only affect the default IScope object. These particular IParseSink methods forward each call to equivalent methods on the default IScope object. Your version of the IScope interface can provide equivalent methods that you can call directly from your parser but what those methods actually do is entirely up to you.

See Also

Reference

IBabelService Interface

IParseSink Interface

IScope Interface

ParseReason