bug: Double prefix (sometimes) parses for a number_literal · Issue #305 · tree-sitter/tree-sitter-c · GitHub
Skip to content

bug: Double prefix (sometimes) parses for a number_literal #305

@pedro-w

Description

@pedro-w

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-c

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

tree-sitter 0.25.4 (726dcd1e872149d95de581589fc408fb8ea9cb0b)

Describe the bug

The C base prefixes '0', '0x' and '0b' seem to be mentioned twice in the grammar and hence for some combinations, something with two prefixes parses as a valid number_literal. For example, this passes the tests

=====
Bogus
=====
double a = {
  0x0xAC00,
  0x0b1010001,
  0b0xabc00ull
};
-----
(translation_unit
  (declaration
    (primitive_type)
    (init_declarator
      (identifier)
      (initializer_list
        (number_literal)
        (number_literal)
        (number_literal)))))

Note that 0x0b1010001 is a valid C literal, it's hex B1010001. The others however are not.

Expected Behavior/Parse Tree

Expected an error.

Repro

run the above with `tree-sitter test -r`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions