示例#1
0
 def add(self, pieces):
     "Add a new set of alternative pieces."
     alternative = Declaration('#' + unicode(len(self.alternatives)))
     alternative.pieces = pieces
     self.alternatives.append(alternative)
     Trace.debug('Alternatives: ' + unicode(self))
     return self
示例#2
0
 def convert(self, image):
     "Convert an image to PNG"
     if not ImageConverter.active or Options.noconvert:
         return
     if image.origin.path == image.destination.path:
         return
     if image.destination.exists():
         if image.origin.getmtime() <= image.destination.getmtime():
             # file has not changed; do not convert
             return
     image.destination.createdirs()
     if Options.copyimages:
         Trace.debug('Copying ' + image.origin.path + ' to ' +
                     image.destination.path)
         shutil.copy2(image.origin.path, image.destination.path)
         return
     converter, command = self.buildcommand(image)
     try:
         Trace.debug(converter + ' command: "' + command + '"')
         result = os.system(command.encode(sys.getfilesystemencoding()))
         if result != 0:
             Trace.error(converter +
                         ' not installed; images will not be processed')
             ImageConverter.active = False
             return
         Trace.message('Converted ' + unicode(image.origin) + ' to ' +
                       unicode(image.destination))
     except OSError, exception:
         Trace.error('Error while converting image ' +
                     unicode(image.origin) + ': ' + unicode(exception))
示例#3
0
 def add(self, pieces):
   "Add a new set of alternative pieces."
   alternative = Declaration('#' + str(len(self.alternatives)))
   alternative.pieces = pieces
   self.alternatives.append(alternative)
   Trace.debug('Alternatives: ' + str(self))
   return self
示例#4
0
文件: image.py 项目: ccpaging/elyxer
 def convert(self, image):
   "Convert an image to PNG"
   if not ImageConverter.active or Options.noconvert:
     return
   if image.origin.path == image.destination.path:
     return
   if image.destination.exists():
     if image.origin.getmtime() <= image.destination.getmtime():
       # file has not changed; do not convert
       return
   image.destination.createdirs()
   if Options.copyimages:
     Trace.debug('Copying ' + image.origin.path + ' to ' + image.destination.path)
     shutil.copy2(image.origin.path, image.destination.path)
     return
   converter, command = self.buildcommand(image)
   try:
     Trace.debug(converter + ' command: "' + command + '"')
     result = os.system(command.encode(sys.getfilesystemencoding()))
     if result != 0:
       Trace.error(converter + ' not installed; images will not be processed')
       ImageConverter.active = False
       return
     Trace.message('Converted ' + str(image.origin) + ' to ' +
         str(image.destination))
   except OSError as exception:
     Trace.error('Error while converting image ' + str(image.origin)
         + ': ' + str(exception))
示例#5
0
 def addconstant(self, constant):
     "Add a constant value."
     if constant in Grammar.instance.constants:
         Trace.error('Repeated constant ' + constant)
         return
     Trace.debug('New constant: ' + constant)
     self.pieces.append(ConstantWord(constant))
示例#6
0
 def addconstant(self, constant):
   "Add a constant value."
   if constant in Grammar.instance.constants:
     Trace.error('Repeated constant ' + constant)
     return
   Trace.debug('New constant: ' + constant)
   self.pieces.append(ConstantWord(constant))
示例#7
0
 def process(self):
     "Process the grammar and create all necessary structures."
     for key in JavaToPyConfig.declarations:
         self.variables[key] = JavaToPyConfig.declarations[key]
     for key in self.variables:
         self.declarations[key] = Declaration(key)
     for key in self.variables:
         Trace.debug('Interpreting ' + self.variables[key])
         pos = TextPosition(self.variables[key])
         self.declarations[key].parse(pos)
示例#8
0
 def process(self):
   "Process the grammar and create all necessary structures."
   for key in JavaToPyConfig.declarations:
     self.variables[key] = JavaToPyConfig.declarations[key]
   for key in self.variables:
     self.declarations[key] = Declaration(key)
   for key in self.variables:
     Trace.debug('Interpreting ' + self.variables[key])
     pos = TextPosition(self.variables[key])
     self.declarations[key].parse(pos)
示例#9
0
文件: macro.py 项目: ccpaging/elyxer
 def parsebit(self, pos):
   "Parse the function that defines the macro."
   self.output = EmptyOutput()
   self.parameternumber = 0
   self.defaults = []
   self.factory.defining = True
   self.parseparameters(pos)
   self.factory.defining = False
   Trace.debug('New command ' + self.newcommand + ' (' + \
       str(self.parameternumber) + ' parameters)')
   self.macros[self.newcommand] = self
