Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
.po file lexer uses static variable
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Neil Hodgson  
View profile  
 More options Jul 10 2012, 4:20 am
From: Neil Hodgson <nyamaton...@me.com>
Date: Tue, 10 Jul 2012 18:20:15 +1000
Local: Tues, Jul 10 2012 4:20 am
Subject: .po file lexer uses static variable
   The lexer for .po translation files, which is located inside LexOthers.cxx as ColourisePoDoc / ColourisePoLine, uses a static variable 'state'. This appears to be unsafe and is likely to be incorrect when called multiple times or when multiple files are loaded. If anyone is using this lexer, it should be modified to not use any static variables: it is likely what it wants is to continue on from the pressing style which is the 'initStyle' (3rd) parameter to the lexer.

   Neil


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Colomban Wendling  
View profile  
 More options Sep 8 2012, 4:16 pm
From: Colomban Wendling <lists....@herbesfolles.org>
Date: Sat, 08 Sep 2012 22:16:13 +0200
Local: Sat, Sep 8 2012 4:16 pm
Subject: Re: [scintilla] .po file lexer uses static variable

If anybody received my previous empty message, I'm sorry.  I messed up
with my mail client ending up sending the message before writing it...
Fortunately, it seems to have been stopped at some point, so maybe
nobody got it.

Le 10/07/2012 10:20, Neil Hodgson a �crit :

> The lexer for .po translation files, which is located inside
> LexOthers.cxx as ColourisePoDoc / ColourisePoLine, uses a static
> variable 'state'. This appears to be unsafe and is likely to be
> incorrect when called multiple times or when multiple files are
> loaded. If anyone is using this lexer, it should be modified to not
> use any static variables: it is likely what it wants is to continue
> on from the pressing style which is the 'initStyle' (3rd) parameter
> to the lexer.

Trying to fix this I ended up writing a new and a little more complete
lexer.  It behaves like the old one but follows a little better the
language like defined by Gettext[1] and as understood by Gettext's
`msgftm` tool; and provides a few more styles [2].

However, I'm not 100% sure about how I dealt with what used the static
variable before.  The thing is that there are 3 string styles, and the
chosen one depends on what precedes it, which can be lines before, and
moreover that is separated by the default style.  For example, given the
code below:

        1. msgid "foo"
        2. "foo string continues"
        3. msgstr "bar"
        4.
        5. "bar string continues"

the style for the strings foo and bar are different, and especially line
4 should be styled with no (default) style.  This leads to two problems:

1) to style line 2 and 5, I need to look behind and find what is the
previous non-default style.
2) doing so will break when changing e.g. "msgstr" to "msgid" since line
5 won't be restyled (but it now should use another style).

So, what I finally did is adding 3 "default" styles (
SCE_PO_MSGCTXT_TEXT_DEFAULT, SCE_PO_MSGID_TEXT_DEFAULT and
SCE_PO_MSGSTR_TEXT_DEFAULT) that are used in place of the default styles
when the various string types are expected, using those to remember how
a string should be styled here.  This removes the need to look behind,
and fixes the restyling issue at the same time.

Again, I'm not sure it's the right approach, but I don't see another way
of keeping the information through many lines without styling everything
with the string style -- which would not be really great either.  I'm
open to comments :)

Attached are two patches, one is the new lexer patch, the other adds the
PO properties to SciTE (which didn't seem to exist at all yet).

Thanks for reading,
Colomban

[1] https://www.gnu.org/software/gettext/manual/gettext.html#PO-Files
[2] SCE_PO_PROGRAMMER_COMMENT, SCE_PO_REFERENCE, SCE_PO_FLAGS,
SCE_PO_MSGID_TEXT_EOL, SCE_PO_MSGSTR_TEXT_EOL, SCE_PO_MSGCTXT_TEXT_EOL,
SCE_PO_ERROR and the three SCE_PO_MSGID_TEXT_DEFAULT,
SCE_PO_MSGSTR_TEXT_DEFAULT and SCE_PO_MSGCTXT_TEXT_DEFAULT.

  0001-Rewrite-PO-lexer.patch
8K Download

  0001-SciTE-add-po-properties.patch
2K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neil Hodgson  
View profile  
 More options Sep 8 2012, 6:33 pm
From: Neil Hodgson <nyamaton...@me.com>
Date: Sun, 09 Sep 2012 08:33:35 +1000
Local: Sat, Sep 8 2012 6:33 pm
Subject: Re: [scintilla] .po file lexer uses static variable
Colomban Wendling:

> If anybody received my previous empty message, I'm sorry.

   Your account still had the moderate flag on, so I saw it and removed it.

> However, I'm not 100% sure about how I dealt with what used the static
> variable before.  The thing is that there are 3 string styles, and the
> chosen one depends on what precedes it, which can be lines before, and
> moreover that is separated by the default style.

   The common ways of implementing this without introducing user-visible changes are:

1) Use line states to remember the state at the end of each line. styler.SetLineState / styler.GetLineState

2) Seek back to the start of the feature and discover the state there.

3) Write an object lexer and record each change in the feature state. This is much more work but is better for complex functionality.

   Neil


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Colomban Wendling  
View profile  
 More options Sep 8 2012, 8:33 pm
From: Colomban Wendling <lists....@herbesfolles.org>
Date: Sun, 09 Sep 2012 02:33:52 +0200
Local: Sat, Sep 8 2012 8:33 pm
Subject: Re: [scintilla] .po file lexer uses static variable

Le 09/09/2012 00:33, Neil Hodgson a �crit :

> Colomban Wendling:

>> If anybody received my previous empty message, I'm sorry.

> Your account still had the moderate flag on, so I saw it and removed
> it.

Oh, so I haven't ever posted on the ML before?  Well, maybe it was only
on the trackers.  Anyway that's fortunate, and thanks :)

>> However, I'm not 100% sure about how I dealt with what used the
>> static variable before.  The thing is that there are 3 string
>> styles, and the chosen one depends on what precedes it, which can
>> be lines before, and moreover that is separated by the default
>> style.

> The common ways of implementing this without introducing user-visible
> changes are:

> 1) Use line states to remember the state at the end of each line.
> styler.SetLineState / styler.GetLineState

That's perfect, thanks!  I updated my patch (attached) to use this
instead of the extra styles and it works just fine, removing the weird
styles and even some lines of code.

> 2) Seek back to the start of the feature and discover the state
> there.

> 3) Write an object lexer and record each change in the feature state.
> This is much more work but is better for complex functionality.

Not sure what you mean with a "feature" here, but since solution 1 works
just fine for this lexer and should even be enough if somebody wants to
add e.g. c-style format highlighting after a "c-format" flag, I won't
rewrite the thing a second time :)  And po format isn't that complex it
requires anything really fancy anyway I guess.

Regards,
Colomban

  0001-Rewrite-PO-lexer.patch
8K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neil Hodgson  
View profile  
 More options Sep 9 2012, 11:12 pm
From: Neil Hodgson <nyamaton...@me.com>
Date: Mon, 10 Sep 2012 13:12:14 +1000
Local: Sun, Sep 9 2012 11:12 pm
Subject: Re: [scintilla] .po file lexer uses static variable
Colomban Wendling:

> That's perfect, thanks!  I updated my patch (attached) to use this
> instead of the extra styles and it works just fine, removing the weird
> styles and even some lines of code.

   cppcheck complains about duplicate if/else branches for lines 693/695. While it looks like you plan to differentiate here, its not unusual for such plans to not be completed leaving confusing code.

   Including .po support in LexOthers was expedient but it should have its own file so it can be included and excluded easily.

   Neil


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Colomban Wendling  
View profile  
 More options Sep 11 2012, 1:49 pm
From: Colomban Wendling <lists....@herbesfolles.org>
Date: Tue, 11 Sep 2012 19:49:12 +0200
Local: Tues, Sep 11 2012 1:49 pm
Subject: Re: [scintilla] .po file lexer uses static variable
Le 10/09/2012 05:12, Neil Hodgson a crit :

> Colomban Wendling:

>> That's perfect, thanks!  I updated my patch (attached) to use this
>> instead of the extra styles and it works just fine, removing the
>> weird styles and even some lines of code.

> cppcheck complains about duplicate if/else branches for lines
> 693/695. While it looks like you plan to differentiate here, its not
> unusual for such plans to not be completed leaving confusing code.

OK, I'll merge the branches.

> Including .po support in LexOthers was expedient but it should have
> its own file so it can be included and excluded easily.

OK, I'll try to move it to its own file and integrate that.

Regards,
Colomban


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neil Hodgson  
View profile  
 More options Sep 12 2012, 2:03 am
From: Neil Hodgson <nyamaton...@me.com>
Date: Wed, 12 Sep 2012 16:03:12 +1000
Local: Wed, Sep 12 2012 2:03 am
Subject: Re: [scintilla] .po file lexer uses static variable
Colomban Wendling:

> OK, I'll try to move it to its own file and integrate that.

   I accidentally committed your current patch. I'd still like the updates though.

   Neil


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Colomban Wendling  
View profile  
 More options Sep 13 2012, 3:17 pm
From: Colomban Wendling <lists....@herbesfolles.org>
Date: Thu, 13 Sep 2012 21:17:04 +0200
Local: Thurs, Sep 13 2012 3:17 pm
Subject: Re: [scintilla] .po file lexer uses static variable

Le 12/09/2012 08:03, Neil Hodgson a �crit :

> Colomban Wendling:

>> OK, I'll try to move it to its own file and integrate that.

> I accidentally committed your current patch. I'd still like the
> updates though.

Here they are.

0001-Move-PO-lexer-outside-LexOthers.patch:
        Moves the PO lexer to it own file.  Tested build with gtk, and
        grepped for others, hopefully it's OK everywhere (I ran
        LexGen.py).  I also changed the lexer module name from "lmPo"
        to "lmPO" (uppercase) to match other lexer names (like lmCPP,
        lmVB, etc.) since "po" here is an abbreviation.
        I'm not completely sure of the implications though, if it
        brings compatibility issues I can change that back to the old
        "lmPo" name.

0002-Remove-duplicated-branch-in-PO-lexer.patch:
        Removes the duplicated branch.

Regards,
Colomban

  0001-Move-PO-lexer-outside-LexOthers.patch
11K Download

  0002-Remove-duplicated-branch-in-PO-lexer.patch
1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neil Hodgson  
View profile  
 More options Sep 13 2012, 9:10 pm
From: Neil Hodgson <nyamaton...@me.com>
Date: Fri, 14 Sep 2012 11:10:31 +1000
Local: Thurs, Sep 13 2012 9:10 pm
Subject: Re: [scintilla] .po file lexer uses static variable
Colomban Wendling:

> Here they are.

   OK, committed.

   Neil


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »