# Copy and edit this script in order to make a customized python
# check based on one or more regular expressions.
# Comments marked #! describe places to insert your code.

import patterns
import re

# Return true if input is valid
def validInput():
    #! Convert any input Parameters or options to unicode.capitalize
    #! Example --- convert Parameter1
    #
    # global Parameter1

    #! Place code to do any necessary validation of input parameters
    # or options here. If you find any problems print a message
    # and return 0.  The message should begin with a # so that the
    # list window knows it is a comment and not a reference.
    # Example -- ensure that user entered something for Parameter1 ---
    #
    # if len(Parameter1) == 0:
    #    print &quot;# You must enter a value for ...&quot;
    #    return 0

    return 1    

    
# always do this first to initialize before running the check
patterns.setupCheck()

flags = 0
#! Comment the next line if you want ^ to only apply at the beginning
# of the chapter -- not at each newline
flags = flags | re.MULTILINE

#! Comment the next line if you do NOT want to ignore case
flags = flags | re.IGNORECASE

#! Comment the next line if you do not want . to match a newline
flags = flags | re.DOTALL

if validInput():
    # For complicated patterns it is often easier to give all the good
    # forms of the pattern first and list anything else that is similar
    # as bad. If you have a simple check in which what is bad can be
    # directly expressed you can skip specifying the good patterns
    # and go directly to the bad patterns.

    # Example: check for repeated words but allow &quot;had had&quot;

    # &quot;had had&quot; is a good pattern, it generates no message
    patterns.addPattern(r&quot;\bhad had\b&quot;)
    
    # all other repeated words are bad
    patterns.addPattern(r&quot;\b(?P&lt;word1&gt;\w+) (?P=word1)\b&quot;, &quot;Repeated word&quot;)

    # Scan all the text    
    patterns.scanText(flags)