示例#10
0
 def parsebit(self, pos):
     "Parse the function that defines the macro."
     self.output = EmptyOutput()
     self.parameternumber = 0
     self.defaults = []
     self.factory.defining = True
     self.parseparameters(pos)
     self.factory.defining = False
     Trace.debug('New command ' + self.newcommand + ' (' + \
         unicode(self.parameternumber) + ' parameters)')
     self.macros[self.newcommand] = self
示例#11
0
 def parsevariable(self, pos):
   "Parse a variable."
   if pos.checkskip('$'):
     self.pieces.append(IdentifierWord())
     return
   name = '$' + pos.globidentifier()
   if not name in Grammar.instance.declarations:
     Trace.error('Unknown variable ' + name)
     return
   Trace.debug('New variable ' + name)
   self.pieces.append(Grammar.instance.declarations[name])
示例#12
0
 def parsevariable(self, pos):
     "Parse a variable."
     if pos.checkskip('$'):
         self.pieces.append(IdentifierWord())
         return
     name = '$' + pos.globidentifier()
     if not name in Grammar.instance.declarations:
         Trace.error('Unknown variable ' + name)
         return
     Trace.debug('New variable ' + name)
     self.pieces.append(Grammar.instance.declarations[name])
示例#13
0
 def processinclude(self):
   "Process a regular include: standard child document."
   self.contents = []
   olddir = Options.directory
   newdir = os.path.dirname(self.getparameter('filename'))
   if newdir != '':
     Trace.debug('Child dir: ' + newdir)
     Options.directory = os.path.join(Options.directory, newdir)
   try:
     self.convertinclude()
   finally:
     Options.directory = olddir
示例#14
0
 def parse(self, pos):
   "Parse the bracket."
   pos.pushending(']')
   declaration = Declaration('bracket').parse(pos)
   pos.popending(']')
   quantifier = pos.skipcurrent()
   if not quantifier in self.quantified:
     Trace.error('Unknown quantifier ' + quantifier)
     return self
   bracket = Cloner.clone(self.quantified[quantifier]).create(declaration, quantifier)
   Trace.debug('Bracket: ' + str(bracket))
   return bracket
示例#15
0
 def processinclude(self):
     "Process a regular include: standard child document."
     self.contents = []
     olddir = Options.directory
     newdir = os.path.dirname(self.getparameter('filename'))
     if newdir != '':
         Trace.debug('Child dir: ' + newdir)
         Options.directory = os.path.join(Options.directory, newdir)
     try:
         self.convertinclude()
     finally:
         Options.directory = olddir
示例#16
0
 def parse(self, pos):
     "Parse the bracket."
     pos.pushending(']')
     declaration = Declaration('bracket').parse(pos)
     pos.popending(']')
     quantifier = pos.skipcurrent()
     if not quantifier in self.quantified:
         Trace.error('Unknown quantifier ' + quantifier)
         return self
     bracket = Cloner.clone(self.quantified[quantifier]).create(
         declaration, quantifier)
     Trace.debug('Bracket: ' + unicode(bracket))
     return bracket
示例#17
0
 def process(self):
   "Include the provided child document"
   self.filename = os.path.join(Options.directory, self.getparameter('filename'))
   Trace.debug('Child document: ' + self.filename)
   LstParser().parsecontainer(self)
   command = self.getparameter('LatexCommand')
   if command == 'verbatiminput':
     self.readverbatim()
     return
   elif command == 'lstinputlisting':
     self.readlisting()
     return
   self.processinclude()
示例#18
0
 def match(self, tok):
   "Match the declaration against a tokenizer."
   decl = Declaration(self.key)
   state = tok.mark()
   for piece in self.pieces:
     Trace.debug('Matching ' + tok.current() + ' against ' + str(piece))
     result = piece.match(tok)
     if not result:
       Trace.error('Mismatch of ' + tok.current() + ' against ' + str(piece))
       tok.revert(state)
       return None
     decl.pieces.append(result)
   return decl
示例#19
0
 def nextstatement(self, tok):
     "Return the next statement."
     statement = None
     while not statement and not tok.finished():
         indent = self.chooser.getindent(tok)
         statement = self.parsestatement(tok)
     if not statement:
         return ''
     Trace.debug('Statement: ' + statement.strip())
     if statement.startswith('\n'):
         # displace newline
         return '\n' + indent + statement[1:]
     return indent + statement
