Author Topic: How to identify Hex numbers without the 0x prefix  (Read 2821 times)

ravigm87

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
How to identify Hex numbers without the 0x prefix
« on: June 24, 2020, 11:19:22 PM »
How to identify the Hexadecimal without the 0x prefix and convert to different formats and display in tooltip window?

Currently in the below value only 1017 is identified has no and is highlighted and the tool tip conversion is displayed, the a060 is displayed as a identifier in different color.

1017a060

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: How to identify Hex numbers without the 0x prefix
« Reply #1 on: June 25, 2020, 01:47:46 PM »
What language mode is this for?  And where is that token, in a string, in a comment, etc?

As a rule of thumb, if a language mode's color coding recognizes that entire token as a number, and we can evaluate it as a number, we should be able to make the tooltip for it, plus or minus some other details.

Off the top of my head, I don't know of any language modes that recognize a hex number without a prefix, because it can be ambiguous - is "ace" a number or an identifier?  Maybe possible with a more limited data format where only numbers can show up in some contexts. 

ravigm87

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Re: How to identify Hex numbers without the 0x prefix
« Reply #2 on: June 25, 2020, 05:53:56 PM »
I am trying to view a Linker File, or map file which contains addresses without the 0x prefix.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: How to identify Hex numbers without the 0x prefix
« Reply #3 on: June 25, 2020, 09:42:29 PM »
I think with a hotfix this can be made to work by creating a language mode for the map files that has the color coding set up to recognize the hex numbers.  I'm still looking into it, I'll update once I get some more testing done.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: How to identify Hex numbers without the 0x prefix
« Reply #4 on: June 26, 2020, 04:35:47 PM »
I've put in a fix in the next hotfix that will allow this to work.

It does require a language mode for the file being edited that can mark hexadecimal numbers without a prefix with the "Hexadecimal Integer" color.  I've attached a simple language mode for *.map files that does this already for hex numbers with 8 digits. To import the map file mode, go to Tools -> Options -> Export/Import Options, and click on Import Options, and select the attached MapFileMode.zip file.

The file mode has just the minimal changes needed to make this work.  The only important details will be under the Tools -> Options -> Languages -> User-Defined Languages -> mapfile -> Color Coding page.   For the Tokens tab, there's a single entry that marks groups of 8 hex digits as a hexadecimal integer, pretty straightforward.  And on the Numbers tab, I just unchecked some of the built in number lexing options that could interfere with this.

ravigm87

  • Junior Community Member
  • Posts: 3
  • Hero Points: 0
Re: How to identify Hex numbers without the 0x prefix
« Reply #5 on: June 27, 2020, 06:53:43 PM »
Thanks Patrick, this seems to work for 8 digit numbers, but still the nos which are 6 digits are not working. Can it be made to identify variable digit sizes?

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: How to identify Hex numbers without the 0x prefix
« Reply #6 on: June 29, 2020, 01:48:22 PM »
Sure, go to the Tokens tab of Tools -> Options -> Languages -> User-Defined Languages -> mapfile -> Color Coding, and look at the one token entry.  The regex under "Start delimiter" is limited to matching 8 hex digits, you can either change that to match unlimited strings of hex digits, or Add Other to make another token entry than can match a different length of hex digits. 

I went with the limit of matching 8 digit numbers to prevent recognizing some of the text in a windows map file incorrectly as a hex digit.  If your map file format is different, that may not be an issue.