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

Rewrite of Annotation parser #91

Merged
merged 23 commits into from
Feb 28, 2012
Merged

Rewrite of Annotation parser #91

merged 23 commits into from
Feb 28, 2012

Conversation

maoueh
Copy link
Contributor

@maoueh maoueh commented Feb 28, 2012

This is the rewrite of the Annotation parsing code.

  • Rewrited lexer and parser almost from scratch
  • The new parser is designed to parse any annotations that is possible to write within Symfony2
  • Added an annotation model which represents the annotation and its sub-annotations
  • Changed and added tests for AnnotationParser and AnnotationCommentParser
  • Added an AnnotationCommentParser responsible to parse annotations from a comment
  • Ported code to use the new AnnotationCommentParser
  • Tried hard to put comment parsing stuff in AnnotationUtils

Tests are passing except one which is also failling in the master branch. I tested what I could (highlighting, report unresolvable annotation, template view extraction). However, for some features (like the F3 for template), I was not able to test it until the end of the chain due to what I suspect are bugs.

Moreover, the last missing bit is the error reporter which is not appended to the parser for now. I think it is not that bad for now since the code for reporting the error in the concrete IErrorReporter is commented anyway.

I will send a PR to the Doctrine-Eclipse-Plugin since it depends of code from this PR.

This PR will fix gh-50. Don't hesitate to ask me if you want to change some stuff inside the PR or if you want me to squash the commits.

Regards,
Matt

 * These classes will hold informations on the Annotation.
 * They will be used by the new AnnotationParser and associated visitor
   to create a structural representation of an Annotation
 * Still more work to do to support more constructs but for now, common
   uses cases are covered.
   (Passes all AnnotationParserTest)
 * Updated and added new tests to show that more use cases than before are
   covered.
 * Changed the AnnotationNodeVisitor to populate an Annotation object.
 * Added a AnnotationObjectValueVisitor to populate a ObjectValue object.
 * For now, kept all old methods of AnnotationNodeVisitor but this will
   change.
 * Added a method getErrorsAsString in the DebugErrorReporter
 * Added more handled annotation constructs like array
 * Changed classes locations
    Visitors and Tree are in a dedicated package
 * Changed how argument are added to the Annotation class
 * Removed and ignored .tokens file as they are not needed
 * Completely refactored the visitors so they visit their children only
   when needed
 * Some classes have been moved to dedicated package in symfony.annotation project
 * This parser will receive a complete comment string and will parse
   every valid symfony annotation it can find.
 * Added model for source position and annotation token
 * Thoses tokens will be used to retrieve source positions
 * It can be populated using a single token
 * Or it can be populated using a start and end token
 * Now, every object of the model is considered as an IValue
 * This has been done to ensure every element of the model have a
   source position member
 * Renamed ArgumentValue interface to IArgumentValue
 * The new information is mainly used to gather the source position
   of the tokens
 * This parser is now adujsting the offset of line, column and indexes correctly
   (This means that source position have correct information about the
    position of the annotation relative to the source code)
 * The AnnotationToken is now adujested with correct offsets
 * Added more AnnotationCommentParser test
 * Renamed IValue to ISourceElement and Value to AnnotationSourceElement
   (This has been done to have better names)
 * Added two sub object to annotation: AnnotationClass and AnnotationDeclaration
   (This has been done to be able to visit those information using a coming model visitor)
 * Added a way to pass the comment offset relative to the php file
 * Added a way to set desired included namespaces
   (This is useful if you want only certain kinds of annotation classes)
 * This will improved annotations support in plugin
 * This will also reduce a lot of code
 * Directly changing the token fields is a bad idea. They seem to be used
   by the parser to do some internal stuff.
 * Now using our own field to adjust the token offsets.
 * Fixed a failing test also
 * Made some improvement for the annotation class and declaration source positions
 * This led to a problem with the grammar accepting spaces between the at
   sign, the namespace, the class name and the first parenthesis.
   (Will fix in an upcoming commit)
…nd the declaration

 * This means that this is valid "@Orm\Test()" but not this "@ Orm\Test()"
 * The annotation token was adding the offset to members when it was requested
   via the getToken() method. This was a bug since offset was added multiple
   times if the token was requested more than once.
 * These API has been removed in favor of the new way to work with Annotation,
   the Annotation model. Every old methods are now part of the Annotation
   class which can be requested from a visitor by doing visitor.getAnnotation()
 * Added a getArgument(int index) and hasArgument(int index)
 * Almost everything related to parsing has been placed in the AnnotationUtils class
 * The only thing missing is error reporting, but since it is comment in
   the ErrorReporter, I will fix this after the PR is merged
@pulse00
Copy link
Owner

pulse00 commented Feb 28, 2012

this is an awesome PR. thanks a lot for your contribution!

Concerning the error-reporting: I've commented this out because with the previous parser id it did not make any sense as it was too buggy. The error reporting is only useful if the parser is really 100% compliant with the one on the PHP side - which your PR brings us really close i think...

I'll push a new version of the plugin to the update site tomorrow.

pulse00 added a commit that referenced this pull request Feb 28, 2012
Rewrite of Annotation parser
@pulse00 pulse00 merged commit c2a3831 into pulse00:master Feb 28, 2012
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.

Bug on routes requirements
2 participants