Skip to content

Commit

Permalink
Allowing verilog format parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
maziac committed Apr 30, 2021
1 parent 3cec9c6 commit 5dccac1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 35 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

# Changelog
# 1.2.0
- Feature request #3: Support for SystemVerilog number format, hex and binary formats are supported now (e.g. 'h7F123A).
- Allows now underscores to be separators for the hex number, e.g. 0xAABB_CCDD.

# 1.1.2
- Fixed accuracy problem for very large numbers. Issue #2.
Expand All @@ -20,6 +22,6 @@
- Fixed packages.
- Icon.

## 0.1.0
# 0.1.0
- Initial version.

52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hex-hover-converter",
"displayName": "Hex Hover Converter",
"description": "Provides conversion between decimal, hex and binary numbers while hovering.",
"version": "1.1.2",
"version": "1.2.0",
"publisher": "maziac",
"license": "MIT",
"keywords": [
Expand Down
Binary file added releases/hex-hover-converter-1.2.0.vsix
Binary file not shown.
19 changes: 13 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
const hoverProvider = vscode.languages.registerHoverProvider({scheme: '*', language: '*'}, {
provideHover(document, position, token) {
const range = document.getWordRangeAtPosition(position, /(?<!\w)[\$0-9a-fA-FbhxulUL]+\b/)!;
const range = document.getWordRangeAtPosition(position, /(?<!\w)[\$0-9a-fA-FbhxulULHB_]+\b/)!; // Note: for Verilog format: '[hHbBdD]... , e.g. 'h7123A for a hex number, b or B for a binary, d or D for a decimal
if (!range)
return;
let hoveredWord = document.getText(range);
Expand Down Expand Up @@ -45,17 +45,22 @@ export function activate(context: vscode.ExtensionContext) {
}

// Check for hex
match = /^0x([0-9a-fA-F]+)$/g.exec(hoveredWord); // E.g. 0x12FA
match = /^0x([0-9a-fA-F_]+)$/g.exec(hoveredWord); // E.g. 0x12FA
if (!match)
match = /^\$([0-9a-fA-F]+)$/g.exec(hoveredWord); // E.g. $AB4F
match = /^\$([0-9a-fA-F_]+)$/g.exec(hoveredWord); // E.g. $AB4F
if (!match)
match = /^([0-9a-fA-F]+)h$/g.exec(hoveredWord); // E.g. 07E2h
match = /^([0-9a-fA-F_]+)h$/g.exec(hoveredWord); // E.g. 07E2h
if (!match) {
match = /^([0-9a-fA-F]+)$/g.exec(hoveredWord); // E.g. F08A
match = /^([0-9a-fA-F_]+)$/g.exec(hoveredWord); // E.g. F08A
}
if (!match) {
match = /^[h|H]([0-9a-fA-F_]+)$/g.exec(hoveredWord); // E.g. hFFFF00, for Verilog
}
if (match) {
// Hexadecimal
const hexString = match[1];
const hString = match[1];
// Remove underscores
const hexString = hString.replace(/_/g, '');
value = parseInt(hexString, 16);
// Check size
if (Math.abs(value) > Number.MAX_SAFE_INTEGER)
Expand All @@ -76,6 +81,8 @@ export function activate(context: vscode.ExtensionContext) {
match = /^([01]+)b$/g.exec(hoveredWord); // E.g. 10010b
if (!match)
match = /^0b([01]+)$/g.exec(hoveredWord); // E.g. 0b01011
if (!match)
match = /^[b|B]([01]+)$/g.exec(hoveredWord); // E.g. b01011, Verilog
if (match) {
// Binary
const binString = match[1];
Expand Down

0 comments on commit 5dccac1

Please sign in to comment.