Support multiple match groups#11
Merged
AndiDittrich merged 1 commit intoEnlighterJS:masterfrom Nov 1, 2015
Krusen:multiple-match-groups
Merged
Support multiple match groups#11AndiDittrich merged 1 commit intoEnlighterJS:masterfrom Krusen:multiple-match-groups
AndiDittrich merged 1 commit intoEnlighterJS:masterfrom
Krusen:multiple-match-groups
Conversation
Member
|
Dear Soren, thanks for your contribution. i have to check if it's working without side-effects to the tokenzier. |
AndiDittrich
pushed a commit
that referenced
this pull request
Nov 1, 2015
Support multiple match groups
Member
|
i've modified your code to support multiple matching groups - now each group is rendered as single token. but you have to take care of the regex to avoid overlapping matches. // matching groups used ?
if (match.length == 1) {
rawTokens.push(token(match[0], rule.alias, match.index));
// use full pattern
}else{
// get first matched group
for (var i = 1; i < match.length; i++) {
if (match[i] && match[i].length > 0){
rawTokens.push(token(match[i], rule.alias, match.index + match[0].indexOf(match[i])));
}
}
}For example, the following pattern: 'test': {
pattern: /(.)?(BYTE|CSEG|DEF)/gim,
alias: 'kw4'
},will render .DEF temp=R16
.DEF ior=R0
.CSEGto i think this modification allows a more universal usage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added support for multiple capture groups in regex expressions.
Example:
/(group1)|(group2)|(group3)/gimexecuted on the string"group3"will return["group3", undefined, undefined, "group3"]which will now work correctly.