summaryrefslogtreecommitdiff
path: root/giscanner/annotationparser.py
Commit message (Collapse)AuthorAgeFilesLines
* scanner: Add (emitter) annotation for signalsEmmanuele Bassi2022-02-121-0/+15
| | | | | | Signals that have an emitter function should have an annotation to allow consumers of the introspection XML to effectively pair signals to their corresponding emitter functions that share the same prototype.
* CI: use a newer mypy in CI to fix the msys2 jobChristoph Reiter2022-02-021-4/+8
| | | | | | | | | | | | | MSYS2 recently updated Python to 3.9.10 which triggered a build issued present in typed_ast, which was fixed in typed_ast 1.5.0: https://github.com/python/typed_ast/issues/169 The currently used mypy version has an upper limit on typed_ast, so this fixed version wasn't pulled in. To fix this, update mypy, fix one new warning it complains about (namedtuple not being named after the variable), and install the markdown stubs explicitely, since mypy no longer bundles them.
* Add "forever" scopeEmmanuele Bassi2022-01-091-1/+3
| | | | | | | | Some functions are meant to exist for the entire duration of the process, and thus have no need for a notification function because one will never be called. Fixes: #49
* Add annotations for property setters and gettersEmmanuele Bassi2021-08-051-4/+48
| | | | | We need new annotations to allow library developers to associate a setter and a getter functions to a property definition.
* Add new annotations for property accessorsEmmanuele Bassi2021-08-051-3/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We introduce two new annotations: - (set-property PROPERTY_NAME) - (get-property PROPERTY_NAME) These annotations are valid inside function blocks for methods on objects and interfaces, and define whether a function is a property accessor, e.g.: /** * gtk_widget_set_name: (set-property name) * @self: ... * @name: ... * * ... */ /** * gtk_widget_get_name: (get-property name) * @self: ... * * ... * * Returns: ... */ The annotations are transformed into the GIR data as attributes: - glib:set-property="PROPERTY_NAME" - glib:get-property="PROPERTY_NAME" The underlying typelib data has had flags for setter and getter functions for a while, but they have never been plugged into the GIR data or the introspection scanner. Now they are; you can retrieve the GIPropertyInfo from a GIFunctionInfo that has the GI_FUNCTION_IS_SETTER or GI_FUNCTION_IS_GETTER flags set. Fixes: #13
* Update the developer.gnome.org URLsEmmanuele Bassi2021-08-051-1/+1
| | | | | | | The GNOME developers documentation website has been updated, and we're in the process of moving API references elsewhere. The old documentation is still available under developer-old.gnome.org, so let's update the URLs we have in our documentation.
* Add basic mypy supportChristoph Reiter2020-11-071-1/+2
| | | | | | Silence some errors, run mypy in CI Adding annotations to functions/classes will make mypy check them.
* Revert "giscanner: Fix section matching for documentation"Mathieu Duponchelle2020-09-291-6/+1
| | | | | | | | | This reverts commit de6512b31b614567bf1800406303d1ccfb6d9455. This was causing naming conflicts when the SECTION documentation was picked over the class documentation. See https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/360
* giscanner: Fix section matching for documentationJames Westman2020-09-071-1/+6
| | | | | | | | | | | | | When writing documentation to the GIR files, GIR tries to match classes with their matching SECTION: comment in the source code. Some codebases use kebab-case or CamelCase for their section names, but GIR always expects them to be flatcase or the matching will fail. This commit converts all section names to flatcase (by removing "-" and converting to lowercase) while they are being parsed, so that they are matched properly later on. Fixes #350.
* giscanner: parse block comments for members and fieldsMathieu Duponchelle2020-07-121-2/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | There was previously no mechanism for tagging enum members and struct fields with Since tags (or other, eg deprecation tags). While the customary place to add Since tags for these symbols is inline in the parent symbol's documentation eg: /** * Foo: * * @FOO_BAR: some bar. Since X.Y */ And variations on that theme, implementing parsing for that scheme would result in a pretty ambiguous grammar, especially if we also want support for multiple tags. Instead, the solution implemented here is to allow providing documentation for individual members and fields through their own separate block, as is done for virtual functions already. Inline comments are still used, with a lower precedence. Fixes #348
* flake8: fix invalid placeholder in GtkDocAnnotatable repr format stringChristoph Reiter2020-05-141-1/+1
| | | | The newest flake8 has started to detect this.
* Support the gtk-doc action syntaxEmmanuele Bassi2020-04-241-6/+36
| | | | | | | | | | | | | | | | GTK4 allows adding widget-related actions to the documentation with the newly defined syntax: <class_name> '|' <action_name> ':' This means g-ir-scanner needs to detect this new format, to avoid emitting unnecessary warnings. Currently, we don't do anything with the actions; in the future we might want to add them to the documentation in the GIR, but for that we'd need a new element. See also: GNOME/gtk-doc!30
* Drop all Python 2 compat codeChristoph Reiter2018-12-081-6/+0
| | | | We only support 3.4+ now.
* giscanner: Maintain python2 compat in annotationparserMikhail Fludkov2018-03-101-4/+4
| | | | | | Mixing ** and explicit keyword arguments is not allowed in Python 2. Signed-off-by: Nirbheek Chauhan <nirbheek@centricular.com>
* giscanner: Fix GtkDocAnnotations implementationNirbheek Chauhan2018-03-101-4/+4
| | | | | | | | Lesson to be learnt: *NEVER* have a try..except block that catches all exceptions and turns them into warnings that are silenced by default. There was a syntax error in this class implementation that made all annotation parsing fail silently.
* giscanner: Remove custom collections implementationNirbheek Chauhan2018-03-101-2/+1
| | | | | | | We already require python 2.7, and it has OrderedDict and Counter. Besides cleaning up unmaintained code, this change found and fixed a Python 3 bug where we were iterating over a dict while changing it.
* giscanner: Mark gpointer nodes as nullable by defaultPhilip Withnall2015-10-041-2/+34
| | | | | | | | | | | | | gpointer parameters and return types should be marked as nullable by default, unless: • also annotated with (type) and not with (nullable); or • explicitly annotated with (not nullable). This introduces the (not nullable) annotation as a direct opposite to (nullable). In future, (not) could be extended to invert other annotations. https://bugzilla.gnome.org/show_bug.cgi?id=729660
* giscanner: Use rich comparison methods for Python 3 compatibilitySimon Feltman2015-09-291-2/+24
| | | | | | | | | | Add lt, le, gt, ge, eq, ne, and hash dunder methods to all classes that implement custom comparisons with __cmp__. This is needed to support Python 3 compatible sorting of instances of these classes. Avoid using @functools.total_ordering which does not work for some of these classes and also is not available in Python 2.6. https://bugzilla.gnome.org/show_bug.cgi?id=679438
* giscanner: Use unicode literals in all Python filesSimon Feltman2015-09-291-2/+4
| | | | | | | | | | | | Add unicode_literals future import which turns any string literal into a unicode string. Return unicode strings from the Python C extension module. Force writing of annotations (g-ir-annotation-tool) to output utf8 encoded data to stdout. This is an initial pass at following the "unicode sandwich" model of programming (http://nedbatchelder.com/text/unipain.html) needed for supporting Python 3. https://bugzilla.gnome.org/show_bug.cgi?id=679438
* giscanner: Replace repr format usage with string formatterSimon Feltman2015-09-291-4/+4
| | | | | | | | | | | Replace occurances of "%r" (repr) in format strings where the intended behaviour is to output a quoted string "'foo'" with explicit usage of "'%s'". This is needed to move the codebase to unicode literals in order to upgrade to Python 3. Python 2 unicode strings are expanded with repr formatting prefixed with a "u" as in "u'foo'" which causes failures for various text formatting scenarios. https://bugzilla.gnome.org/show_bug.cgi?id=679438
* giscanner: Use print as a function for Python 3 compatibilitySimon Feltman2015-09-291-0/+1
| | | | | | | Use future import "print_function" and update relevant uses of print as a function call. See: PEP 3105 https://bugzilla.gnome.org/show_bug.cgi?id=679438
* giscanner: Enable "true division" for all Python filesSimon Feltman2015-09-291-0/+1
| | | | | | | | | | Import Python 3 compatible "true division" from the future (PEP 238). This changes the Python 2 classic division which uses floor division on integers to true division. Verfied we don't actually use the division operator anywhere in the code base so this a safety for supporting both Python 2 and 3. https://bugzilla.gnome.org/show_bug.cgi?id=679438
* scanner: centralize caret error message handlingDieter Verfaillie2015-06-241-98/+67
| | | | | | | Not doing this manually all over the place makes the code slightly more readable. https://bugzilla.gnome.org/show_bug.cgi?id=689454
* tests: sync with GTK-Doc test suite @ ↵Dieter Verfaillie2015-06-241-5/+2
| | | | | | 02e545371e2132a97458888895cacf57b8c0f83a (2015-06-23) https://bugzilla.gnome.org/show_bug.cgi?id=725685
* scanner: allow multiline annotationsDieter Verfaillie2015-04-181-50/+49
| | | | | | | Allow `identifier`, `parameter` and `tag` part `annotations` fields to span multiple lines https://bugzilla.gnome.org/show_bug.cgi?id=676133
* scanner: fix a docstring typoDieter Verfaillie2015-04-181-1/+1
|
* scanner: allow (array zero-terminated) instead of (array zero-terminated=1)Dieter Verfaillie2015-03-031-1/+6
| | | | | | | | | | | | | | What we already had: - (array zero-terminated=1) > array which is NULL terminated - (array zero-terminated=0) > array which is not NULL terminated - (array) > array which is not NULL terminated - (array zero-terminated=X) > array which is not NULL terminated where X can be anything What this patch adds: - (array zero-terminated) > array which is NULL terminated https://bugzilla.gnome.org/show_bug.cgi?id=657754
* annotationparser: more nullable fixesRyan Lortie2014-05-081-0/+2
| | | | | Add ANN_NULLABLE and ANN_OPTIONAL in the one (and only) other place that ANN_ALLOW_NONE is mentioned...
* giscanner: allow (nullable) and (optional)Ryan Lortie2014-05-071-2/+2
| | | | | | | Add (nullable) and (optional) as recognised annotations in the same places that (allow-none) is allowed. This should have been done in the previous commits but the tests were passing because the only ill effect was that a warning was issued.
* Revert "giscanner: don't accept (allow-none) on Returns:"Ryan Lortie2014-05-061-1/+1
| | | | | | | This reverts commit 0839e696e9fbc1942ac5c61054de3b47e9578152. This was accidentally picked up by my 'git bz apply' against the bug as I was getting ready to push the last set of changes.
* giscanner: add (nullable) and (optional) annotationsRyan Lortie2014-05-061-0/+26
| | | | | | | | | | | Add two new annotations, (nullable) and (optional). (nullable) always means "the type of this value can also contain null". (optional) always means "this out parameter can be ignored by passing NULL to the C function". https://bugzilla.gnome.org/show_bug.cgi?id=660879
* giscanner: don't accept (allow-none) on Returns:Dieter Verfaillie2014-05-061-1/+1
| | | | | | | | | The old annotationparser.py happily parsed this, but giscanner/girwriter.py never serialized an allow-none attribute to the .gir file and girepository/girparser.c never looked for an allow-none attribute either. https://bugzilla.gnome.org/show_bug.cgi?id=660879
* giscanner: fix c0e748e1cdf8cf0803266f94c3c5ad154df504a8Dieter Verfaillie2013-10-081-1/+2
| | | | | | | | | | | When encountering /**/ in the source, parse_gtk_doc_comment() would be executed (due to the /** part starting a GTK-Doc comment block) and would happily consume the / and everything up until the next comment block was closed or EOF, thus consuming a whole block of C code... Encoutered in the wild here: https://git.gnome.org/browse/clutter-gst/tree/clutter-gst/clutter-gst-player.c?id=03f0d8f48bd7f60e582e6185cb73a07038e8d55d#n1926
* giscanner: complain about text before the ' * 'Dieter Verfaillie2013-10-081-0/+9
| | | | | | Makes our GTK-Doc comment block rewriting tool halt on such issues, requireing user intervention instead of writing back even more bogus data.
* giscanner: return namedtuples where appropriateDieter Verfaillie2013-10-081-65/+77
| | | | | makes _parse_annotations() and _parse_fields() callers slightly more readable
* giscanner: Fix GtkDocBlock.position...Dieter Verfaillie2013-10-081-59/+119
| | | | | ... so it points to the start of the GTK-Doc comment block instead of the position of the identifier field.
* giscanner: refactor GTK-Doc comment block serializationDieter Verfaillie2013-10-081-103/+195
|
* giscanner: make some warnings errorsDieter Verfaillie2013-10-081-23/+23
| | | | | | | GTK-Doc comment block fixer tool will refuse to rewrite source files that generated errors (indicating a source->parse tree->source would result in information being lost), but will happily continue on warnings (which do not result in information being lost).
* giscanner: honor line and paragraph breaks in description fieldsDieter Verfaillie2013-10-081-14/+34
| | | | | | | | | GTK-Doc parameter description fields are allowed to span multiple lines, tag description fields are allowed to span multiple lines and paragraphs. A tool fixing/rewriting GTK-Doc comment blocks in source files would need to have description fields parsed and stored (almost) exactly as they appear in the source file.
* giscanner: improve state trackingDieter Verfaillie2013-10-081-19/+12
|
* giscanner: better lineno handlingDieter Verfaillie2013-10-081-12/+13
| | | | | | No need to enumerate the comment lines list as we already receive the lineno of the very first line as a parameter. Simply increment that one when looping over the comment lines list.
* giscanner: store indentation before the '*' of each lineDieter Verfaillie2013-10-081-14/+20
|
* giscanner: store code before and after comment blockDieter Verfaillie2013-10-081-32/+76
| | | | | | so we can later use them to re-write source files containing broken GTK-Doc comment blocks where /** is preceded by and/or */ is followed by code...
* giscanner: accept different forms of line breaksDieter Verfaillie2013-10-081-4/+4
|
* giscanner: merge _parse_comment_block() into parse_comment_block()Dieter Verfaillie2013-10-081-26/+0
|
* giscanner: refactor annotation validationDieter Verfaillie2013-10-081-260/+385
| | | | | | | | - annotations on the identifier (formerly g-i specific tags) have never been validated before, so fix this - removes duplicate validation code from GtkDocTag and GtkDocParameter - remove repeated validation code doing the same thing as annotationparser from maintransformer...
* giscanner: give parameters their own storage classDieter Verfaillie2013-10-081-40/+221
|
* giscanner: deprecate GObject-Introspection GTK-Doc tagsDieter Verfaillie2013-10-081-32/+53
| | | | | | | | | | | | | | | | | | | | | After discussing a different issue with the GTK-Doc maintainers, we learned that our g-i specific top level tags should never have existed in the first place. The prefered notation for annotations that apply to the identifier should be written on the identifier line, for example like what we already do with (skip). As a result, this patch deprecates g-i specific top level tags and implements them as annotations on the identifier instead but still keeps support for malformed comment blocks using g-i specific top level tags. This means that all annotated code "out there" will continue to work just fine with this version of g-i, but when a developer decides to fix deprecation warnings in his/her comment blocks, the dependency on g-i needs to be raised to a version that contains at least this patch. #676133 https://bugzilla.gnome.org/show_bug.cgi?id=676133
* giscanner: flesh out annotation parsing and storageDieter Verfaillie2013-10-081-367/+611
| | | | | | | | | | - remove annotations regex, restore proper parens parsing - drop weird DocOption() storage class and use lists/dicts as appropriate - make GtkDocAnnotations a simple OrderedDict subclass instead of a weird hybrid dict/list storage class - Deprecate Attribute: tag, replace with (attributes) annotation on the identifier
* giscanner: extract tag valuesDieter Verfaillie2013-10-081-9/+54
|