Posted 19 years ago by Thane Plummer
Avatar
I am working on an XML parser for Python, but am having trouble with the multi-line triple-quoted strings. Has anyone done this? I have tried defining pattern groups for both the "StringState" key and also the "MultiLineCommentState" key, but without success. I've gone through numerous iterations of various explicit and regex patterns, but without success.

Both the start and end of the multi-line string delimiter are the same: either """&quot" OR "'''".

Thanks in advance.

Comments (4)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
If you have a normal string state, be careful of the order in which you insert the ChildState tags in your DefaultState. Remember that it will match in order of how you create them so put your triple-quoted string child state ahead of the normal one or else it will match the normal strings first.


Actipro Software Support

Posted 19 years ago by Thane Plummer
Avatar
Yes, I figured that one out the hard way, and moved the "MultiLineCommentState" in front of the string states. Here's the simple case (that doesn't work):
  
<State Key="MultiLineCommentState" Token="MultiLineCommentDefaultToken" Style="CommentDefaultStyle">
    <!-- Scopes -->
    <Scopes>
        <Scope BracketHighlight="True">
            <ExplicitPatternGroup Type="StartScope" Token="MultiLineCommentStartToken" Style="CommentDelimiterStyle" PatternValue="'''" />
            <ExplicitPatternGroup Type="EndScope" Token="MultiLineCommentEndToken" Style="CommentDelimiterStyle" PatternValue="'''" />    
        </Scope>        
    </Scopes>
    <!-- Patterns Groups -->
    <PatternGroups> ...    </PatternGroups>
</State>
Now, to test this I changed the MultiLineCommentEndToken PatternValue to "*/" just to see if the lexer was working, and also changed the ending triple quote in my Python code to "*/". It parsed just fine. Since most all function definitions are documented using multi-line triple quotes, I'd really like to resolve this. Here's a typical code snipper:
  
def MyFunction():
    '''MyFunction() documentation
    
    This function takes no parameters and prints "foo",
    just for testing purposes.
    '''
    print "foo"
I'm open to pretty much any ideas/suggestions.

Thanks again.
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
If you email the full language definition to me I can have a look to see what's wrong.


Actipro Software Support

Posted 19 years ago by Thane Plummer
Avatar
Thanks for looking into this. The solution is to set:
  
<RegexPatternGroup Token="MultiLineCommentDefaultToken" PatternValue="[^*"]" />
I have understand that a Python definition will ship with version 2.5, in case anyone is interested.
The latest build of this product (v24.1.0) was released 25 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.