Skip to content
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

Fixed parameters parsing #237

Merged
merged 5 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 17 additions & 4 deletions custom_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const types = {
STATIC: 0,
PARAM: 1,
MATCH_ALL: 2,
REGEX: 3,
// It's used for a parameter, that is followed by another parameter in the same part
MULTI_PARAM: 4
REGEX: 3
}

function Node (options) {
Expand Down Expand Up @@ -48,7 +46,6 @@ Node.prototype.addChild = function (node) {
break
case this.types.PARAM:
case this.types.REGEX:
case this.types.MULTI_PARAM:
assert(this.parametricChild === null, 'There is already a parametric child')
this.parametricChild = node
break
Expand Down Expand Up @@ -146,6 +143,22 @@ Node.prototype.split = function (length) {
return newChild
}

Node.prototype.getChildByLabel = function (label, kind) {
if (label.length === 0) {
return null
}

switch (kind) {
case this.types.STATIC:
return this.staticChildren[label]
case this.types.MATCH_ALL:
return this.wildcardChild
case this.types.PARAM:
case this.types.REGEX:
return this.parametricChild
}
}

Node.prototype.findStaticMatchingChild = function (path, pathIndex) {
const child = this.staticChildren[path[pathIndex]]
if (child !== undefined) {
Expand Down
Loading