return res # the next would be close to the spec (but huge!) #identi = py.Word(u''.join(lang.IDENTIFIER_CHARS_START), u''.join(lang.IDENTIFIER_CHARS_BODY)) # but using regex, to be consistent with the parser py_js_identifier = py.Regex(lang.IDENTIFIER_REGEXP) py_simple_type = py.Suppress('{') + py_js_identifier.copy()( 'type_name') + py.Suppress('}') py_single_type = py_js_identifier.copy().setResultsName('type_name') + \ py.ZeroOrMore('[]').setResultsName('type_dimensions') # mirror: {Foo|Bar? 34} py_type_expression = py.Suppress('{') + py.Optional( py.delimitedList(py_single_type, delim='|')("texp_types") + # Foo|Bar py.Optional( py.Literal('?')("texp_optional") + # ? py.Optional(py.Regex(r'[^}]+'))("texp_defval")) # 34 ) + py.Suppress('}') ## # "@type {Map} gr_at_type = py.Suppress('@') + py.Literal('type') + py_simple_type def parse_at_type(self, line): grammar = self.gr_at_type presult = grammar.parseString(line) res = { 'category': 'type', 'type': presult.type_name,
} return res # the next would be close to the spec (but huge!) #identi = py.Word(u''.join(lang.IDENTIFIER_CHARS_START), u''.join(lang.IDENTIFIER_CHARS_BODY)) # but using regex, to be consistent with the parser py_js_identifier = py.Regex(lang.IDENTIFIER_REGEXP) py_simple_type = py.Suppress('{') + py_js_identifier.copy()('type_name') + py.Suppress('}') py_single_type = py_js_identifier.copy().setResultsName('type_name') + \ py.ZeroOrMore('[]').setResultsName('type_dimensions') # mirror: {Foo|Bar? 34} py_type_expression = py.Suppress('{') + py.Optional( py.delimitedList(py_single_type, delim='|')("texp_types") + # Foo|Bar py.Optional(py.Literal('?')("texp_optional") + # ? py.Optional(py.Regex(r'[^}]+'))("texp_defval")) # 34 ) + py.Suppress('}') ## # "@type {Map} gr_at_type = py.Suppress('@') + py.Literal('type') + py_simple_type def parse_at_type(self, line): grammar = self.gr_at_type presult = grammar.parseString(line) res = { 'category' : 'type', 'type' : presult.type_name, } return res
'text' : presult.text.strip(), } return res # the next would be close to the spec (but huge!) #identi = py.Word(u''.join(lang.IDENTIFIER_CHARS_START), u''.join(lang.IDENTIFIER_CHARS_BODY)) # but using regex, to be consistent with the parser py_js_identifier = py.Regex(lang.IDENTIFIER_REGEXP) # next: Ugly hack to add '*' to identifier globs __idx = lang.IDENTIFIER_REGEXP.rfind(']') py_js_identifier_glob = py.Regex(lang.IDENTIFIER_REGEXP[:__idx] + '\\*' + lang.IDENTIFIER_REGEXP[__idx:]) # next: still wider, matching more elements py_term_argument = py.Regex(r'(?u)[^\s,)]+') py_comment_term = (py_js_identifier.copy().setResultsName('t_functor') + py.Suppress('(') + py.Optional(py.delimitedList(py_term_argument)) # 'foo.Bar#baz' .setResultsName('t_arguments') + py.Suppress(')')) py_simple_type = py.Suppress('{') + py_js_identifier.copy()('type_name') + py.Suppress('}') py_single_type = py_js_identifier.copy().setResultsName('type_name') + \ py.ZeroOrMore('[]').setResultsName('type_dimensions') # mirror: {Foo|Bar? 34} py_type_expression = py.Suppress('{') + py.Optional( py.delimitedList(py_single_type, delim='|')("texp_types") + # Foo|Bar py.Optional(py.Literal('?')("texp_optional") + # ? py.Optional(py.Regex(r'[^}]+'))("texp_defval")) # 34 ) + py.Suppress('}') ##
return res # the next would be close to the spec (but huge!) # identi = py.Word(u''.join(lang.IDENTIFIER_CHARS_START), u''.join(lang.IDENTIFIER_CHARS_BODY)) # but using regex, to be consistent with the parser py_js_identifier = py.Regex(lang.IDENTIFIER_REGEXP) # next: Ugly hack to add '*' to identifier globs __idx = lang.IDENTIFIER_REGEXP.rfind("]") py_js_identifier_glob = py.Regex(lang.IDENTIFIER_REGEXP[:__idx] + "\\*" + lang.IDENTIFIER_REGEXP[__idx:]) # next: still wider, matching more elements py_term_argument = py.Regex(r"(?u)[^\s,)]+") py_comment_term = ( py_js_identifier.copy().setResultsName("t_functor") + py.Suppress("(") + py.Optional(py.delimitedList(py_term_argument)).setResultsName("t_arguments") # 'foo.Bar#baz' + py.Suppress(")") ) py_simple_type = py.Suppress("{") + py_js_identifier.copy()("type_name") + py.Suppress("}") py_single_type = py_js_identifier.copy().setResultsName("type_name") + py.ZeroOrMore("[]").setResultsName( "type_dimensions" ) # mirror: {Foo|Bar? 34} py_type_expression = ( py.Suppress("{") + py.Optional( py.delimitedList(py_single_type, delim="|")("texp_types") + py.Optional( # Foo|Bar
# the next would be close to the spec (but huge!) #identi = py.Word(u''.join(lang.IDENTIFIER_CHARS_START), u''.join(lang.IDENTIFIER_CHARS_BODY)) # but using regex, to be consistent with the parser py_js_identifier = py.Regex(lang.IDENTIFIER_REGEXP) # next: Ugly hack to add '*' to identifier globs __idx = lang.IDENTIFIER_REGEXP.rfind(']') py_js_identifier_glob = py.Regex(lang.IDENTIFIER_REGEXP[:__idx] + '\\*' + lang.IDENTIFIER_REGEXP[__idx:]) py_simple_type = py.Suppress('{') + py_js_identifier.copy()('type_name') + py.Suppress('}') py_single_type = py_js_identifier.copy().setResultsName('type_name') + \ py.ZeroOrMore('[]').setResultsName('type_dimensions') # mirror: {Foo|Bar? 34} py_type_expression = py.Suppress('{') + py.Optional( py.delimitedList(py_single_type, delim='|')("texp_types") + # Foo|Bar py.Optional(py.Literal('?')("texp_optional") + # ? py.Optional(py.Regex(r'[^}]+'))("texp_defval")) # 34 ) + py.Suppress('}') ## # "@type {Map} gr_at_type = py.Suppress('@') + py.Literal('type') + py_simple_type def parse_at_type(self, line): grammar = self.gr_at_type presult = grammar.parseString(line) res = { 'category' : 'type', 'type' : presult.type_name, } return res
# the next would be close to the spec (but huge!) #identi = py.Word(u''.join(lang.IDENTIFIER_CHARS_START), u''.join(lang.IDENTIFIER_CHARS_BODY)) # but using regex, to be consistent with the parser py_js_identifier = py.Regex(lang.IDENTIFIER_REGEXP) # next: Ugly hack to add '*' to identifier globs __idx = lang.IDENTIFIER_REGEXP.rfind(']') py_js_identifier_glob = py.Regex(lang.IDENTIFIER_REGEXP[:__idx] + '\\*' + lang.IDENTIFIER_REGEXP[__idx:]) # next: still wider, matching more elements py_term_argument = py.Regex(r'(?u)[^\s,)]+') py_comment_term = ( py_js_identifier.copy().setResultsName('t_functor') + py.Suppress('(') + py.Optional(py.delimitedList(py_term_argument)) # 'foo.Bar#baz' .setResultsName('t_arguments') + py.Suppress(')')) py_simple_type = py.Suppress('{') + py_js_identifier.copy()( 'type_name') + py.Suppress('}') py_single_type = py_js_identifier.copy().setResultsName('type_name') + \ py.ZeroOrMore('[]').setResultsName('type_dimensions') # mirror: {Foo|Bar? 34} py_type_expression = py.Suppress('{') + py.Optional( py.delimitedList(py_single_type, delim='|')("texp_types") + # Foo|Bar py.Optional( py.Literal('?')("texp_optional") + # ? py.Optional(py.Regex(r'[^}]+'))("texp_defval")) # 34 ) + py.Suppress('}')