Skip to content

feat(config): complete config file parser (tokenizer + parser)#19

Merged
byronlove111 merged 3 commits into
mainfrom
config-parsing
Jun 18, 2026
Merged

feat(config): complete config file parser (tokenizer + parser)#19
byronlove111 merged 3 commits into
mainfrom
config-parsing

Conversation

@arthurpnl

@arthurpnl arthurpnl commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Objectif

Module config parsing complet : transforme un fichier .conf (façon NGINX) en une structure Config validée, prête à être consommée par le reste du serveur. Respecte l'interface du mock (Config / ServerConfig / LocationConfig) — il remplit les mêmes structures que createMockConfig().

Architecture (recursive descent, 2 étages)

Étage 1 — Tokenizer (Tokenizer.hpp/.cpp)

  • Lexer complet : mots, nombres, symboles ({ } ;), commentaires #
  • Suivi du numéro de ligne pour des messages d'erreur précis
  • Découpé en helpers (makeSymbol, readWordOrNumber)

Étage 2 — Parser (ConfigParser.hpp/.cpp)

  • Lecture du fichier + gestion d'erreur (throw si introuvable)
  • Helpers de navigation : current(), advance(), expect()
  • parse()parseServer()parseServerDirective() / parseLocation()parseLocationDirective()
  • Directives server : listen, host, server_name, client_max_body_size, error_page
  • Directives location : root, index, autoindex, methods, upload_store, cgi_extensions
  • parseSize() : suffixe k/m/g pour client_max_body_size + garde-fou anti-débordement

Robustesse

  • advance() ne lit jamais au-delà de END_OF_FILEpas de crash sur fichier tronqué
  • Toute config malformée lève une exception claire (Unexpected token at line N), rattrapée proprement — aucun segfault

Tests

  • tests/config/test_tokenizer.cpp — vérifie le découpage en tokens
  • tests/config/test_parser.cpp — parse default.conf et affiche le Config complet (servers, locations, methods, cgi…)
  • Compile en -Wall -Wextra -Werror -std=c++98

Reste à faire (hors PR)

  • Validation sémantique (port ∈ [1,65535], host:port unique…)
  • Branchement dans le main (remplacer le mock par le parser)

- Tokenizer: full lexer (words, numbers, symbols, comments, line tracking)
- ConfigParser: file reading + navigation helpers (current/advance/expect)
  + parseServer skeleton (recognizes server block structure)
- tests: standalone harnesses for tokenizer and parser

WIP: directive and location parsing still to come.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- parseLocation + parseLocationDirective (root, index, autoindex,
  methods, upload_store, cgi_extensions)
- parseSize: client_max_body_size with k/m/g suffix + overflow guard
- advance() guard against reading past END_OF_FILE (no crash on
  truncated files)
- verbose test harness printing the full parsed Config

default.conf now parses fully; malformed/truncated configs throw
cleanly without crashing.
@arthurpnl arthurpnl changed the title feat(config): tokenizer + config parser scaffolding (WIP) feat(config): complete config file parser (tokenizer + parser) Jun 18, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@byronlove111 byronlove111 merged commit 2714f92 into main Jun 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants