Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user guide about models #280

Merged
merged 1 commit into from
Feb 23, 2025

Conversation

akosthekiss
Copy link
Collaborator

  • The example grammar was incorrect, at least for parsing. For ANTLR, character classes are invalid in parser rules, may only be used in lexer rules. Thus, grammar was rewritten to use lexer rules.
  • In the python examples, indentation was off by one for quantify and charset methods. Fixed.
  • The quantify methods in the examples used an old API: the number and names of arguments was incorrect, and the methods still acted as generators. So, the cnt argument was added, min and max were renamed to start and stop, and return was used instead of yielding.
  • Since the decimal rule in the grammar got turned into an lexer rule, Decimal nodes don't have children anymore. Thus, charset methods in the examples have been updated to make decisions based on token length instead of children count.
  • It got revealed that charset methods don't get charsets as lists but as tuples. The documentation of Model.charset had to updated and example charset methods had to be adapted.
  • All methods in the DispatchingModel subclass example fell into infinite recursion. The use of super() in the subclass directed the call to the method defined in DispatchingModel, which in turn called back into the subclass (and so on), instead of calling to the method in DefaultModel, the parent class of DispatchingModel and the grandparent of the subclass. Fixed by using the two-argument version of super(..., ...).

Fixes: #272

- The example grammar was incorrect, at least for parsing. For
  ANTLR, character classes are invalid in parser rules, may only be
  used in lexer rules. Thus, grammar was rewritten to use lexer
  rules.
- In the python examples, indentation was off by one for `quantify`
  and `charset` methods. Fixed.
- The `quantify` methods in the examples used an old API: the
  number and names of arguments was incorrect, and the methods
  still acted as generators. So, the `cnt` argument was added,
  `min` and `max` were renamed to `start` and `stop`, and `return`
  was used instead of `yield`ing.
- Since the `decimal` rule in the grammar got turned into an lexer
  rule, `Decimal` nodes don't have children anymore. Thus,
  `charset` methods in the examples have been updated to make
  decisions based on token length instead of children count.
- It got revealed that `charset` methods don't get charsets as
  lists but as tuples. The documentation of `Model.charset` had to
  updated and example `charset` methods had to be adapted.
- All methods in the `DispatchingModel` subclass example fell into
  infinite recursion. The use of `super()` in the subclass directed
  the call to the method defined in `DispatchingModel`, which in
  turn called back into the subclass (and so on), instead of
  calling to the method in `DefaultModel`, the parent class of
  `DispatchingModel` and the grandparent of the subclass. Fixed by
  using the two-argument version of `super(..., ...)`.

Fixes: renatahodovan#272
@coveralls
Copy link

Coverage Status

coverage: 83.374% (-0.5%) from 83.859%
when pulling 1100b49 on akosthekiss:fix-model-docs
into 49a835e on renatahodovan:master.

Copy link
Owner

@renatahodovan renatahodovan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@renatahodovan renatahodovan merged commit 0402b7f into renatahodovan:master Feb 23, 2025
26 checks passed
@akosthekiss akosthekiss deleted the fix-model-docs branch February 23, 2025 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue in docs
3 participants