Skip to content

LuizZak/ObjcGrammar

Repository files navigation

Summary

Objective-C 2.0 grammars with preprocessor support can be used in 2 different modes:

  • One-step processing. Includes a lexer which is used for both directives and ordinary Objective-C code. Used in Swiftify Objective-C to Swift converter.
  • Two-step processing. Includes separate lexers for directives and Objective-C code. Used in Codebeat, the web service for automated code review for different programming languages (including Objective-C).

One-step processing

  1. Lexer (ObjectiveCLexer.g4).
  2. Parser (ObjectiveCPreprocessorParser.g4 and ObjectiveCParser.g4).

Two-step processing

  1. Preprocessor lexer (ObjectiveCPreprocessorLexer.g4).
  2. Preprocessor parser (ObjectiveCPreprocessorLexer.g4).
  3. Visitor class for removing preprocessor directives from code (ObjectiveCPreprocessor.java).
  4. Lexer (ObjectiveCLexer.g4).
  5. Parser (ObjectiveCParser.g4).

ObjectiveCPreprocessor processes preprocessor directives and replaces code that does not compile with spaces. Spaces are kept for correct detection of error line and column numbers during parsing of the ordinary Objective-C code. ObjectiveCParser is shared by both one-step and two-step processing.

Testing

One-step processing

Successful parsing and conversion of complete projects, ex. Popovers demo.

Two-step processing

More than 95% correctly parsed .m files from these projects:

  1. AFNetworking
  2. realm-cocoa
  3. iOS-Source-Code-Analyze
  4. SDWebImage
  5. MJRefresh
  6. SmarterStreaming
  7. ReactiveCocoa
  8. GSKStretchyHeaderView
  9. JSQMessagesViewController
  10. SocketRocket
  11. MBProgressHUD
  12. DZNEmptyDataSet
  13. AsyncDisplayKit
  14. UITableView-FDTemplateLayoutCell3
  15. SDAutoLayout
  16. Chameleon
  17. TomatoRead
  18. iCarousel
  19. SVProgressHUD
  20. fmdb

License

ObjectiveC grammars and helper files are licensed under MIT.

About

Repository for latest Objective-C ANTLR4 grammar files used in SwiftRewriter; based off of existing grammar files from ANTLR's github pages.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published