[Commits] [wesnoth/wesnoth-old] 6eb2e7: parser: Refactor to pass translated STL strings to...

GitHub noreply at github.com
Sun Feb 16 10:47:06 UTC 2014


  Branch: refs/heads/master
  Home:   https://github.com/wesnoth/wesnoth-old
  Commit: 6eb2e7346c560ddf57ce928668b9999afca888d8
      https://github.com/wesnoth/wesnoth-old/commit/6eb2e7346c560ddf57ce928668b9999afca888d8
  Author: Ignacio R. Morelle <shadowm at wesnoth.org>
  Date:   2014-02-16 (Sun, 16 Feb 2014)

  Changed paths:
    M src/serialization/parser.cpp

  Log Message:
  -----------
  parser: Refactor to pass translated STL strings to parser::lineno_string()

Passing translated strings instead of translatable strings makes a bunch
of things easier:

 * We don't need to worry about forgetting to call gettext _() in
   lineno_string() (which, as a matter of fact, I forgot to do for
   hint_string, oops)
 * We can append and preprend stuff to the *translated* strings before
   passing to lineno_string() without breaking localization! Woo!

Using STL strings instead of C strings also makes things easier and
prettier. The negligible performance impact shouldn't be a concern here
because landing in parser::lineno_string() or parser::error() is a
worst-case situation since it only happens when the parser encounters an
error and cannot continue.

Also, parser::lineno_string() now takes an optional fifth argument
with the tokenizer state message to append to the end of the full
message and trail. We need that for the next commit.


  Commit: 996b31def547be7a093b699ec84c0581208308b9
      https://github.com/wesnoth/wesnoth-old/commit/996b31def547be7a093b699ec84c0581208308b9
  Author: Ignacio R. Morelle <shadowm at wesnoth.org>
  Date:   2014-02-16 (Sun, 16 Feb 2014)

  Changed paths:
    M src/serialization/parser.cpp

  Log Message:
  -----------
  parser: parser::error() now takes the position message format as an argument

The optional argument allows us to specify a nicer and more relevant
position message format for the two parser errors that involve more than
one file location: missing closing tags (expected location and opening
location) and invalid closing tags (opening location and (invalid)
closing location).

This makes it easier to tell what's going on even when confronted with a
kilometric preprocessor brace-substitution trail, e.g:

> Found invalid closing tag [/tag2] for tag [tag1]
> Opened at ~add-ons/My_Add-on/scenarios/24.cfg:1090
>     included from ~add-ons/My_Add-on/scenarios/24.cfg:120
>     included from ~add-ons/My_Add-on/_main.cfg:42
>     [...]
> Closed at ~add-ons/My_Add-on/scenarios/24.cfg:1098
>     included from ~add-ons/My_Add-on/scenarios/24.cfg:120
>     included from ~add-ons/My_Add-on/_main.cfg:42
>     [...]

Some day we will be able to make it easier to handle these situations by
ensuring the trail format is concise and relevant, but that day will not
come before 1.13.0. Messing further with the main ::lineno_string()
function (in preprocessor.cpp) would be risky at this point with 1.12.0
approaching.


Compare: https://github.com/wesnoth/wesnoth-old/compare/ba30b70fbe74...996b31def547


More information about the Commits mailing list