Lexes an ngspice netlist into the intermediate representation the NgspiceCircuitFactory consumes ( todo/ngspice_parser_plan.md §9.1 ).
Handled here: the mandatory title line ( always consumed, never parsed ); full-line '' comments; "</em> belfem:" directives ( single line, recognized before the comment strip, whitespace tolerated before the colon ); end-of-line comments ';', '$' and token-leading '//' ( PSPICE compatibility decks, where '$' is an ordinary character, are not supported ); leading '+' continuations; '(' ')' ',' normalized to spaces and whitespace around '=' removed before tokenizing; case-folding of every identifier; ".end" ( exactly that token – trailing tokens hard-error ) after which remaining lines are ignored; the ordered first-appearance node-name list ( restart contract O9 ), including nodes introduced only by a directive's n+/n- keys.
Two deliberate BELFEM extensions beyond the manual's strict wording ( the manual both demands that continuations "immediately
follow" and declares empty lines ignored and comment lines legal anywhere ): comment and blank lines may sit between a card and its '+' continuation, and EOF terminates a deck that has no ".end". Both accept strictly more than stock ngspice and never reinterpret a deck ngspice accepts. A "* belfem:" DIRECTIVE is a statement, not a comment: it completes the pending card ( so node collection follows line order, O9 ) and ends the continuation chain.
Hard errors ( BELFEM_ERROR, each naming source, line and card ): unsupported element letters – controlled switches S/W ( use the "* belfem: switch" directive ), subcircuit instances X, and every other letter beyond R/C/L/V/I/D; every control card except ".model", ".tran" and ".end" ( .subckt/.control/.ac/.dc/.op/ .param/.ic/... – v1 refuses rather than silently altering the deck, plan §12.2 ); a continuation with no card to continue; an element card with fewer than two nodes; a deck with no cards.
Parameter-level policy ( e.g. rejecting "ic=" on a supported card ) is deliberately NOT enforced here – the factory owns card semantics.