# orion.core.astprovider

The `orion.core.astprovider` service allows plugins to provide ASTs (<dfn>Abstract Syntax Trees</dfn>) for specific content types.

## Service methods

Implementations of `orion.core.astprovider` must define the following function:

computeAST(astContext)
  astContext is an object that contains all of the information needed to compute the AST. The astContext object currently only contains the `text` argument that contains the entire source from the current editor context.

## Service attributes

Implementations of `orion.core.astprovider` may define the following attributes:

contentType
  `Array` An array of Content Type IDs for which this command is valid.

## Examples

The following example is how Orion uses the Esprima parser internally to provide ASTs for JavaScript:

    var provider = new orion.PluginProvider();
    provider.registerService('orion.core.astprovider',
       {
           computeAST: function(astContext) {
               var ast = esprima.parse(astContext.text, {
                            loc: true,
    			range: true,
    			raw: true,
    			tokens: true,
    			comment: true,
    			tolerant: true
    		     });
    	   if (ast.errors) {
    	       ast.errors = ast.errors.map(serialize.serializeError);
    	   }
    	   return ast;
           }
       }, {
         contentType: ['application/javascript']
      });
    provider.connect();