w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

comment_stripper.py
Go to the documentation of this file.
1 # Copyright (C) 2018 and later: Unicode, Inc. and others.
2 # License & terms of use: http://www.unicode.org/copyright.html
3 
4 import io
5 
7  """Removes lines starting with "//" from a file stream."""
8 
9  def __init__(self, f):
10  self.ff = f
11  self.statestate = 0
12 
13  def read(self, size=-1):
14  bytes = self.ff.read(size)
15  # TODO: Do we need to read more bytes if comments were stripped
16  # in order to obey the size request?
17  return "".join(self._strip_comments_strip_comments(bytes))
18 
19  def _strip_comments(self, bytes):
20  for byte in bytes:
21  if self.statestate == 0:
22  # state 0: start of a line
23  if byte == "/":
24  self.statestate = 1
25  elif byte == "\n":
26  self.statestate = 0
27  yield byte
28  else:
29  self.statestate = 2
30  yield byte
31  elif self.statestate == 1:
32  # state 1: read a single '/'
33  if byte == "/":
34  self.statestate = 3
35  elif byte == "\n":
36  self.statestate = 0
37  yield "/" # the one that was skipped
38  yield "\n"
39  else:
40  self.statestate = 2
41  yield "/" # the one that was skipped
42  yield byte
43  elif self.statestate == 2:
44  # state 2: middle of a line, no comment
45  if byte == "\n":
46  self.statestate = 0
47  yield byte
48  elif self.statestate == 3:
49  # state 3: inside a comment
50  if byte == "\n":
51  self.statestate = 0
#define join
Definition: ctangleboot.c:112