Small single-file spec for payments such as EUR 50.5 due on May 31, 2025.
What it shows
$flags: FLEXIBLE_WHITESPACElets patterns tolerate any whitespace between tokens.Numbersplits into semantic subtypesDecimalandInteger— order matters, soDecimalis tried first.Monthgives each full month name its own stable identity.DateseparatesYearMonthDay,MonthDayYear,DayMonthYear, andTextualDaterepresentations. Each exposesyear,month, andday.Currencyis a small enum (EUR,USD,GBP).Moneycomposescurrencyandamount;Paymentgives that value theamountrole and its date thedueDaterole.
Try adding another currency, adding a new Date shape, or extending Payment with an optional amount range.
Specs
spec.yml
$flags: 'FLEXIBLE_WHITESPACE'
Number:
Decimal: '\d+\.\d+'
Integer: '\d+'
Month:
January: 'January'
February: 'February'
March: 'March'
April: 'April'
May: 'May'
June: 'June'
July: 'July'
August: 'August'
September: 'September'
October: 'October'
November: 'November'
December: 'December'
Date:
YearMonthDay:
$fields:
day: { $type: Number::Integer, $match: '0[1-9]|[12]\d|3[01]' }
month: { $type: Number::Integer, $match: '0[1-9]|1[0-2]' }
year: { $type: Number::Integer, $match: '\d{4}' }
$patterns: '#{year}-#{month}-#{day}'
MonthDayYear:
$fields:
day: { $type: Number::Integer, $match: '0[1-9]|[12]\d|3[01]' }
month: { $type: Number::Integer, $match: '0[1-9]|1[0-2]' }
year: { $type: Number::Integer, $match: '\d{4}' }
$patterns: '#{month}/#{day}/#{year}'
DayMonthYear:
$fields:
day: { $type: Number::Integer, $match: '0[1-9]|[12]\d|3[01]' }
month: { $type: Number::Integer, $match: '0[1-9]|1[0-2]' }
year: { $type: Number::Integer, $match: '\d{4}' }
$patterns: '#{day}-#{month}-#{year}'
TextualDate:
$fields:
year: { $type: Number::Integer, $match: '\d{4}' }
month: Month
day: { $type: Number::Integer, $match: '0[1-9]|[12]\d|3[01]' }
$patterns: '#{month} #{day}, #{year}'
Currency:
USD: '(USD|US\$|\$)'
EUR: '(EUR|€)'
GBP: '(GBP|£)'
Money:
$flags: 'OPTIONAL_WHITESPACE'
$fields:
currency: Currency
amount: Number
$patterns:
- '#{currency} #{amount}'
- '#{amount} #{currency}'
Payment:
$fields:
amount: Money
dueDate: Date
$patterns: '#{amount} due on #{dueDate}'Try it liveOpen Money and Dates in StudioTweak the spec, paste your own input, and see the parse tree update in real time.