SwiftStudies / OysterKit

OysterKit is a framework that provides a native Swift scanning, lexical analysis, and parsing capabilities. In addition it provides a language that can be used to rapidly define the rules used by OysterKit called STLR
BSD 2-Clause "Simplified" License
177 stars 23 forks source link

STLR: using singular term for predefined characters #11

Closed markmunz closed 6 years ago

markmunz commented 6 years ago

Use singular for predefined sets (.decimalDigit, .letter vs. .decimalDigits, .letters)

ICU specifies character categories in singular terms (\p{Decimal}, \p{Letter}) with the quantifier being separate (+, *, ?, {n,m})

SLTR rule also uses modifiers (?,*,+) to specify quantity and seems more in line with a Regular Expression type of declaration. Plural term in the definition seems to imply multiple of given category, when it's only one of N. When you read the STLR

number = .decimalDigits

One could infer it to match the number "123" when in fact it will only match the "1"

Examples of the singular w/ modifiers:

digits = .decimalDigit+ // one or more of a decimal digit ows = .whitespace? // optional whitespace char

SwiftStudies commented 6 years ago

Thanks for raising this. I've been thinking about it over the weekend and last few days and my feeling is that I wish to remain consistent with Swift foundation at this time. One of the reasons for this decision is actually the other request for a .backslash which would actually be a single character terminal where the singular now makes sense, and consequently the plural is communicating something.