Bug 140514 - In BASH parser, parenthesis grouping commands does not require to be spaced
Summary: In BASH parser, parenthesis grouping commands does not require to be spaced
Status: RESOLVED INTENTIONAL
Alias: None
Product: kate
Classification: Applications
Component: syntax (show other bugs)
Version: 2.5
Platform: unspecified Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-23 21:56 UTC by Luiz Angelo De Luca
Modified: 2015-10-08 09:04 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Removed the limitation of bracket starting with line or space before. Added ")" as valid character after bracked (3.90 KB, patch)
2012-04-13 02:17 UTC, Luiz Angelo De Luca
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Luiz Angelo De Luca 2007-01-23 21:56:04 UTC
Version:           3.3.5 (using KDE 3.5.5 "release 45.2" , openSUSE 10.2)
Compiler:          Target: x86_64-suse-linux
OS:                Linux (x86_64) release 2.6.18.2-34-default

In this code:

if ([ "" ] || [ "123" ]); then echo 123; fi

The parser does not recognize the parenthesis before/after the command ("[ ]" in case) if not spaced as:

if ( [ "" ] || [ "123" ] ); then echo 123; fi
Comment 1 Andreas Pakulat 2007-01-23 22:23:28 UTC
I can confirm this, as with the other 2, reassigning to kate.
Comment 2 Pino Toscano 2007-07-31 00:44:24 UTC
(Really reassing to the Kate guys.)
Comment 3 Luiz Angelo De Luca 2009-05-20 21:53:10 UTC
This bug is still present in kde 4.3
Comment 4 Christoph Cullmann 2010-02-20 14:56:17 UTC
Moving to wish list status. All highlightings works with heuristics and will never be perfect. Perhaps somebody can provide a patch, therefor not closing it.
Comment 5 Luiz Angelo De Luca 2012-04-10 14:44:30 UTC
Still present in kde 4.8
Comment 6 Dominik Haumann 2012-04-10 21:02:44 UTC
Then please look into bash.xml and provide a fix... That would be awesome.
Comment 7 Luiz Angelo De Luca 2012-04-11 12:34:18 UTC
Hello Dominik,

As you suggested, I'm trying to fix all the bugs I opened about bash syntax. Some of them I already fixed but I'm struggling with the parentheses.

With multiple parentheses, I can have:

(((exp)); cmd )  
(((exp) exp ))
(((cmd); cmd); cmd ) 
((((exp) )))

For example, these are valid bash syntax:

(( A + 1 ))
(((1 > 2) )); echo $?
((((1 > 2) ))) ; echo $?
( ((1>2))); echo $?
(( echo 123 ) | echo 1 )

How can I write a rule that matches correctly all these cases?

I only know what the "((" means after I find a "))", so it is an expression, or when I find a single ")", so it is a subshell. I could use lookAhead with regexp but it does not solve the problem as I still can have internal parentheses, which regexp are not enough and I need to consume the string to get into the context.

is there someway to have kate "rollback" to the previous context unconsumming the string used in this context and letting it check the next rule in the parent context? I.E:

   <context attribute="Normal Text" lineEndContext="#stay" name="FindCommands">
        <Detect2Chars attribute="Keyword" context="ExprDblParen" char="(" char1="(" beginRegion="expression" />
        <DetectChar attribute="Keyword" context="SubShell" char="(" beginRegion="subshell" />
    (...)

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblParen">
        <Detect2Chars attribute="Keyword" context="#pop" char=")" char1=")" endRegion="expression" />
        <!-- ops... it wasn't an expression but a subshell -->
        <DetectChar attribute="Keyword" context="#rollback" char=")" endRegion="subshell" />
        <DetectChar attribute="Normal Text" context="ExprSubParen" char="(" />
        <IncludeRules context="FindMost" />
      </context>

For example:



 (( echo 123 ) | echo 1 )  Matches (( in Detect2Chars@FindCommands and go to ExprDblParen

echo 123 ) | echo 1 )  Matches "echo 123" in FindMost@ExprDblParen

) | echo 1 )  Matches ")" in DetectChar@ExprDblParen, rollback to FindCommands

(( echo 123 ) | echo 1 )  Matches ( in DetectChar@FindCommands and go to SubShell

I also though about improving FindMost to avoid detecting commands but echo>2 is both a valid expression and a valid command.

I need some help :-)
Comment 8 Luiz Angelo De Luca 2012-04-13 02:17:21 UTC
Created attachment 70356 [details]
Removed the limitation of bracket starting with line or space before. Added ")" as valid character after bracked



Fix all those cases:

echo |[[ true ]]
echo |[ true ]

if ([ true ]); then
  true
fi
  
if ([ true ] ); then
  true
fi
  
if ([[ true ]]); then
  true
fi
  
if ([[ true ]] ); then
  true
fi

if ( [[ true ]]); then
  true
fi

if ([ "" ] || [ "123" ]); then echo 123; fi
Comment 9 Luiz Angelo De Luca 2012-04-13 02:18:49 UTC
I still need help with "((true) )"
Comment 10 Christoph Cullmann 2015-10-08 09:04:28 UTC
Dear user,

this wish list item is now closed, as it wasn't touched in the last two years and no contributor stepped up to implement it.

The Kate/KTextEditor team is very small and we can just try to keep up with fixing bugs. Therefore wishs that show no activity for two years or more will be closed from now on to keep at least a bit overview about 'current' wishs of the users.

If you want your feature to be implemented, please step up to provide some patch for it. If you think it is really needed, you can reopen your request, but keep in mind, if no new good arguments are made and no people get attracted to help out to implement it, it will expire in two years again.

We have a nice website kate-editor.org that provides all the information needed to contribute, please make use of it. For highlighting improvements our user manual shows how to write syntax definition files.

Greetings
Christoph