Commit 5f97a348 authored by Per Cederqvist's avatar Per Cederqvist

(lexer.__init__): Set __builtin_types, __builtin_aggregates,

	__builtin_typelike, __tindex_seen and __types_used.
(lexer.__seen_type): New method.
(lexer.toplevel_tindex): Implement.
(lexer.__parse_userdefined_types): New method, not yet implemented.
(lexer.__bad_type): Check that the casing rules for user-defined
	types are adhered to.
parent 9f0a5769
......@@ -97,6 +97,14 @@ class lexer:
self.__reader = reader(file)
self.__findex = None
self.__linkhere = None
self.__builtin_types = ["BOOL", "INT8", "INT16", "INT32",
"HOLLERITH"]
self.__builtin_aggregates = ["BITSTRING", "ENUMERATION",
"ARRAY", "SELECTION", "RPC"]
self.__builtin_typelike = (self.__builtin_types
+ self.__builtin_aggregates)
self.__tindex_seen = {}
self.__types_used = {}
def run(self):
while 1:
......@@ -213,7 +221,6 @@ class lexer:
toplevel_priv = ignore
toplevel_emph = ignore
toplevel_enumerate = ignore
toplevel_tindex = ignore # FIXME: check 'em?
toplevel_xref = ignore
toplevel_itemx = ignore
toplevel_ae = ignore
......@@ -251,7 +258,6 @@ class lexer:
return
self.__findex = arg
self.__args = {}
self.__tokens = []
if self.__get_token() != '@example':
self.error(self.__reader.line_no(), "missing @example")
return
......@@ -273,6 +279,8 @@ class lexer:
def toplevel_bye(self, arg, line_no):
if self.__findex != None:
self.error(self.__reader.line_no(), "unterminated @findex node")
# FIXME: check __tindex_seen and __tindex_used. They should
# contain the same keys. Report any discrepancies.
def toplevel_reqdlink(self, arg, line_no):
self.__assert_no_linkhere()
......@@ -288,6 +296,39 @@ class lexer:
self.error(line_no, "spurious @linkhere{}")
self.__linkhere = None
def __seen_type(self, arg, line_no):
if self.__tindex_seen.has_key(arg):
self.error(line_no, "multiple @tindex entries for %s" % arg)
self.error(self.__tindex_seen[arg], "previous location")
else:
self.__tindex_seen[arg] = line_no
def toplevel_tindex(self, arg, line_no):
self.__seen_type(arg, line_no)
if arg in self.__builtin_typelike:
return
self.__bad_type(arg)
self.__tokens = []
t = self.__get_token()
while t == '@tindex':
t = self.__get_token()
self.__seen_type(t, self.__reader.line_no())
self.__bad_type(t)
t = self.__get_token()
if t != '@example':
self.error(self.__reader.line_no(),
"missing @example after @tindex for defined type")
return
self.__parse_userdefined_types()
def __parse_userdefined_types(self):
# FIXME
# FIXME: Check that the defined type has a @tindex above.
# FIXME: Parse the type.
pass
def __parse_request(self):
self.__tokens = []
req = self.__get_token()
......@@ -374,16 +415,30 @@ class lexer:
return token
def __bad_type(self, tp):
if tp in ['INT8', 'INT16', 'INT32']:
if tp in self.__builtin_types:
return 0
# This is an ugly special case, that is a good type name.
# More or less.
if tp == "UConference":
return 0
ok = 1
if len(tp) < 0:
ok = 0
if ok and not tp[0].isupper():
ok = 0
upper = 0
for c in tp[1:]:
if not c.isalpha() and c != '-':
ok = 0
if upper:
if c == '-' or not c.isupper():
ok = 0
upper = 0
else:
if c == '-':
upper = 1
elif not c.islower():
ok = 0
if ok and tp[-1] == '-':
ok = 0
if not ok:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment