Class Parser
Main entry point for the Mangrove lightweight parser.
Inherited Members
Namespace: Mangrove.Parsing
Assembly: Mangrove.Parsing.dll
Syntax
public class Parser
Remarks
The current implementation is a very incomplete MVP. It has these known gaps:
- The order of expression and table parsing is not chosen dynamically. Users have to provide a metric set in which columns are defined before they are used.
- Binary aggregations aren't supported yet.
- A "standard library" of helper functions (e.g., string matches, starts with, ends with, etc.).
- User-defined functions (called "generic templates", in the old syntax), with one or more arguments or table parameters.
- Support for Kusto or Spark Sql expression parsing.
- Support for "less than" and "greater than" binary operations.
These gaps will be filled in based on ease of implementation and customer demand.
Constructors
View SourceParser(MetricsPlan, Boolean, IMetricsPlanValidator)
Instantiate a compiler object with context in the form of a MetricsPlan object. That context will become part of the state of the compiler. It could include: Table objects only, some Tables with corresponding DataSourceColumn objects, or a partially complete collection of Table and Expression nodes.
Declaration
public Parser(MetricsPlan context, bool strict, IMetricsPlanValidator validator)
Parameters
Type | Name | Description |
---|---|---|
MetricsPlan | context | Initial context. |
Boolean | strict | Whether or not to treat warnings as errors. |
IMetricsPlanValidator | validator |
Remarks
Note: the initial context
can contain empty
Tables and Expressions collections,
so this class can be used to parse single "expression snippets" without necessarily
deserializing an entire collection of XML or YAML files.
Parser(MutableMetricsPlan, Boolean, IMetricsPlanValidator, Boolean)
Instantiate with an already mutable version of a MetricsPlan.
Declaration
public Parser(MutableMetricsPlan context, bool strict, IMetricsPlanValidator validator, bool sparkCompatible = false)
Parameters
Type | Name | Description |
---|---|---|
MutableMetricsPlan | context | |
Boolean | strict | |
IMetricsPlanValidator | validator | |
Boolean | sparkCompatible |
Parser(Stream, Boolean, IMetricsPlanValidator)
Instantiate a compiler from a serialized MetricsPlan.
Declaration
public Parser(Stream serializedPlan, bool strict, IMetricsPlanValidator validator)
Parameters
Type | Name | Description |
---|---|---|
Stream | serializedPlan | Serialized initial context. |
Boolean | strict | Whether or not to treat warnings as errors. |
IMetricsPlanValidator | validator |
Properties
View SourceStrict
Whether or not this compiler is strict (treats warnings as errors). If set to
true
, this compiler will return IDiagnostics objects with
empty Warnings, and any content which would have been
a warning added to Errors.
Declaration
public bool Strict { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
View SourceContext()
Current "state" of this compiler, in the form of a valid MetricsPlan. If this is called before any invocations of "parse and add", it will be identical to the MetricsPlan passed into the constructor.
Declaration
public MetricsPlan Context()
Returns
Type | Description |
---|---|
MetricsPlan |
CreateParser(MetricsPlan, Boolean)
Create a wrapper for filter / trigger / segment expression parsing logic we can inject into the appropriate IMetricsPlanTransformer.
Declaration
public static Func<string, Expression> CreateParser(MetricsPlan metricsPlan, bool sparkCompatible = false)
Parameters
Type | Name | Description |
---|---|---|
MetricsPlan | metricsPlan | |
Boolean | sparkCompatible |
Returns
Type | Description |
---|---|
Func<String, Expression> |
Parse(IParseableExpression)
Attempt to parse the content of an IParseableExpression, but do not modify current state.
Declaration
public IParsed<Expression> Parse(IParseableExpression expression)
Parameters
Type | Name | Description |
---|---|---|
IParseableExpression | expression |
Returns
Type | Description |
---|---|
IParsed<Expression> |
Parse(IParseableMetricSet, Boolean, IMetricsPlanValidator)
Parse all the IParseableExpression and IParseableTable objects in an IParseableMetricSet to construct a MetricsPlan.
Declaration
public static IParsed<MetricsPlan> Parse(IParseableMetricSet metricSet, bool strict, IMetricsPlanValidator validator)
Parameters
Type | Name | Description |
---|---|---|
IParseableMetricSet | metricSet | May come from a file or entities in a database. |
Boolean | strict | Whether or not to treat warnings as errors. |
IMetricsPlanValidator | validator |
Returns
Type | Description |
---|---|
IParsed<MetricsPlan> |
Parse(IParseableTable)
Attempt to parse the content of an IParseableTable, but do not modify current state.
Declaration
public IParsed<Table> Parse(IParseableTable table)
Parameters
Type | Name | Description |
---|---|---|
IParseableTable | table |
Returns
Type | Description |
---|---|
IParsed<Table> |
Parse(IEnumerable<IParseableExpression>)
Attempt to parse the content of a sequence of IParseableExpression which may depend on each other, but do not modify current state.
Declaration
public IReadOnlyList<IParsed<Expression>> Parse(IEnumerable<IParseableExpression> expressions)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IParseableExpression> | expressions |
Returns
Type | Description |
---|---|
IReadOnlyList<IParsed<Expression>> |
Parse(IEnumerable<IParseableTable>)
Attempt to parse the content of a sequence of IParseableTable which may depend on each other, but do not modify current state.
Declaration
public IReadOnlyList<IParsed<Table>> Parse(IEnumerable<IParseableTable> tables)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IParseableTable> | tables |
Returns
Type | Description |
---|---|
IReadOnlyList<IParsed<Table>> |
ParseAndAdd(IParseableExpression)
Attempt to parse the content of an IParseableExpression and add the result to Context() if succesful.
Declaration
public IParsed<Expression> ParseAndAdd(IParseableExpression expression)
Parameters
Type | Name | Description |
---|---|---|
IParseableExpression | expression |
Returns
Type | Description |
---|---|
IParsed<Expression> |
ParseAndAdd(IParseableTable)
Attempt to parse the content of an IParseableTable and add the result to Context() if succesful.
Declaration
public IParsed<Table> ParseAndAdd(IParseableTable table)
Parameters
Type | Name | Description |
---|---|---|
IParseableTable | table |
Returns
Type | Description |
---|---|
IParsed<Table> |
ParseAndAdd(IEnumerable<IParseableExpression>)
Attempt to parse the content of a sequence of IParseableExpression which may depend on each other, adding the results to Context() only if every individual parse succeeds.
Declaration
public IReadOnlyList<IParsed<Expression>> ParseAndAdd(IEnumerable<IParseableExpression> expressions)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IParseableExpression> | expressions |
Returns
Type | Description |
---|---|
IReadOnlyList<IParsed<Expression>> |
ParseAndAdd(IEnumerable<IParseableTable>)
Attempt to parse the content of a sequence of IParseableTable which may depend on each other, adding the results to Context() only if every individual parse succeeds.
Declaration
public IReadOnlyList<IParsed<Table>> ParseAndAdd(IEnumerable<IParseableTable> tables)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IParseableTable> | tables |
Returns
Type | Description |
---|---|
IReadOnlyList<IParsed<Table>> |