[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Infinity as index
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 25 Apr 2014 10:14:39 +0200
2014-04-24 23:08 GMT+02:00 Lukas Prokop <admin@lukas-prokop.at>:
> [[ 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]
You could also initialize `to` to -1. By the time string.sub is hit, the
main argument must be a string, and -1 addresses its last bit.