MCPcopy Index your code
hub / github.com/clips/pattern / nextobject

Method nextobject

pattern/web/pdf/psparser.py:532–592  ·  view source on GitHub ↗

Yields a list of objects. Returns keywords, literals, strings, numbers, arrays and dictionaries. Arrays and dictionaries are represented as Python lists and dictionaries.

(self)

Source from the content-addressed store, hash-verified

530 return
531
532 def nextobject(self):
533 """Yields a list of objects.
534
535 Returns keywords, literals, strings, numbers, arrays and dictionaries.
536 Arrays and dictionaries are represented as Python lists and dictionaries.
537 """
538 while not self.results:
539 (pos, token) = self.nexttoken()
540 #print (pos,token), (self.curtype, self.curstack)
541 if (isinstance(token, int) or
542 isinstance(token, float) or
543 isinstance(token, bool) or
544 isinstance(token, str) or
545 isinstance(token, PSLiteral)):
546 # normal token
547 self.push((pos, token))
548 elif token == KEYWORD_ARRAY_BEGIN:
549 # begin array
550 self.start_type(pos, 'a')
551 elif token == KEYWORD_ARRAY_END:
552 # end array
553 try:
554 self.push(self.end_type('a'))
555 except PSTypeError:
556 if STRICT: raise
557 elif token == KEYWORD_DICT_BEGIN:
558 # begin dictionary
559 self.start_type(pos, 'd')
560 elif token == KEYWORD_DICT_END:
561 # end dictionary
562 try:
563 (pos, objs) = self.end_type('d')
564 if len(objs) % 2 != 0:
565 raise PSSyntaxError('Invalid dictionary construct: %r' % objs)
566 # construct a Python dictionary.
567 d = dict( (literal_name(k), v) for (k,v) in choplist(2, objs) if v is not None )
568 self.push((pos, d))
569 except PSTypeError:
570 if STRICT: raise
571 elif token == KEYWORD_PROC_BEGIN:
572 # begin proc
573 self.start_type(pos, 'p')
574 elif token == KEYWORD_PROC_END:
575 # end proc
576 try:
577 self.push(self.end_type('p'))
578 except PSTypeError:
579 if STRICT: raise
580 else:
581 if 2 <= self.debug:
582 print >>sys.stderr, 'do_keyword: pos=%r, token=%r, stack=%r' % \
583 (pos, token, self.curstack)
584 self.do_keyword(pos, token)
585 if self.context:
586 continue
587 else:
588 self.flush()
589 obj = self.results.pop(0)

Callers 7

load_trailerMethod · 0.80
loadMethod · 0.80
getobjMethod · 0.80
runMethod · 0.80
get_objectsMethod · 0.80
get_encodingMethod · 0.80
executeMethod · 0.80

Calls 11

pushMethod · 0.95
start_typeMethod · 0.95
end_typeMethod · 0.95
do_keywordMethod · 0.95
choplistFunction · 0.90
lenFunction · 0.85
PSSyntaxErrorClass · 0.85
literal_nameFunction · 0.85
nexttokenMethod · 0.80
flushMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected