Skip to content

Commit

Permalink
feat(values): Adding a static value node
Browse files Browse the repository at this point in the history
  • Loading branch information
aholstenson committed Oct 21, 2018
1 parent bcf240f commit 2987664
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/resolver/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Matcher from '../graph/matching/matcher';
import TokenNode from '../graph/token';
import ValueNode from './value';

import { LanguageSpecificValue, ParsingValue, ValueMatcher } from '../values/base';
import { LanguageSpecificValue } from '../values/base';
import { isDeepEqual } from '../utils/equality';

const VALUE = /{([a-zA-Z0-9]+)}/g;
Expand Down Expand Up @@ -78,7 +78,7 @@ export default class ResolverParser extends Builder {
throw new Error('No type registered for ' + id);
}

let nextNode = value instanceof ParsingValue || value instanceof ValueMatcher
let nextNode = value.toNode
? value.toNode(id)
: new ValueNode(id, value);

Expand Down
25 changes: 25 additions & 0 deletions src/resolver/value-static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { isDeepEqual } from '../utils/equality';

import Node from '../graph/node';

export default class ValueStatic extends Node {
constructor(id, value) {
super();

this.id = id;
this.value = value;
}

equals(o) {
return o instanceof ValueStatic && this.id.equals(o.id)
&& isDeepEqual(this.value, o.value);
}

match(encounter) {
return encounter.next(0, 0, { id: this.id, value: this.value });
}

toString() {
return 'ValueStatic[' + this.id + '=' + this.value + ']';
}
}
1 change: 1 addition & 0 deletions src/values/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { default as integer } from './integer';
export { default as number } from './number';
export { default as options } from './options';
export { default as ordinal } from './ordinal';
export { default as staticValue } from './static';
export { default as temperature } from './temperature';
export { default as timeDuration } from './time-duration';
export { default as time } from './time';
5 changes: 5 additions & 0 deletions src/values/static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ValueStatic from '../resolver/value-static';

export default function(id, value) {
return new ValueStatic(id, value);
}

0 comments on commit 2987664

Please sign in to comment.