Skip to content

Commit

Permalink
Use objectliterals.jsdoc instead of objectliterals.exports
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Apr 7, 2013
1 parent b833525 commit 1d54312
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 302 deletions.
54 changes: 33 additions & 21 deletions bin/generate-exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,43 @@ def main(argv):
objects = {}
requires = set()
for arg in args:
in_comment = False
object_literal = None
for line in open(arg):
line = line.strip()
if not line:
continue
if line == '/**':
assert not in_comment
in_comment = True
continue
if line == '*/':
assert in_comment
in_comment = False
object_literal = None
continue
if in_comment:
if not line.startswith('*'):
raise RuntimeError(line) # malformed comment
m = re.match(r'\*\s*@typedef\s*\{Object\}\s*(?P<name>\S+)', line)
if m:
assert object_literal is None
name = m.group('name')
if name in objects:
raise RuntimeError(line) # Name already defined
object_literal = ObjectLiteral(name)
objects[name] = object_literal
continue
m = re.match(r'\*\s*@property\s*{(?P<type>.*)}\s*(?P<prop>\S+)', line)
if m:
assert object_literal is not None
prop = m.group('prop')
if prop in object_literal.prop_types:
raise RuntimeError(line) # Duplicate property
type = m.group('type')
object_literal.prop_types[prop] = type
continue
continue
m = re.match(r'@exportClass\s+(?P<name>\S+)(?:\s+(?P<object_literal_name>\S+))?\Z', line)
if m:
name = m.group('name')
Expand All @@ -215,27 +248,6 @@ def main(argv):
klass = Class(name, object_literal, objects)
objects[name] = klass
continue
m = re.match(r'@exportObjectLiteral\s+(?P<name>\S+)\Z', line)
if m:
name = m.group('name')
if name in objects:
raise RuntimeError(line) # Name already defined
object_literal = ObjectLiteral(name)
objects[name] = object_literal
continue
m = re.match(r'@exportObjectLiteralProperty\s+(?P<prop>\S+)\s+(?P<type>\S+)\Z', line)
if m:
components = m.group('prop').split('.')
name = '.'.join(components[:-1])
if not name in objects:
raise RuntimeError(line) # Undefined object literal
object_literal = objects[name]
prop = components[-1]
if prop in object_literal.prop_types:
raise RuntimeError(line) # Duplicate property
type = m.group('type')
object_literal.prop_types[prop] = type
continue
m = re.match(r'@exportProperty\s+(?P<prop>\S+)\Z', line)
if m:
components = m.group('prop').split('.')
Expand Down
19 changes: 9 additions & 10 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@

EXPORTS = [path
for path in ifind('src')
if path.endswith('.exports')
if path != 'src/objectliterals.exports']
if path.endswith('.exports')]

EXTERNAL_SRC = [
'build/src/external/externs/types.js',
Expand Down Expand Up @@ -212,24 +211,24 @@ def build_ol_all_js(t):


@target('build/src/external/externs/types.js', 'bin/generate-exports.py',
'src/objectliterals.exports')
'src/objectliterals.jsdoc')
def build_src_external_externs_types_js(t):
t.output('%(PYTHON)s', 'bin/generate-exports.py',
'--externs', 'src/objectliterals.exports')
'--externs', 'src/objectliterals.jsdoc')


@target('build/src/external/src/exports.js', 'bin/generate-exports.py',
'src/objectliterals.exports', EXPORTS)
'src/objectliterals.jsdoc', EXPORTS)
def build_src_external_src_exports_js(t):
t.output('%(PYTHON)s', 'bin/generate-exports.py',
'--exports', 'src/objectliterals.exports', EXPORTS)
'--exports', 'src/objectliterals.jsdoc', EXPORTS)


@target('build/src/external/src/types.js', 'bin/generate-exports.py',
'src/objectliterals.exports')
'src/objectliterals.jsdoc')
def build_src_external_src_types_js(t):
t.output('%(PYTHON)s', 'bin/generate-exports.py',
'--typedef', 'src/objectliterals.exports')
'--typedef', 'src/objectliterals.jsdoc')


if os.path.exists(TEMPLATE_GLSL_COMPILER_JS):
Expand Down Expand Up @@ -268,10 +267,10 @@ def build_test_requireall_js(t):


@target('build/src/internal/src/types.js', 'bin/generate-exports.py',
'src/objectliterals.exports')
'src/objectliterals.jsdoc')
def build_src_internal_types_js(t):
t.output('%(PYTHON)s', 'bin/generate-exports.py',
'--typedef', 'src/objectliterals.exports')
'--typedef', 'src/objectliterals.jsdoc')


virtual('build-examples', 'examples', EXAMPLES_COMBINED)
Expand Down
Loading

0 comments on commit 1d54312

Please sign in to comment.