Class: Cooklang::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/cooklang/parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(input) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cooklang/parser.rb', line 5

def parse(input)
  # Tokenize input
  lexer = Lexer.new(input)
  tokens = lexer.tokenize

  # Extract metadata
  , content_tokens = Processors::MetadataProcessor.(tokens)

  # Clean up tokens
  cleaned_tokens = Processors::TokenProcessor.strip_comments(content_tokens)
  notes, recipe_tokens = Processors::TokenProcessor.extract_notes(cleaned_tokens)

  # Parse steps
  parsed_steps = Processors::StepProcessor.parse_steps(recipe_tokens)

  # Build final recipe
  recipe = Builders::RecipeBuilder.build_recipe(parsed_steps, )

  # Add notes to recipe (create new recipe with notes)
  Recipe.new(
    ingredients: recipe.ingredients,
    cookware: recipe.cookware,
    timers: recipe.timers,
    steps: recipe.steps,
    metadata: recipe.,
    sections: recipe.sections,
    notes: notes
  )
end