Class: SolidAgent::AgentManifest::ParserRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_agent/agent_manifest/parser_registry.rb

Overview

ParserRegistry manages format parsers and provides format detection.

It enables automatic detection of file formats and routes parsing to the appropriate parser class.

Examples:

Parsing a file

manifest = ParserRegistry.parse("agent.agent.md")
manifest = ParserRegistry.parse("agent.prompt", format: :dotprompt)

Registering a custom parser

ParserRegistry.register(:custom, MyCustomParser)

Class Method Summary collapse

Class Method Details

.detect_format(path) ⇒ Symbol

Detect format from file path

Parameters:

  • path (String)

    File path

Returns:

  • (Symbol)

    Detected format

Raises:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 48

def detect_format(path)
  extension = File.extname(path).downcase

  case extension
  when ".md"
    detect_markdown_format(path)
  when ".prompt"
    :dotprompt
  when ".yaml", ".yml"
    detect_yaml_format(path)
  when ".json"
    detect_json_format(path)
  else
    raise UnknownFormatError, "Cannot detect format for extension: #{extension}"
  end
end

.format_supported?(format) ⇒ Boolean

Check if a format is supported

Parameters:

  • format (Symbol)

    Format to check

Returns:

  • (Boolean)


101
102
103
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 101

def format_supported?(format)
  parsers.key?(format.to_sym)
end

.formatsArray<Symbol>

Alias for registered_formats

Returns:

  • (Array<Symbol>)


93
94
95
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 93

def formats
  registered_formats
end

.parse(path, format: nil) ⇒ Manifest

Parse a file, auto-detecting format if not specified

Parameters:

  • path (String)

    Path to the file

  • format (Symbol, nil) (defaults to: nil)

    Optional format override

Returns:



70
71
72
73
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 70

def parse(path, format: nil)
  format ||= detect_format(path)
  parser_for(format).parse(path)
end

.parse_string(content, format:) ⇒ Manifest

Parse content string with explicit format

Parameters:

  • content (String)

    File content

  • format (Symbol)

    Format identifier

Returns:



80
81
82
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 80

def parse_string(content, format:)
  parser_for(format).parse_string(content)
end

.parser_for(format) ⇒ Class

Get parser for a format

Parameters:

  • format (Symbol)

    Format identifier

Returns:

  • (Class)

    Parser class

Raises:



39
40
41
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 39

def parser_for(format)
  parsers[format.to_sym] || raise(UnknownFormatError, "No parser registered for format: #{format}")
end

.parsersHash{Symbol => Class}

Registered parsers by format

Returns:

  • (Hash{Symbol => Class})


22
23
24
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 22

def parsers
  @parsers ||= {}
end

.register(format, parser_class) ⇒ Object

Register a parser for a format

Parameters:

  • format (Symbol)

    Format identifier

  • parser_class (Class)

    Parser class (must respond to .parse and .parse_string)



30
31
32
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 30

def register(format, parser_class)
  parsers[format.to_sym] = parser_class
end

.registered_formatsArray<Symbol>

List all registered formats

Returns:

  • (Array<Symbol>)


87
88
89
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 87

def registered_formats
  parsers.keys
end

.supports?(format) ⇒ Boolean

Alias for format_supported?

Returns:

  • (Boolean)


107
108
109
# File 'lib/solid_agent/agent_manifest/parser_registry.rb', line 107

def supports?(format)
  format_supported?(format)
end