lua-users home
lua-l archive

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


> On Thu, Apr 24, 2014 at 11:22 AM, Thiago L. <fakedme@gmail.com> wrote:
>> On 24/04/2014 12:41, steve donovan wrote:
>>> [...]
>> Well something like what I said... I would actually expect str:sub(inf)
>> to expand to str:sub(#str+1) and str:sub(-inf,inf) to expand to
>> str:sub(0,#str+1)... or something...
>
> This is a really basic question (maybe so much so as to be off-topic):
>
> What is all of this useful for? Where do you guys come across this in real
> life?

For my part, I was developing on the markdown parser and had a pattern
like this:

    [[ Parsing recursive HTML5 tag structures ]]
    1. Initialize "from, to = 1, 1/0"
    2. Find first opening tag and set "from" to index after opening tag
    3. Resolve recursive structure and find closing tag at equivalent depth
    4. Set "to" to index before closing tag
    5. Parse "source_code:sub(from, to)" recursively.

    The point here is, that for empty tags I don't have to treat indices
    in a special way. "to" keeps its infinity value and will return the
    string until the end.

    ... until I realized that infinity is unsupported.

[You might want to argue that I could initialize "to" with "#source_code"
but of course this algorithm is simplified. "#source_code" is more dynamic
/ more difficult to maintain in my real-world source code]

best regards,
meisterluk