Skip to content

Commit

Permalink
Implement token equality
Browse files Browse the repository at this point in the history
  • Loading branch information
ygormutti committed Jul 4, 2018
1 parent 4d52817 commit 23ab9c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion diffless/array/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export class Token extends Excerpt {
) {
super(content, location);
}

equals(other: Token): boolean {
return !(other instanceof ValuedToken) && this.type === other.type;
}

static equals(a: Token, b: Token) {
return a.equals(b);
}
}

export class ValuedToken<TTokenValue> extends Token {
Expand All @@ -18,8 +26,14 @@ export class ValuedToken<TTokenValue> extends Token {
content: string,
type: number,
readonly value: TTokenValue,
readonly equals: Equals<TTokenValue>,
readonly valueEquals: Equals<TTokenValue>,
) {
super(location, content, type);
}

equals(other: Token): boolean {
return other instanceof ValuedToken
&& this.type === other.type
&& this.valueEquals(this.value, other.value);
}
}
2 changes: 2 additions & 0 deletions diffless/languages/json/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { characterDiff, compose } from '../..';
import { ArrayDiffTool } from '../../array/diff';
import { Token } from '../../array/model';
import { DiffLevel } from '../../model';
import { tokenize } from './lexer';

const jsonLexicalDiffTool = new ArrayDiffTool({
equals: Token.equals,
excerptMapper: tokenize,
level: DiffLevel.Lexical,
similarityThreshold: 0,
Expand Down

0 comments on commit 23ab9c3

Please sign in to comment.