Case insensitive ValueRefs

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
Ophiuchus
Programmer
Posts: 3427
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Case insensitive ValueRefs

#1 Post by Ophiuchus »

Problem:

Properties of universe objects in FOCS are case sensitive for evaluation, but are case insensitive in parsing.
In case of a casing mismatch, a default value is used which leads to wrong results.
Such an error is easy to miss as everything seems to be ok, just calculations are off.

Example:

Source.DesignID will return the design ID for a ship Source.

Source.DesignId parses and will return 0 (zero) for a ship Source. I think there is an error log entry that the property was not found.

Possible solutions:
  1. make FOCS parsing of properties case sensitive.
  2. store the property name in the ValueRef::Variable lowercase and compare to lowercase strings
  3. make the comparison case insensitive
  4. dont do anything
Not sure how to proceed.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13586
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Case insensitive ValueRefs

#2 Post by Geoff the Medio »

Making the parsing case-sensitive seems like it should be the simplest solution, in that fixing all the string comparisons in the internal FOCS C++ code would be quite a lot. It appears that just

Code: Select all

 parse/Lexer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parse/Lexer.cpp b/parse/Lexer.cpp
index 357314929..2979e1c7a 100644
--- a/parse/Lexer.cpp
+++ b/parse/Lexer.cpp
@@ -38,7 +38,7 @@ lexer::lexer() :
     double_(double_regex),
     string(string_regex),
 
-#define DEFINE_TOKEN(r, _, name) BOOST_PP_CAT(name, _)("(?i:" BOOST_PP_STRINGIZE(name) ")"),
+#define DEFINE_TOKEN(r, _, name) BOOST_PP_CAT(name, _)("(?-i:" BOOST_PP_STRINGIZE(name) ")"),
     BOOST_PP_SEQ_FOR_EACH(DEFINE_TOKEN, _, TOKEN_SEQ_1)
     BOOST_PP_SEQ_FOR_EACH(DEFINE_TOKEN, _, TOKEN_SEQ_2)
     BOOST_PP_SEQ_FOR_EACH(DEFINE_TOKEN, _, TOKEN_SEQ_3)
should make it case-sensitive, but I'm not sure.

Will probably still need to fix a bunch of .focs.txt files after the switch, regardless...

Edit: immediate issues after applying that are many instances of "name" needing to be "Name". If the token is changed from Name to name, then the parser needs to be updated from Name_ to name_.

Here's a start...
parser_case_sensitize.patch.txt
WIP parser patch for case sensitivity
(60.62 KiB) Downloaded 115 times

Ophiuchus
Programmer
Posts: 3427
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Case insensitive ValueRefs

#3 Post by Ophiuchus »

Geoff the Medio wrote: Tue Oct 27, 2020 7:57 pm Will probably still need to fix a bunch of .focs.txt files after the switch, regardless...
Thanks for the patch. Is quite a bulk of changes, but I like the result more than before the refactoring.

PR-3210 (still WIP)
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Post Reply