parameters: (text)
return_statement: return main, newHelpers, rest
docstring: Splits the text string into main, helpers, and rest. main is the main function,
      i.e. the function tha thas the same name as the macro file. Helpers is a list of
      strings, each a helper function, i.e. any other function that is not the main function.
      Finally, rest is a string containing any top-level code outside of any function.
      Comments immediately prior to a helper cell are converted into markdown cell,
      added to the helper, and removed from rest.
      Intended for C++ files only.
      >>> split('''void tutorial(){
      ...    content of tutorial
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', [], '')
      >>> split('''void tutorial(){
      ...    content of tutorial
      ... }
      ... void helper(arguments = values){
      ...    helper function
      ...    content spans lines
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n A helper function is created: \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '')
      >>> split('''#include <header.h>
      ... using namespace NAMESPACE
      ... void tutorial(){
      ...    content of tutorial
      ... }
      ... void helper(arguments = values){
      ...    helper function
      ...    content spans lines
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n A helper function is created: \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '#include <header.h>\\nusing namespace NAMESPACE')
      >>> split('''void tutorial(){
      ...    content of tutorial
      ... }
      ... // This is a multiline
      ... // description of the
      ... // helper function
      ... void helper(arguments = values){
      ...    helper function
      ...    content spans lines
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n  This is a multiline\\n description of the\\n helper function\\n \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '')
docstring_summary: Splits the text string into main, helpers, and rest. main is the main function,
      i.e. the function tha thas the same name as the macro file. Helpers is a list of
      strings, each a helper function, i.e. any other function that is not the main function.
      Finally, rest is a string containing any top-level code outside of any function.
      Comments immediately prior to a helper cell are converted into markdown cell,
      added to the helper, and removed from rest.
      Intended for C++ files only.
      >>> split('''void tutorial(){
      ...    content of tutorial
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', [], '')
      >>> split('''void tutorial(){
      ...    content of tutorial
      ... }
      ... void helper(arguments = values){
      ...    helper function
      ...    content spans lines
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n A helper function is created: \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '')
      >>> split('''#include <header.h>
      ... using namespace NAMESPACE
      ... void tutorial(){
      ...    content of tutorial
      ... }
      ... void helper(arguments = values){
      ...    helper function
      ...    content spans lines
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n A helper function is created: \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '#include <header.h>\\nusing namespace NAMESPACE')
      >>> split('''void tutorial(){
      ...    content of tutorial
      ... }
      ... // This is a multiline
      ... // description of the
      ... // helper function
      ... void helper(arguments = values){
      ...    helper function
      ...    content spans lines
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n  This is a multiline\\n description of the\\n helper function\\n \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '')
docstring_tokens: Splits the text string into main helpers and rest . main is the main function i . e . the function tha thas the same name as the macro file . Helpers is a list of strings each a helper function i . e . any other function that is not the main function . Finally rest is a string containing any top - level code outside of any function . Comments immediately prior to a helper cell are converted into markdown cell added to the helper and removed from rest . Intended for C ++ files only . >>> split ( void tutorial () { ... content of tutorial ... } ) ( void tutorial () { \\ n content of tutorial \\ n } [] ) >>> split ( void tutorial () { ... content of tutorial ... } ... void helper ( arguments = values ) { ... helper function ... content spans lines ... } ) ( void tutorial () { \\ n content of tutorial \\ n } [ \\ n# <markdowncell > \\ n A helper function is created : \\ n# <codecell > \\ n%%cpp - d \\ nvoid helper ( arguments = values ) { \\ n helper function \\ n content spans lines \\ n } ] ) >>> split ( #include <header . h > ... using namespace NAMESPACE ... void tutorial () { ... content of tutorial ... } ... void helper ( arguments = values ) { ... helper function ... content spans lines ... } ) ( void tutorial () { \\ n content of tutorial \\ n } [ \\ n# <markdowncell > \\ n A helper function is created : \\ n# <codecell > \\ n%%cpp - d \\ nvoid helper ( arguments = values ) { \\ n helper function \\ n content spans lines \\ n } ] #include <header . h > \\ nusing namespace NAMESPACE ) >>> split ( void tutorial () { ... content of tutorial ... } ... // This is a multiline ... // description of the ... // helper function ... void helper ( arguments = values ) { ... helper function ... content spans lines ... } ) ( void tutorial () { \\ n content of tutorial \\ n } [ \\ n# <markdowncell > \\ n This is a multiline \\ n description of the \\ n helper function \\ n \\ n# <codecell > \\ n%%cpp - d \\ nvoid helper ( arguments = values ) { \\ n helper function \\ n content spans lines \\ n } ] )
function: def split(text):
      """
      Splits the text string into main, helpers, and rest. main is the main function,
      i.e. the function tha thas the same name as the macro file. Helpers is a list of
      strings, each a helper function, i.e. any other function that is not the main function.
      Finally, rest is a string containing any top-level code outside of any function.
      Comments immediately prior to a helper cell are converted into markdown cell,
      added to the helper, and removed from rest.
      Intended for C++ files only.
      >>> split('''void tutorial(){
      ...    content of tutorial
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', [], '')
      >>> split('''void tutorial(){
      ...    content of tutorial
      ... }
      ... void helper(arguments = values){
      ...    helper function
      ...    content spans lines
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n A helper function is created: \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '')
      >>> split('''#include <header.h>
      ... using namespace NAMESPACE
      ... void tutorial(){
      ...    content of tutorial
      ... }
      ... void helper(arguments = values){
      ...    helper function
      ...    content spans lines
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n A helper function is created: \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '#include <header.h>\\nusing namespace NAMESPACE')
      >>> split('''void tutorial(){
      ...    content of tutorial
      ... }
      ... // This is a multiline
      ... // description of the
      ... // helper function
      ... void helper(arguments = values){
      ...    helper function
      ...    content spans lines
      ... }''')
      ('void tutorial(){\\n   content of tutorial\\n}', ['\\n# <markdowncell>\\n  This is a multiline\\n description of the\\n helper function\\n \\n# <codecell>\\n%%cpp -d\\nvoid helper(arguments = values){\\n   helper function\\n   content spans lines\\n}'], '')
      """
      functionReString="("
      for cpptype in gTypesList:
          functionReString += ("^%s|") % cpptype
  
      functionReString = functionReString[:-1] + r")\s?\*?&?\s?[\w:]*?\s?\([^\)]*\)\s*\{.*?^\}"
  
      functionRe = re.compile(functionReString, flags = re.DOTALL | re.MULTILINE)
      #functionre = re.compile(r'(^void|^int|^Int_t|^TF1|^string|^bool|^double|^float|^char|^TCanvas|^TTree|^TString|^TSeqCollection|^Double_t|^TFile|^Long64_t|^Bool_t)\s?\*?\s?[\w:]*?\s?\([^\)]*\)\s*\{.*?^\}', flags = re.DOTALL | re.MULTILINE)
      functionMatches = functionRe.finditer(text)
      helpers = []
      main = ""
      for matchString in [match.group() for match in functionMatches]:
          if tutName == findFunctionName(matchString):  # if the name of the function is that of the macro
              main = matchString
          else:
              helpers.append(matchString)
  
      # Create rest by replacing the main and helper functions with blank strings
      rest = text.replace(main, "")
  
      for helper in helpers:
          rest = rest.replace(helper, "")
  
      newHelpers = []
      lines = text.splitlines()
      for helper in helpers:      # For each helper function
          for i, line in enumerate(lines):                    # Look through the lines until the
              if line.startswith(helper[:helper.find("\n")]):  # first line of the helper is found
                  j = 1
                  commentList = []
                  while lines[i-j].startswith("//"):   # Add comment lines immediately prior to list
                      commentList.append(lines[i-j])
                      j += 1
                  if commentList:                  # Convert list to string
                      commentList.reverse()
                      helperDescription = ''
                      for comment in commentList:
                          if comment in ("//", "// "):
                              helperDescription += "\n\n"  # Two newlines to create hard break in Markdown
                          else:
                              helperDescription += (comment[2:] + "\n")
                              rest = rest.replace(comment, "")
                      break
                  else:   # If no comments are found create generic description
                      helperDescription = "A helper function is created:"
                      break
  
          if findFunctionName(helper) != "main":  # remove void main function
              newHelpers.append("\n# <markdowncell>\n " + helperDescription + " \n# <codecell>\n%%cpp -d\n" + helper)
  
      rest = rest.rstrip("\n /")  # remove newlines and empty comments at the end of string
  
      return main, newHelpers, rest
function_tokens: def split ( text ) : functionReString = "(" for cpptype in gTypesList : functionReString += ( "^%s|" ) % cpptype functionReString = functionReString [ : - 1 ] + r")\s?\*?&?\s?[\w:]*?\s?\([^\)]*\)\s*\{.*?^\}" functionRe = re . compile ( functionReString , flags = re . DOTALL | re . MULTILINE ) #functionre = re.compile(r'(^void|^int|^Int_t|^TF1|^string|^bool|^double|^float|^char|^TCanvas|^TTree|^TString|^TSeqCollection|^Double_t|^TFile|^Long64_t|^Bool_t)\s?\*?\s?[\w:]*?\s?\([^\)]*\)\s*\{.*?^\}', flags = re.DOTALL | re.MULTILINE) functionMatches = functionRe . finditer ( text ) helpers = [ ] main = "" for matchString in [ match . group ( ) for match in functionMatches ] : if tutName == findFunctionName ( matchString ) : # if the name of the function is that of the macro main = matchString else : helpers . append ( matchString ) # Create rest by replacing the main and helper functions with blank strings rest = text . replace ( main , "" ) for helper in helpers : rest = rest . replace ( helper , "" ) newHelpers = [ ] lines = text . splitlines ( ) for helper in helpers : # For each helper function for i , line in enumerate ( lines ) : # Look through the lines until the if line . startswith ( helper [ : helper . find ( "\n" ) ] ) : # first line of the helper is found j = 1 commentList = [ ] while lines [ i - j ] . startswith ( "//" ) : # Add comment lines immediately prior to list commentList . append ( lines [ i - j ] ) j += 1 if commentList : # Convert list to string commentList . reverse ( ) helperDescription = '' for comment in commentList : if comment in ( "//" , "// " ) : helperDescription += "\n\n" # Two newlines to create hard break in Markdown else : helperDescription += ( comment [ 2 : ] + "\n" ) rest = rest . replace ( comment , "" ) break else : # If no comments are found create generic description helperDescription = "A helper function is created:" break if findFunctionName ( helper ) != "main" : # remove void main function newHelpers . append ( "\n# <markdowncell>\n " + helperDescription + " \n# <codecell>\n%%cpp -d\n" + helper ) rest = rest . rstrip ( "\n /" ) # remove newlines and empty comments at the end of string return main , newHelpers , rest