paul-j-lucas / cdecl

Composing and deciphering C (or C++) declarations or casts, aka ‘‘gibberish.’’
GNU General Public License v3.0
90 stars 11 forks source link

Unable to declare an explanation with "ptr" #18

Closed jengelh closed 2 years ago

jengelh commented 2 years ago

The explain command's output is normally usable a command in its own right (and vice-versa), but this falls on its feet when the variable name is called ptr:

c++decl> explain void *ptr
declare ptr as pointer to void
c++decl> declare ptr as pointer to void
                 ^
18: syntax error: "ptr": name or operator expected
paul-j-lucas commented 2 years ago

That's because ptr is a cdecl keyword that's a shorthand for pointer. Note that cdecl recognizes such words only when parsing English and not gibberish (which is why your explain line works).

paul-j-lucas commented 2 years ago

I could perhaps add code to check to see if a token is a cdecl keyword and include that in the error message. Cdecl already does that for C/C++ keywords, e.g.:

cdecl> declare switch as pointer to void
               ^
18: syntax error: "switch": name or operator expected ("switch" is a keyword)

but not currently for cdecl keywords.

paul-j-lucas commented 2 years ago

As of 306ff626412a, cdecl token checks are done.