Skip to content

Commit

Permalink
Mild tweak to patterns (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxjrvs authored Nov 2, 2024
1 parent b7fa2ad commit fcf40fe
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/patterns.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const digitPattern = /\d*/.source

export const coreNotationPattern = /^\d+[Dd](\d+|{.*})/
export const dropHighestPattern = /[Hh]\d*/g
export const dropLowestPattern = /[Ll]\d*/g
Expand All @@ -11,33 +13,47 @@ const coreGreaterLessThanEquals = new RegExp(
coreGreaterLessThan.source + /=?\d+/.source
)

function oneOrMany(core: RegExp) {
function createRepeatedPattern(core: RegExp) {
return new RegExp(`{(${core.source},)*(${core.source})}`, 'g')
}

const greaterThanLessEqualityThanMatcher = oneOrMany(coreGreaterLessThanEquals)
const greaterThanLessEqualityThanMatcher = createRepeatedPattern(
coreGreaterLessThanEquals
)
export const replacePattern = new RegExp(
/[Vv]/.source + greaterThanLessEqualityThanMatcher.source,
'g'
)

const greaterThanLessThanMatcher = oneOrMany(coreGreaterLessThan)
const greaterThanLessThanMatcher = createRepeatedPattern(coreGreaterLessThan)
export const dropConstraintsPattern = new RegExp(
/[Dd]/.source + greaterThanLessThanMatcher.source,
'g'
)

export const rerollPattern = new RegExp(
/[Rr]/.source + greaterThanLessThanMatcher.source + /\d*/.source,
`${/[Rr]/.source}${greaterThanLessThanMatcher.source}${digitPattern}`,
'g'
)

export const capPattern = new RegExp(
/[Cc]/.source + greaterThanLessThanMatcher.source,
`${/[Cc]/.source}${greaterThanLessThanMatcher.source}`,
'g'
)

export const completeRollPattern = new RegExp(
`${coreNotationPattern.source}|${dropHighestPattern.source}|${dropLowestPattern.source}|${dropConstraintsPattern.source}|${explodePattern.source}|${uniquePattern.source}|${replacePattern.source}|${rerollPattern.source}|${capPattern.source}|${plusPattern.source}|${minusPattern.source}`,
[
coreNotationPattern.source,
dropHighestPattern.source,
dropLowestPattern.source,
dropConstraintsPattern.source,
explodePattern.source,
uniquePattern.source,
replacePattern.source,
rerollPattern.source,
capPattern.source,
plusPattern.source,
minusPattern.source
].join('|'),
'g'
)

0 comments on commit fcf40fe

Please sign in to comment.