ucc rejects hyphen in name

Discussions about Coding and Scripting
Post Reply
User avatar
Wormbo
Adept
Posts: 258
Joined: Sat Aug 24, 2013 6:04 pm
Contact:

Re: ucc rejects hyphen in name

Post by Wormbo »

Barbie wrote:
Wormbo wrote:While name values may contain all kinds of awkward characters, name literals may not. That simple.
:shock:
Whow, thanks - that made me really head shaking. A data type is a data type is a ... oh wait. Not this one.
(Let's compare it to data type byte: it can contain numbers between 0 and 255, but you are allowed to assign values from 0 to 99 literally only?)
Is there any reasonable reason for this behaviour? Except less work for the programmer of the parser code?
It's a parser thing. Well, actually a tokenizer thing. The UnrealScript compiler never was great in terms of consistency. The defaultproperties block is not even UnrealScript code, but T3D content, so allowing strings as name values there doesn't tell anything about name literals in UnrealScript. (There's no separate name literal in T3D files.)

I think it is safe to assume that names weren't intended to contain all possible weird stuff in the context of the UnrealScript language. Every class, variable and function you declare also becomes a name, and you are restricted to identifiers there. So if you spawn an actor from UnrealScript, there's hardly any chance to give it a weird tag - and thus not much reason to allow anything different for other places where names could be used. In fact, the way the tokenizer needs to decide between name literals and object literals is quite fragile. (It's also the reason nobody will ever write a syntax highlighter that is 100% precise, as it simply can't know about all valid class names. That's a requirement for correctly distinguishing between a simple identifier followed by a name literal and an object literal.)

BTW: The UnrealScript compiler also has a pretty peculiar way to parse numbers. Try figuring it our yourself - what will the following code output? (I'm pretty sure it will compile, even if parts of it looks weird.)

Code: Select all

log(0123456789abcedfx);
log(123456789abcedfx);
log(0123456789abcedf);
log(123456789abcedf);
log(0123456789abcedf.x);
log(123456789abcedf.x);
log(0123456789abced.f);
log(123456789abced.f);
log(0123456789abced.fx);
log(123456789abced.fx);
log(012e3);
log(12e3);
log(1.2e+3);
log(1.2d3);
log(1.2a3);
log(1.2x3);
tl;dr: There's no reason, except sloppy parser code.
User avatar
Barbie
Godlike
Posts: 2819
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: ucc rejects hyphen in name

Post by Barbie »

Thanks for putting some lights here. :)
"If Origin not in center it be not in center." --Buggie
Post Reply