Skip to content

Add carriageReturn to simple mapper #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
56be421
Comment in character classes to be added
corsonknowles Aug 9, 2017
a414232
Add carriage return placeholder comment
corsonknowles Aug 9, 2017
b61969e
Add helper methods and builder hashes for additonal RegEx character c…
corsonknowles Aug 9, 2017
b176e2d
Add all new character classes, clean up comments
corsonknowles Aug 9, 2017
bf6416b
Remove A and z character classes which are not supperted in JavaScrip…
corsonknowles Aug 10, 2017
1c96ab3
Modify test rules
corsonknowles Aug 10, 2017
cd5d7d4
Gitignore package lock and remove test package
corsonknowles Aug 11, 2017
d34d499
Remove nested git file
corsonknowles Aug 11, 2017
6903aa7
Move rules back into place
corsonknowles Aug 11, 2017
ba5d26d
Remove git submodule
corsonknowles Aug 11, 2017
af12154
change file encoding of new test rules
corsonknowles Aug 11, 2017
94127f2
Amend rules files for word and no word
corsonknowles Aug 11, 2017
1ceae8c
Change allowed type of word boundaries
corsonknowles Aug 11, 2017
580d3cb
Add mapper functions for word and nonword boundaries
corsonknowles Aug 11, 2017
b2e10f0
Fix all new test rules, verify working
corsonknowles Aug 11, 2017
36f440f
Hard delete package-lock
corsonknowles Aug 11, 2017
95e0e87
Restore .gitmodules for test
corsonknowles Aug 12, 2017
bf41185
Update package.json
corsonknowles Aug 12, 2017
e442703
Move rules files to submodule repo
corsonknowles Aug 12, 2017
3c81766
remove duplicate rules files
corsonknowles Aug 12, 2017
8369c3e
Remove only rules file duplicates
corsonknowles Aug 12, 2017
2a6bc57
Reactivate submodule
corsonknowles Aug 12, 2017
042dd46
Add vertical tab as supported JavaScript regex character, and remove …
corsonknowles Aug 12, 2017
637cdf8
Add support for text input of backslash
corsonknowles Aug 13, 2017
a4185a3
Amend vertical tab in mbuilder and methodMatch
corsonknowles Aug 13, 2017
9e3e75a
Add carriageReturn to simple mapper
corsonknowles Aug 14, 2017
b906f13
Double escape backslashtranslation
corsonknowles Aug 22, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
coverage
.vscode
package-lock.json
76 changes: 74 additions & 2 deletions lib/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,31 @@ const simpleMapper = {
'type': METHOD_TYPE_CHARACTER,
'allowed': METHOD_TYPES_ALLOWED_FOR_CHARACTERS
},
'backslash': {
'add': '\\\\',
'type': METHOD_TYPE_CHARACTER,
'allowed': METHOD_TYPES_ALLOWED_FOR_CHARACTERS
},
'tab': {
'add': '\\t',
'type': METHOD_TYPE_CHARACTER,
'allowed': METHOD_TYPES_ALLOWED_FOR_CHARACTERS
},
'verticalTab': {
'add': '\\v',
'type': METHOD_TYPE_CHARACTER,
'allowed': METHOD_TYPES_ALLOWED_FOR_CHARACTERS
},
'newLine': {
'add': '\\n',
'type': METHOD_TYPE_CHARACTER,
'allowed': METHOD_TYPES_ALLOWED_FOR_CHARACTERS
},
'carriageReturn': {
'add': '\\r',
'type': METHOD_TYPE_CHARACTER,
'allowed': METHOD_TYPES_ALLOWED_FOR_CHARACTERS
},
'whitespace': {
'add': '\\s',
'type': METHOD_TYPE_CHARACTER,
Expand All @@ -68,7 +83,18 @@ const simpleMapper = {
'add': '\\W',
'type': METHOD_TYPE_CHARACTER,
'allowed': METHOD_TYPES_ALLOWED_FOR_CHARACTERS
},
'word': {
'add': '\\b',
'type': METHOD_TYPE_CHARACTER,
'allowed': METHOD_TYPE_BEGIN
},
'nonWord': {
'add': '\\B',
'type': METHOD_TYPE_CHARACTER,
'allowed': METHOD_TYPE_BEGIN
}

}

