Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#111 closed defect (fixed)

Command line parsing doesn't handle single quotes

Reported by: Tom Goddard Owned by: Greg Couch
Priority: major Milestone:
Component: Command Line Version:
Keywords: Cc: meganrm@…
Blocked By: Blocking:
Notify when closed: Platform: all
Project: chimera

Description

Command line parsing allows quoting string arguments with double quotes but not single quotes. Both types of quotes are needed to handle nested quoting with the perframe command

2dlabel create e text "Time 1"
perframe "2dlabel change e text 'Time $1'" frames 100

Megan Riel-Mehan reported this when trying to make a movie in Chimera 2.

Change History (10)

comment:1 by Greg Couch, 10 years ago

Strictly speaking, single quotes are not needed because double quotes can be escaped with a backslash in Chimera2. But I understand the utility of allowing single quotes.

comment:2 by meganrm@…, 10 years ago

It wasn’t so much single quotes verse double quotes, I don’t think it could parse either.
I could only get the command to work if i didn’t use quotes and just had the text be a single word. 

This didn’t work at all:
2d change mylabel text 'time 1'

2dlabels change mylabel text 'time 1'

...................................^

Expected keyword, got

2d change mylabel text "time 1"



On Jul 17, 2015, at 7:02 PM, Chimera2 <chimera2-bugs-admin@cgl.ucsf.edu> wrote:

comment:3 by Greg Couch, 10 years ago

What was the CmdDesc for 2dlabels? I would expect double quotes to work. The error message is weird.

FYI, I don't exactly remember why single quote support was commented out. It's probably because single quotes don't quote in atom specifications, and the breaking of lines into multiple commands on a semicolon wants to ignore semicolons that inside strings.

comment:4 by Eric Pettersen, 10 years ago

In Chimera 1, a starting-quote character only "matters" if there is whitespace to the left of it. The matching end quote must be the same type of character and have whitespace to the right of it.

--Eric

comment:5 by goddard@…, 10 years ago

Now I see that nested double quotes do work in this perframe use of 2dlabel

2dlabel create e text "Time 1"
perframe "2dlabel change e text "Time $1"" frames 100

I guess I did not try that case.  Unfortunately changing the perframe command to 

perframe "2dlabel change e text "Time $1” color pink" frames 100

and it now raises an error I guess because the initial quote mark matches the third quote mark after $1 instead of the one after pink.

Greg suggested that backslash escape of the inside quote marks would work.

perframe "2dlabel change e text \"Time $1\” color pink" frames 100

but that raises another error (copied below).

I think the most obvious thing for a user to try when nested quotation marks are needed is use both single and double quotes.  Currently single quotes do not work at all.  But what I would like is that the following work:

perframe "2dlabel change e text 'Time $1' color pink" frames 100

In the meantime, Megan, if you rearrange the 2dlabel arguments so the text argument is at the end it will work, like so

perframe "2dlabel change e color pink text "Time $1"" frames 100

There can’t be a space between the two quote marks after $1 or it will not work.

Error when using backslash escaped quotes as in example 3 above

Traceback (most recent call last):
File "/Users/goddard/Desktop/Chimera2 2.app/Contents/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/chimera/cmd_line/gui.py", line 112, in on_enter
cmd = cli.Command(session, cmd_text, final=True)
File "/Users/goddard/Desktop/Chimera2 2.app/Contents/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/chimera/core/cli.py", line 1301, in __init__
self.parse_text(text, final, _used_aliases)
File "/Users/goddard/Desktop/Chimera2 2.app/Contents/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/chimera/core/cli.py", line 1609, in parse_text
self._process_positional_arguments()
File "/Users/goddard/Desktop/Chimera2 2.app/Contents/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/chimera/core/cli.py", line 1494, in _process_positional_arguments
value, text = self._parse_arg(anno, text, session, False)
File "/Users/goddard/Desktop/Chimera2 2.app/Contents/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/chimera/core/cli.py", line 1398, in _parse_arg
value, replacement, rest = annotation.parse(text, session)
File "/Users/goddard/Desktop/Chimera2 2.app/Contents/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/chimera/core/cli.py", line 521, in parse
token, text, rest = next_token(text)
File "/Users/goddard/Desktop/Chimera2 2.app/Contents/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/chimera/core/cli.py", line 785, in next_token
token = unescape(token)
File "/Users/goddard/Desktop/Chimera2 2.app/Contents/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/chimera/core/cli.py", line 677, in unescape
return unescape_with_index_map(text)[0]
File "/Users/goddard/Desktop/Chimera2 2.app/Contents/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/chimera/core/cli.py", line 701, in unescape_with_index_map
index_map = index_map[:index] + index_map[index + 1:]
TypeError: unsupported operand type(s) for +: 'range' and 'range'


comment:6 by Eric Pettersen, 10 years ago

I think you want the Chimera 1 quote-handling rules because they just work out much more naturally. In the incredibly rare case of actually wanting a quote to begin in the middle of non-whitespace (which I have never encountered in practice) you can instead backslash-escape the spaces.

--Eric

comment:7 by goddard@…, 10 years ago

In Chimera 1 using nested double quotes as follows gives an error

	perframe "2dl change e text "time $1" color pink" frames 50

and using single quotes inside double quotes works

	perframe "2dl change e text 'time $1' color pink" frames 50

I agree Chimera 2 should handle single quotes as Chimera 1 does.


comment:8 by Greg Couch, 10 years ago

Fixed in 82756bff4792c25edd459f239e0cbe6b1a50e3ea. Also fixed named unicode characters "\N{Greek Small Letter Alpha}".

comment:9 by Greg Couch, 10 years ago

Resolution: fixed
Status: newclosed

comment:10 by Eric Pettersen, 10 years ago

Component: User InterfaceCommand Line
Note: See TracTickets for help on using tickets.