parserForType function

DesignTokenParser parserForType(
  1. String type, {
  2. int indentationLevel = 1,
  3. BuilderConfig? config,
})

Returns the DesignTokenParser for the given type.

Therefore the method checks DesignTokenParser.tokenType array if it contains the passed type. Make to register one DesignTokenParser per type. Otherwise the wrong parser might be returned.

Implementation

DesignTokenParser parserForType(
  String type, {
  int indentationLevel = 1,
  BuilderConfig? config,
}) {
  try {
    return [
      BorderParser(indentationLevel, config),
      BorderRadiusParser(indentationLevel, config),
      BoxShadowParser(indentationLevel, config),
      ColorParser(indentationLevel, config),
      DimensionParser(indentationLevel, config),
      FontFamilyParser(indentationLevel, config),
      FontWeightParser(indentationLevel, config),
      LineHeightParser(indentationLevel, config),
      NumberParser(indentationLevel, config),
      OpacityParser(indentationLevel, config),
      SpacingParser(indentationLevel, config),
      TextCaseParser(indentationLevel, config),
      TextDecorationParser(indentationLevel, config),
      TypographyParser(indentationLevel, config),
    ].firstWhere((element) => element.tokenType.contains(type));
  } catch (e) {
    throw Exception('No parser found for type $type');
  }
}