antlr / grammars-v4

Grammars written for ANTLR v4; expectation that the grammars are free of actions.
MIT License
10.08k stars 3.68k forks source link

Objective C marco usage causes parsing error #1690

Open camelsiu opened 4 years ago

camelsiu commented 4 years ago

there is a tested code like below:


@implementation UINavigationItem (QMUINavigationButton)

QMUISynthesizeIdCopyProperty(tempLeftBarButtonItems, setTempLeftBarButtonItems)
QMUISynthesizeIdCopyProperty(tempRightBarButtonItems, setTempRightBarButtonItems)

+ (void)load {
    static dispatch_once_t onceToken;
}

@end

I use one-step parser, and the parser prints this error:

line 4:51 no viable alternative at input 'QMUISynthesizeIdCopyProperty(tempLeftBarButtonItems,' line 9:0 extraneous input '}' expecting {, 'auto', 'char', 'const', 'double', 'enum', 'extern', 'float', 'inline', 'int', 'long', 'register', 'restrict', 'short', 'signed', 'static', 'struct', 'typedef', 'union', 'unsigned', 'void', 'volatile', 'BOOL', 'Class', 'bycopy', 'byref', 'id', 'IMP', 'in', 'inout', 'oneway', 'out', 'Protocol', 'SEL', 'self', 'super', '@class', '@implementation', '@interface', '@import', '@protocol', 'atomic', 'nonatomic', 'retain', 'attribute', 'autoreleasing', 'block', 'bridge', 'bridge_retained', 'bridge_transfer', 'covariant', 'contravariant', 'deprecated', 'kindof', 'strong', TYPEOF, 'unsafe_unretained', 'unused', '__weak', NULL_UNSPECIFIED, NULLABLE, NONNULL, 'null_resettable', 'NS_INLINE', 'NS_ENUM', 'NS_OPTIONS', 'assign', 'copy', 'getter', 'setter', 'strong', 'readonly', 'readwrite', 'weak', 'unsafe_unretained', 'IBOutlet', 'IBOutletCollection', 'IBInspectable', 'IB_DESIGNABLE', IDENTIFIER}

It seems that the parser does not recognize the Macro feature. How do I fix this error?

Marti2203 commented 3 years ago

Hi, I would suggest customizing the grammar such that you have macro calls in a lot of places, which could be useful. Another thing is to have an error handler that deletes such tokens, but this means knowing when it is a macro call and not another issue. This is probably an old issue that can be closed probably but I am just looking around and trying to fix them.