class Builder {
Expand Down Expand Up @@ -140,6 +166,21 @@ class Builder {
return this.add(`[${result}]`)
}

/**
* Literally match a character that is not one of these characters.
*
* @param {string} chars
* @return {Builder}
*/
noneOf(chars) {
this._validateAndAddMethodType(METHOD_TYPE_CHARACTER, METHOD_TYPES_ALLOWED_FOR_CHARACTERS)

let result = chars.split('').map((character) => this.escape(character)).join('')
result = result.replace('-', '\\-').replace(']', '\\]')

return this.add(`[^${result}]`)
}

/**
* Literally match all of these characters in that order.
*
Expand All @@ -166,6 +207,17 @@ class Builder {
return this.add(`[${min}-${max}]`)
}

/**
* Match any non-digit character (in given span). Default will be any character not between 0 and 9.
*
* @return {Builder}
*/
noDigit() {
this._validateAndAddMethodType(METHOD_TYPE_CHARACTER, METHOD_TYPES_ALLOWED_FOR_CHARACTERS)

return this.add(`[^0-9]`)
}

/**
* Match any uppercase letter (between A to Z).
*
Expand Down Expand Up @@ -194,10 +246,10 @@ class Builder {
/**********************************************************/

/**
* Match any of these condition.
* Match any of these conditions.
*
* @param {Closure|Builder|string} conditions Anonymous function with its Builder as first parameter.
* @return {Builer}
* @return {Builder}
*/
anyOf(conditions) {
this._validateAndAddMethodType(METHOD_TYPE_GROUP, METHOD_TYPES_ALLOWED_FOR_CHARACTERS)
Expand Down Expand Up @@ -423,14 +475,26 @@ class Builder {
return this._addFromMapper('any')
}

backslash() {
return this._addFromMapper('backslash')
}

tab() {
return this._addFromMapper('tab')
}

verticalTab() {
return this._addFromMapper('verticalTab')
}

newLine() {
return this._addFromMapper('newLine')
}

carriageReturn() {
return this._addFromMapper('carriageReturn')
}

whitespace() {
return this._addFromMapper('whitespace')
}
Expand All @@ -447,6 +511,14 @@ class Builder {
return this._addFromMapper('noCharacter')
}

word() {
return this._addFromMapper('word')
}

nonWord() {
return this._addFromMapper('nonWord')
}

/**********************************************************/
/* INTERNAL METHODS */
/**********************************************************/
Expand Down
14 changes: 13 additions & 1 deletion lib/Language/Helpers/methodMatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,41 @@ const SyntaxException = require('../../Exceptions/Syntax')
// Unimplemented: all lazy, single line, unicode, first match
const mapper = {
'any character': { 'class': SimpleMethod, 'method': 'anyCharacter' },
'backslash': { 'class': SimpleMethod, 'method': 'backslash' },
'no character': { 'class': SimpleMethod, 'method': 'noCharacter' },
'multi line': { 'class': SimpleMethod, 'method': 'multiLine' },
'case insensitive': { 'class': SimpleMethod, 'method': 'caseInsensitive' },
'starts with': { 'class': SimpleMethod, 'method': 'startsWith' },
'start with': { 'class': SimpleMethod, 'method': 'startsWith' },
'begin with': { 'class': SimpleMethod, 'method': 'startsWith' },
'begins with': { 'class': SimpleMethod, 'method': 'startsWith' },
'must end': { 'class': SimpleMethod, 'method': 'mustEnd' },
'once or more': { 'class': SimpleMethod, 'method': 'onceOrMore' },
'never or more': { 'class': SimpleMethod, 'method': 'neverOrMore' },
'new line': { 'class': SimpleMethod, 'method': 'newLine' },
'whitespace': { 'class': SimpleMethod, 'method': 'whitespace' },
'no whitespace': { 'class': SimpleMethod, 'method': 'noWhitespace' },
'anything': { 'class': SimpleMethod, 'method': 'any' },
'tab': { 'class': SimpleMethod, 'method': 'atb' },
'tab': { 'class': SimpleMethod, 'method': 'tab' },
'vertical tab': { 'class': SimpleMethod, 'method': 'verticalTab' },
'digit': { 'class': SimpleMethod, 'method': 'digit' },
'no digit': { 'class': SimpleMethod, 'method': 'noDigit' },
'nondigit': { 'class': SimpleMethod, 'method': 'noDigit' },
'number': { 'class': SimpleMethod, 'method': 'digit' },
'letter': { 'class': SimpleMethod, 'method': 'letter' },
'uppercase': { 'class': SimpleMethod, 'method': 'uppercaseLetter' },
'once': { 'class': SimpleMethod, 'method': 'once' },
'twice': { 'class': SimpleMethod, 'method': 'twice' },
'word': { 'class': SimpleMethod, 'method': 'word' },
'no word': { 'class': SimpleMethod, 'method': 'nonWord' },
'nonword': { 'class': SimpleMethod, 'method': 'nonWord' },
'carriage return': { 'class': SimpleMethod, 'method': 'carriageReturn' },
'carriagereturn': { 'class': SimpleMethod, 'method': 'carriageReturn' },

'literally': { 'class': DefaultMethod, 'method': 'literally' },
'either of': { 'class': DefaultMethod, 'method': 'anyOf' },
'any of': { 'class': DefaultMethod, 'method': 'anyOf' },
'none of': { 'class': DefaultMethod, 'method': 'noneOf' },
'if followed by': { 'class': DefaultMethod, 'method': 'ifFollowedBy' },
'if not followed by': { 'class': DefaultMethod, 'method': 'ifNotFollowedBy' },
'optional': { 'class': DefaultMethod, 'method': 'optional' },
Expand Down