[PATCH 1/2] Add character literal parsing in bytestrings

David Gibson david at gibson.dropbear.id.au
Wed Jul 20 23:40:06 EST 2011


On Thu, Jun 23, 2011 at 04:20:38PM -0700, Anton Staaf wrote:
> This adds support for parsing simple (non-escaped) 'x' character
> literal syntax in bytestrings.  For example:
> 
>     property = ['a' 2b 'c'];
> 
> is equivalent to:
> 
>     property = [61 2b 62];

Hrm.  I like the idea of being able to encode character literals.
However I'm dubious as to whether the bytestring syntax is the right
place to encode them.

Bytestrings are quite lexically strange, they are quite different from
the < ... > cell syntax: the things inside default to hex, and spacing
is irrelevant ([abcd] is equivalent to [ab cd], [a bc] is a syntax
error and *not* equivalent to [0a bc]).  This makes me worry about
possible ambiguities or other parsing problems if we put something
other than exactly 2 digit hex bytes in there - not that I can see any
definite ambiguities in this proposal.

I have for some time been intending to introduce some variant of the
< > syntax which allows for different sized entries (1, 2 or 8 bytes
instead of the default 4).  I just haven't thought of a nice syntax
for it yet.  Character literals would fit just fine into that scheme.

The other possibility would be to allow something like 'abcd' without
any special context to be a non-NULL-terminated "string".  I'm also a
bit dubious about that on the "be like C" principle, which has served
us pretty well in the past.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson


More information about the devicetree-discuss mailing list