diff --git a/src/resolver/parser.js b/src/resolver/parser.js index 91e9b1e..336bc6c 100644 --- a/src/resolver/parser.js +++ b/src/resolver/parser.js @@ -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; @@ -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); diff --git a/src/resolver/value-static.js b/src/resolver/value-static.js new file mode 100644 index 0000000..ec37af6 --- /dev/null +++ b/src/resolver/value-static.js @@ -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 + ']'; + } +} diff --git a/src/values/index.js b/src/values/index.js index 6578bf9..bd0ed49 100644 --- a/src/values/index.js +++ b/src/values/index.js @@ -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'; diff --git a/src/values/static.js b/src/values/static.js new file mode 100644 index 0000000..2e091fa --- /dev/null +++ b/src/values/static.js @@ -0,0 +1,5 @@ +import ValueStatic from '../resolver/value-static'; + +export default function(id, value) { + return new ValueStatic(id, value); +}