[ prog / sol / mona ]

prog


How can I run my own instance of this

32 2020-02-18 23:54

Here is a regular grammar for quotelink:

number -> [1-9][0-9]*
range -> number "-" number
numberorrange -> number | range
list -> numberorrange ("," numberorrange)*

The resulting regex, with extra parens for pair highlighting:

(([1-9][0-9]*)|(([1-9][0-9]*)-([1-9][0-9]*)))(,(([1-9][0-9]*)|(([1-9][0-9]*)-([1-9][0-9]*))))*
^^  number   ^ ^^  number   ^ ^  number   ^^^  ^^  number   ^ ^^  number   ^ ^  number   ^^^
|+-----------+ |+-----------+ +-----------+||  |+-----------+ |+-----------+ +-----------+||
|              |           range           ||  |              |           range           ||
|              +---------------------------+|  |              +---------------------------+|
|            numberorrange                  |  |            numberorrange                  |
+-------------------------------------------+  +-------------------------------------------+

This can be "simplified" by making the range-closing optional, but such "simplifications" tend to be counterproductive for long-term maintainability. And you should still add strict sanity checks in bbs.scm:posts-range.

301


VIP:

do not edit these