Skip to content

Commit

Permalink
Adapt json-tokenize lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
ygormutti committed Jul 4, 2018
1 parent 0a1382d commit 2d61144
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion diffless/languages/json/json-tokenize.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare namespace JsonTokenize {
enum TokenType {
const enum TokenType {
Whitespace = 'whitespace',
String = 'string',
Literal = 'literal',
Expand Down
12 changes: 6 additions & 6 deletions diffless/languages/json/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function tokenize(document: Document): Token[] {
export function adapt(uri: DocumentURI, token: JsonTokenize.Token): Token | undefined {
const { type, value } = token;
switch (type) {
case JsonTokenize.TokenType.Literal:
case 'literal':
switch (value) {
case null:
return toToken(uri, token, TokenType.Null);
Expand All @@ -34,10 +34,10 @@ export function adapt(uri: DocumentURI, token: JsonTokenize.Token): Token | unde
}
break;

case JsonTokenize.TokenType.Number:
case 'number':
return toValuedToken(uri, token, TokenType.Number);

case JsonTokenize.TokenType.Punctuation:
case 'punctuation':
switch (value) {
case '{':
return toToken(uri, token, TokenType.LeftBrace);
Expand All @@ -53,10 +53,10 @@ export function adapt(uri: DocumentURI, token: JsonTokenize.Token): Token | unde
return toToken(uri, token, TokenType.Comma);
}

case JsonTokenize.TokenType.String:
case 'string':
return toValuedToken(uri, token, TokenType.String);

case JsonTokenize.TokenType.Whitespace:
case 'whitespace':
return undefined;
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ function toRange(raw: string, locator: JsonTokenize.Range | JsonTokenize.Positio
} else {
const range = locator as JsonTokenize.Range;
start = new Position(range.start.lineno, range.start.column);
end = new Position(range.end.lineno, range.end.column);
end = new Position(range.end.lineno, range.end.column + 1);
}
return new Range(start, end);
}

0 comments on commit 2d61144

Please sign in to comment.