Exemplo n.º 1
0
    def parse_simple(self):
        self.eat_whitespace()
        c = chr(self.peek)

        if c == u('('):
            self.next()
            tree = self.parse_tree()
            self.eat_whitespace()
            self.eat(')')
            return tree

        if c == u('/'):
            return NameTree.Leaf(self.parse_path())

        if c == u('!'):
            self.next()
            return NameTree.Fail

        if c == u('~'):
            self.next()
            return NameTree.Neg

        if c == u('$'):
            self.next()
            return NameTree.Empty

        self.illegal("simple", c)
Exemplo n.º 2
0
  def parse_simple(self):
    self.eat_whitespace()
    c = chr(self.peek)

    if c == u('('):
      self.next()
      tree = self.parse_tree()
      self.eat_whitespace()
      self.eat(')')
      return tree

    if c == u('/'):
      return NameTree.Leaf(self.parse_path())

    if c == u('!'):
      self.next()
      return NameTree.Fail

    if c == u('~'):
      self.next()
      return NameTree.Neg

    if c == u('$'):
      self.next()
      return NameTree.Empty

    self.illegal("simple", c)
Exemplo n.º 3
0
 def eat_whitespace(self):
     while not self.at_end and (self.ord in WHITESPACE
                                or self.chr == u("#")):
         if self.chr == u("#"):
             self.eat_line()
         else:
             self.next()
Exemplo n.º 4
0
 def __init__(self, str_input):
   # avoiding circular dependencies
   from dtab.dtab import Dentry, Dtab
   self._dentry_cls = Dentry
   self._dtab_cls = Dtab
   self._str_input = u(str_input)
   self._index = 0
Exemplo n.º 5
0
 def __init__(self, str_input):
     # avoiding circular dependencies
     from dtab.dtab import Dentry, Dtab
     self._dentry_cls = Dentry
     self._dtab_cls = Dtab
     self._str_input = u(str_input)
     self._index = 0
Exemplo n.º 6
0
 def parse_number(self):
   result = ""
   seendot = False
   while self.is_number_char(self.peek):
     if self.peek == ord('.'):
       seendot = True if not seendot else self.illegal("number char", self.peek)
     result += chr(self.peek)
     self.next()
   if len(result) == 1 and result[0] == u('.'):
     self.illegal("weight", '.')
   return float(result)
Exemplo n.º 7
0
 def parse_number(self):
     result = ""
     seendot = False
     while self.is_number_char(self.peek):
         if self.peek == ord('.'):
             seendot = True if not seendot else self.illegal(
                 "number char", self.peek)
         result += chr(self.peek)
         self.next()
     if len(result) == 1 and result[0] == u('.'):
         self.illegal("weight", '.')
     return float(result)
Exemplo n.º 8
0
 def parse_label(self):
   bio = BytesIO()
   while True:
     c = self.peek
     if Path.is_showable(c):
       self.next()
       bio.write(chr(c))
     elif c == FORWARD_SLASH:
       self.next()
       self.eat(u('x'))
       fst = self.parse_hex_char()
       snd = self.parse_hex_char()
       bio.write(chr(int(fst, 16) << 4 | int(snd, 16)))
     else:
       self.illegal("label char", c)
     if not self.is_label_char(self.peek):
       break
   return bio.getvalue().decode('utf-8')
Exemplo n.º 9
0
 def parse_label(self):
     bio = BytesIO()
     while True:
         c = self.peek
         if Path.is_showable(c):
             self.next()
             bio.write(bytes(c))
         elif c == FORWARD_SLASH:
             self.next()
             self.eat(u('x'))
             fst = self.parse_hex_char()
             snd = self.parse_hex_char()
             bio.write(chr(int(fst, 16) << 4 | int(snd, 16)))
         else:
             self.illegal("label char", c)
         if not self.is_label_char(self.peek):
             break
     return bio.getvalue().decode('utf-8')
Exemplo n.º 10
0
 def Utf8(cls, *elems):
     return cls(*[u(elem) for elem in elems])
Exemplo n.º 11
0
 def Utf8(cls, *elems):
   return cls(*[u(elem) for elem in elems])
Exemplo n.º 12
0
 def is_number_char(self, char):
   char = chr(char)
   return char.isdigit() or char == u('.')
Exemplo n.º 13
0
 def eat_line(self):
   while (not self.at_end and self.chr != u("\n")):
     self.next()
   if not self.at_end:
     self.eat("\n")
Exemplo n.º 14
0
 def eat_whitespace(self):
   while not self.at_end and (self.ord in WHITESPACE or self.chr == u("#")):
     if self.chr == u("#"):
       self.eat_line()
     else:
       self.next()
Exemplo n.º 15
0
 def is_number_char(self, char):
     char = chr(char)
     return char.isdigit() or char == u('.')
Exemplo n.º 16
0
 def eat_line(self):
     while (not self.at_end and self.chr != u("\n")):
         self.next()
     if not self.at_end:
         self.eat("\n")