示例#20
0
文件: porter.py 项目: ccpaging/elyxer
 def nextstatement(self, tok):
   "Return the next statement."
   statement = None
   while not statement and not tok.finished():
     indent = self.chooser.getindent(tok)
     statement = self.parsestatement(tok)
   if not statement:
     return ''
   Trace.debug('Statement: ' + statement.strip())
   if statement.startswith('\n'):
     # displace newline
     return '\n' + indent + statement[1:]
   return indent + statement
示例#21
0
 def process(self):
     "Include the provided child document"
     self.filename = os.path.join(Options.directory,
                                  self.getparameter('filename'))
     Trace.debug('Child document: ' + self.filename)
     LstParser().parsecontainer(self)
     command = self.getparameter('LatexCommand')
     if command == 'verbatiminput':
         self.readverbatim()
         return
     elif command == 'lstinputlisting':
         self.readlisting()
         return
     self.processinclude()
示例#22
0
 def match(self, tok):
     "Match the declaration against a tokenizer."
     decl = Declaration(self.key)
     state = tok.mark()
     for piece in self.pieces:
         Trace.debug('Matching ' + tok.current() + ' against ' +
                     unicode(piece))
         result = piece.match(tok)
         if not result:
             Trace.error('Mismatch of ' + tok.current() + ' against ' +
                         unicode(piece))
             tok.revert(state)
             return None
         decl.pieces.append(result)
     return decl
示例#23
0
文件: tex.py 项目: gitGNU/gnu_elyxer
 def parseentry(self, pos):
   "Parse a single entry"
   for entry in BibEntry.instances:
     if entry.detect(pos):
       newentry = Cloner.clone(entry)
       newentry.parse(pos)
       if not newentry.isvisible():
         return
       if self.showall or newentry.isreferenced():
         self.entries.append(newentry)
         self.added += 1
       else:
         Trace.debug('Ignored entry ' + unicode(newentry))
         self.ignored += 1
       return
   # Skip the whole line since it's a comment outside an entry
   pos.globincluding('\n').strip()
示例#24
0
文件: tex.py 项目: hainm/elyxer
 def parseentry(self, pos):
     "Parse a single entry"
     for entry in BibEntry.instances:
         if entry.detect(pos):
             newentry = Cloner.clone(entry)
             newentry.parse(pos)
             if not newentry.isvisible():
                 return
             if self.showall or newentry.isreferenced():
                 self.entries.append(newentry)
                 self.added += 1
             else:
                 Trace.debug("Ignored entry " + unicode(newentry))
                 self.ignored += 1
             return
     # Skip the whole line since it's a comment outside an entry
     pos.globincluding("\n").strip()
示例#25
0
 def parsetoendings(self, tok, endings):
     "Parse the tokenizer up to a number of endings."
     result = ''
     tok.next()
     while not tok.current() in endings:
         processed = self.processtoken(tok)
         if processed == '++':
             processed = '+ 1'
             Trace.debug('Increasing ' + result + ' for endings: ' +
                         unicode(endings))
             tok.autoincreases.append(result)
         if processed == '--':
             Trace.debug('Decreasing ' + result)
             processed = '- 1'
             tok.autodecreases.append(result)
         if processed != '.' and not result.endswith('.'):
             processed = ' ' + processed
         result += processed
         if not tok.current in endings:
             tok.next()
     if len(result) > 0:
         result = result[1:]
     Trace.debug('Left after ' + tok.current() + ', endings ' +
                 unicode(endings) + ', result: ' + result)
     return result
示例#26
0
 def assigninvoke(self, tok, token=None):
     "An assignment or a method invocation."
     self.onelineblock(tok)
     if not token:
         token = tok.current()
     token2 = tok.next()
     if token2 == '=':
         # assignment
         return token + ' = ' + self.parser.parsevalue(tok)
     if token2 == '.':
         member = tok.next()
         return self.assigninvoke(tok, token + '.' + member)
     if token2 == '(':
         parameters = self.parser.parseparameters(tok)
         Trace.debug('Parameters: ' + parameters)
         return self.assigninvoke(tok, token + parameters)
     if token2 == '[':
         square = self.parser.parseinsquare(tok)
         return self.assigninvoke(tok, token + square)
     if token2 == '{':
         # ignore anonymous class
         self.parser.parseupto('}', tok)
         return token
     if token2 == '++':
         Trace.debug('Increasing invoked ' + token)
         tok.autoincreases.append(token)
         return self.assigninvoke(tok, token + ' + 1')
     if token2 == '--':
         Trace.debug('Decreasing invoked ' + token)
         tok.autodecreases.append(token)
         return self.assigninvoke(tok, token + ' - 1')
     if token2 in [';', ',', ')']:
         # finished invocation
         return token
     if token2 in tok.javasymbols:
         Trace.error('Unknown symbol ' + token2 + ' for ' + token)
         return '*error ' + token + ' ' + token2 + ' error*'
     token3 = tok.next()
     if token3 == ';':
         # a declaration; ignore
         return ''
     if token3 == '=':
         # declaration + assignment
         tok.variables.append(token2)
         return token2 + ' = ' + self.parser.parsevalue(tok)
     if token3 == '[':
         # array declaration
         self.parser.parseupto(']', tok)
         return self.assigninvoke(tok, token2)
     Trace.error('Unknown combination ' + token + '+' + token2 + '+' +
                 token3)
     return '*error ' + token + ' ' + token2 + ' ' + token + ' error*'
示例#27
0
文件: porter.py 项目: ccpaging/elyxer
 def assigninvoke(self, tok, token = None):
   "An assignment or a method invocation."
   self.onelineblock(tok)
   if not token:
     token = tok.current()
   token2 = next(tok)
   if token2 == '=':
     # assignment
     return token + ' = ' + self.parser.parsevalue(tok)
   if token2 == '.':
     member = next(tok)
     return self.assigninvoke(tok, token + '.' + member)
   if token2 == '(':
     parameters = self.parser.parseparameters(tok)
     Trace.debug('Parameters: ' + parameters)
     return self.assigninvoke(tok, token + parameters)
   if token2 == '[':
     square = self.parser.parseinsquare(tok)
     return self.assigninvoke(tok, token + square)
   if token2 == '{':
     # ignore anonymous class
     self.parser.parseupto('}', tok)
     return token
   if token2 == '++':
     Trace.debug('Increasing invoked ' + token)
     tok.autoincreases.append(token)
     return self.assigninvoke(tok, token + ' + 1')
   if token2 == '--':
     Trace.debug('Decreasing invoked ' + token)
     tok.autodecreases.append(token)
     return self.assigninvoke(tok, token + ' - 1')
   if token2 in [';', ',', ')']:
     # finished invocation
     return token
   if token2 in tok.javasymbols:
     Trace.error('Unknown symbol ' + token2 + ' for ' + token)
     return '*error ' + token + ' ' + token2 + ' error*'
   token3 = next(tok)
   if token3 == ';':
     # a declaration; ignore
     return ''
   if token3 == '=':
     # declaration + assignment
     tok.variables.append(token2)
     return token2 + ' = ' + self.parser.parsevalue(tok)
   if token3 == '[':
     # array declaration
     self.parser.parseupto(']', tok)
     return self.assigninvoke(tok, token2)
   Trace.error('Unknown combination ' + token + '+' + token2 + '+' + token3)
   return '*error ' + token + ' ' + token2 + ' ' + token + ' error*'
示例#28
0
 def parsetoendings(self, tok, endings):
   "Parse the tokenizer up to a number of endings."
   result = ''
   tok.next()
   while not tok.current() in endings:
     processed = self.processtoken(tok)
     if processed == '++':
       processed = '+ 1'
       Trace.debug('Increasing ' + result + ' for endings: ' + unicode(endings))
       tok.autoincreases.append(result)
     if processed == '--':
       Trace.debug('Decreasing ' + result)
       processed = '- 1'
       tok.autodecreases.append(result)
     if processed != '.' and not result.endswith('.'):
       processed = ' ' + processed
     result += processed
     if not tok.current in endings:
       tok.next()
   if len(result) > 0:
     result = result[1:]
   Trace.debug('Left after ' + tok.current() + ', endings ' + unicode(endings) + ', result: ' + result)
   return result
示例#29
0
 def process(self):
     self.type = 'author'
     self.output.tag = 'h2 class="author"'
     author = self.extracttext()
     Trace.debug('Author: ' + author)
     DocumentAuthor.appendauthor(author)
示例#30
0
 def tree(self, level = 0):
   "Show in a tree"
   Trace.debug("  " * level + unicode(self))
   for container in self.contents:
     container.tree(level + 1)
示例#31
0
 def process(self):
   "Disable inactive branches"
   self.branch = self.header[2]
   if not self.isactive():
     Trace.debug('Branch ' + self.branch + ' not active')
     self.output = EmptyOutput()
示例#32
0
 def tree(self, level=0):
     "Show in a tree"
     Trace.debug("  " * level + unicode(self))
     for container in self.contents:
         container.tree(level + 1)
示例#33
0
 def process(self):
   self.type = 'author'
   self.output.tag = 'h2 class="author"'
   author = self.extracttext()
   Trace.debug('Author: ' + author)
   DocumentAuthor.appendauthor(author)