parsingcompiler-constructionprogramming-languageslexer

Do any languages allow a space in a function name?


Normally a function token is a normal identifier ([A-z_][0-9A-z_]*), or some variation thereof. Do any language support a quoted function name that includes a space? An example would be something like:

`my function`(x,y,z)  # using back-tick quoting

Solution

  • Do any language[s] support a quoted function name that includes a space?

    Yes, Zig allows this using @"..." syntax:

    pub fn @"function with spaces"() void {}
    
    pub fn main() void {
        const @"variable with spaces" = 42;
        _ = @"variable with spaces";
        @"function with spaces"();
    }
    

    See the Identifiers section in the language reference for details.

    I've found the feature neat e.g. for token enums. @"::<>" is nicer than Turbofish.