Permalink
Browse files

And yeah, syntax highlighting and nested function arguments kind of w…

…ork!
  • Loading branch information...
1 parent b580976 commit 73d9d1ca1103b1337c240fe36e6fb43e4ba99146 @fredreichbier committed May 12, 2012
Showing with 18 additions and 23 deletions.
  1. +1 −0 source/conf.py
  2. +1 −1 source/index.rst
  3. +0 −19 source/test.rst
  4. +16 −3 sphinx_ooc/__init__.py
View
1 source/conf.py
@@ -32,6 +32,7 @@
# We do ooc!
primary_domain = 'ooc'
+highlight_language = 'ooc'
# The suffix of source filenames.
source_suffix = '.rst'
View
2 source/index.rst
@@ -11,12 +11,12 @@ Contents:
.. toctree::
:maxdepth: 2
+ the-ooc-language/index
Indices and tables
==================
* :ref:`genindex`
-* :ref:`modindex`
* :ref:`search`
View
19 source/test.rst
@@ -1,19 +0,0 @@
-Test
-====
-
-.. module:: lang/string
-
-.. class:: String
-
- Heya!
-
-.. module:: nark/fu
-
-Hey, an *ooc* function:
-
-.. function:: fubar(yessss: :class:`~lang/string String`)
-
- Yeah, this is documentation, baby!
-
-
-Also, a reference to it: :func:`nark fubar`.
View
19 sphinx_ooc/__init__.py
@@ -53,8 +53,11 @@ def parse_arglist(self, parameternode, arglist):
"""
Parse and create a parameter list. With crossrefs even!
"""
+ # TODO: do a real parser that handles nested function types with argument lists
+ # e.g. `f: func (b: Func (a, b, c) -> d)`
stack = [parameternode]
token_before = None
+ openparens = 0
for token in ooc_paramlist_re.split(arglist):
if token == ',':
# skip lonely commas. we don't want them. :(
@@ -67,17 +70,27 @@ def parse_arglist(self, parameternode, arglist):
else:
token = token_before + token
token_before = None
+ openparens += token.count('(')
+ openparens -= token.count(')')
if token.count('<') != (token.count('>') - token.count('->')):
# splitted in the middle of a <A, B, C> declaration :(
token_before = token
+ continue
+ if openparens > 0:
+ # we still have some open parens! we need to join the next token
+ token_before = token + ', ' # TODO: I guess?
+ # but reset the counter
+ openparens -= token.count('(')
+ openparens += token.count(')')
+ continue
elif not token or token == ',' or token.isspace():
- pass
+ continue
else:
token = token.strip()
if ':' in token:
# We have a type and we can link it.
- if 'Func' in token:
- print repr(token)
+ if '->:' in token:
+ token = token.replace('->:', '-> :') # TODO: wow, how nasty
stack[-1] += addnodes.desc_parameter('', '', *self._resolve_typeref(token))
else:
stack[-1] += addnodes.desc_parameter(token, token)

0 comments on commit 73d9d1c

Please sign in to comment.