lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In October 2013, Egil, Roberto wrote:
Anyway, it seems we both agree the C documentation is quite convoluted
about this topic.  So, the question remains whether it is worth trying
to explain something similar in the Lua manual, versus leaving it open
to the user's imagination or own tests...

-- Roberto



I would suggest a note that file:read("*n") (being based on based on C function fscanf)
> is  not recommended unless it is certain that the stream return a valid textual number.

Egil

There are several levels of parsers available to the user:
    - The ANSI C's strtod() function as provided via the scanf() family of functions;
    - Lua's string library, with its pattern-matching facilities;
    - Writing a parser more explicitly in Lua, with the possibility of extending
      and/or replacing the hand-crafted the Lua code with C code as desired;
             ...and a more recent addition:
    - Using more explicit lexical analysers/compiler libraries such as LPeg.

The introduction of LPeg has changed the nature of the terrain somewhat; my
suspicion is that a future version of PiL might contain at least a pointer to
LPeg when discussing parsing text.

Laying out a list of options, ranging from simple to complex, as given above,
may give the reader a "heads-up" about the potential complexity of the
problem, and show some of the existing solutions, with varying power/complexity
engineering trade-offs, that are available to tackle the task.

cheers,

behoffski