On Aug 23, 7:55 am, Chris Seberino <cseber...@gmail.com> wrote:
> So what is the next step to move forward?

You may want to look at how implicit_mul is currently processing its
input. Perhaps you can easily adapt it for your purposes. Python's
library itself should be able to help you quite a bit too. There is
tokenize.generate_token that can chop your expression into meaningful
python lexical units. It removes whitespace, but it reports column
numbers, so that is recoverable:

sage: list(tokenize.generate_tokens(StringIO("f(x)").readline))[:2]
[(1, 'f', (1, 0), (1, 1), 'f(x)'), (51, '(', (1, 1), (1, 2), 'f(x)')]
sage: list(tokenize.generate_tokens(StringIO("f (x)").readline))[:2]
[(1, 'f', (1, 0), (1, 1), 'f (x)'), (51, '(', (1, 2), (1, 3), 'f
(x)')]

furthermore, keyword.iskeyword should be able to tell you if something
is a keyword:

sage: keyword.iskeyword("and")
True
sage: keyword.iskeyword("f")
False

so, one pattern to do your substitution on would be sequences of
tokens.

[...,(1,N,_,(C1,R1),_),(51,'(',(C2,R2),_,_),...]

where keywork.iskeyword(N) is false, R1 == R2 and C2 > C1

in that case, you would want to splice a (51,"*",(C1,R1),(C1+1,R1),_)
in between. Once you're done processing, you can reconstruct a string
by calling tokenize.untokenize (it's a shame Python doesn't have a
hook in its reader to transform token sequences)

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to