Fix parsing numeric literals with underscore in decimal part

The regexp adapted from Emacs' ada-mode was wrong,
and also not accept "E+..."
This commit is contained in:
Emmanuel Briot 2022-12-14 11:05:55 +01:00
parent 6903869a00
commit c61d74d03a
4 changed files with 1848 additions and 1826 deletions

View File

@ -124,7 +124,7 @@ module.exports = grammar({
character_literal: $ => token(/'.'/), character_literal: $ => token(/'.'/),
numeric_literal: $ => token( numeric_literal: $ => token(
choice( choice(
/[0-9][0-9_]*(\.[0-9]+)?([eE][0-9_-]+)?/, /[0-9][0-9_]*(\.[0-9_]+)?([eE][+-]?[0-9_]+)?/,
/[0-9]+#[0-9a-fA-F._-]+#/ /[0-9]+#[0-9a-fA-F._-]+#/
) )
), ),

View File

@ -50,7 +50,7 @@
"members": [ "members": [
{ {
"type": "PATTERN", "type": "PATTERN",
"value": "[0-9][0-9_]*(\\.[0-9]+)?([eE][0-9_-]+)?" "value": "[0-9][0-9_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?"
}, },
{ {
"type": "PATTERN", "type": "PATTERN",

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@ String literals
A : String := "12'34"; A : String := "12'34";
-------- --------------------------------------------------------------------------------
(compilation (compilation
(compilation_unit (compilation_unit
@ -21,7 +21,7 @@ String literals with quotes
A : String := "12""23"; A : String := "12""23";
-------- --------------------------------------------------------------------------------
(compilation (compilation
(compilation_unit (compilation_unit
@ -32,3 +32,19 @@ A : String := "12""23";
(term (term
(string_literal)))))) (string_literal))))))
================================================================================
Numeric literals with underscore
================================================================================
A : Integer := 12_14.12_122E+11_2;
--------------------------------------------------------------------------------
(compilation
(compilation_unit
(object_declaration
(identifier)
(identifier)
(expression
(term
(numeric_literal))))))