Discussion:
C++11 user defined literals
Neil Hodgson
2013-10-28 02:19:09 UTC
Permalink
[Mail is in HTML to show examples]

C++11 allows the syntax of literals to be extended with suffixes where the suffixes look like identifiers. Suffixes of user-defined literals must start with "_" and suffixes of standard-defined literals start with characters other than "_". There are no standard-defined literals in C++11 but some are proposed for C++14 such as durations like "45min" or "0.5h". A user-defined literal might look like "12.3_km".

A single new lexical class SCE_C_USERLITERAL has been added for user defined literals. This could be extended in the future to allow multiple classes for different types of literal so, for example, durations could easily be distinguished from fixed-point numbers. Or to have lists of allowed/disallowed suffixes. The sub-style feature is used to break one style into subsets so could be used for this. Here is an example of some user defined literals as lexed by Scintilla:
double x = 90.0_deg; // x = 1.570796
page.match("([A-Z]+)([0-9]+)"_regex);

There is no style for standard-defined numeric literals, mostly because the lexer doesn't understand numeric literal syntax sufficiently to determine if there is a suffix. It currently accepts arbitrary sequences of letters in numbers (after an initial digit) so standard-defined numeric literals will look like other numbers. Standard-defined string literals are not currently understood: the literal will end at " or ' and the suffix will appear as an identifier. Repeating the above example without the "_" so in the standard space:
double x = 90.0deg; // x = 1.570796
page.match("([A-Z]+)([0-9]+)"regex);
The string example should be fixed to style the 'regex' like the string but I'm not sure that there's a need to change the way the numeric example appears.

Change is:
http://sourceforge.net/p/scintilla/code/ci/d0a5f24eeb374a045cdd0a9226cecfa9afd97a0f/

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Loading...