Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
net.sourceforge.pmd.lang.objectivec.ast.ObjectiveC.jj Maven / Gradle / Ivy
/**
* This Objective-C grammar was copied and adapted from the Objective-C-CPD-Language Github project. (https://github.com/jkennedy1980/Objective-C-CPD-Language)
*
* Original author:
* @author Michael Hall - Based on Parnel SableCC ObjectiveC grammar and javacc C grammar
*
* Original source file:
* https://github.com/jkennedy1980/Objective-C-CPD-Language/blob/master/src/main/javacc/ObjC2.0.jj (commit 5b07b5cc424522e435929bbff7589c690100edf6)
*/
options {
JAVA_UNICODE_ESCAPE = true;
BUILD_PARSER=false;
CACHE_TOKENS=true;
STATIC=false;
}
PARSER_BEGIN(ObjectiveCParserImpl)
package net.sourceforge.pmd.lang.objectivec.ast;
import java.io.*;
import java.util.*;
import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream;
import net.sourceforge.pmd.lang.ast.TokenMgrError;
/**
* Grammar to parse ObjectiveC 2.0
* @author Michael Hall - Based on Parnel SableCC ObjectiveC grammar and javacc C grammar
*
* Josh Kennedy - added CSTRING_LITERAL so parser doesn't die on CStrings.
* Paul Taykalo - added support for 0x literals, @compatibility_alias, and the $ character identifier
* Paul Taykalo - vertical tab (\v) and alert (\a) characters are added
*/
public class ObjectiveCParserImpl {}
PARSER_END(ObjectiveCParserImpl)
SKIP : {
" "
| "\t"
| "\n"
| "\r"
| "\f"
| "\\\n" /* Special issue for long strings concatenation */
| "\\\r\n" /* Special issue for long strings concatenation */
| "__weak"
| "__strong"
| "__attribute__"
| "__objc_exception__"
| "#" : PREPROCESSOR_OUTPUT
| "extern \"C\" {"
| "CF_EXPORT"
| "CF_INLINE"
| "CF_EXTERN_C_BEGIN"
| "CF_EXTERN_C_END"
| "CA_EXTERN_C_BEGIN"
| "CA_EXTERN_C_END"
| "CA_EXTERN"
| "CA_DEPRECATED"
| "COREDATA_EXTERN"
| "NS_INLINE"
| "APPKIT_EXTERN"
| "FOUNDATION_EXPORT" : PREPROCESSOR_OUTPUT /* mjh - Cocoa specific not currently of interest, ignore like preprocessor stuff */
| "DEPRECATED_IN_MAC_OS_X_VERSION_10_0_AND_LATER" /* mjh - not currently of interest */
| "DEPRECATED_IN_MAC_OS_X_VERSION_10_1_AND_LATER" /* mjh - not currently of interest */
| "DEPRECATED_IN_MAC_OS_X_VERSION_10_2_AND_LATER" /* mjh - not currently of interest */
| "DEPRECATED_IN_MAC_OS_X_VERSION_10_3_AND_LATER" /* mjh - not currently of interest */
| "DEPRECATED_IN_MAC_OS_X_VERSION_10_4_AND_LATER" /* mjh - not currently of interest */
| "DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER" /* mjh - not currently of interest */
| "DEPRECATED_IN_MAC_OS_X_VERSION_10_6_AND_LATER" /* mjh - not currently of interest */
| "AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER" /* mjh - not currently of interest */
| "AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER" /* mjh - not currently of interest */
| "AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER" /* mjh - not currently of interest */
| "AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER" /* mjh - not currently of interest */
| "AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER" /* mjh - not currently of interest */
| "AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER" /* mjh - not currently of interest */
| "AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER" /* mjh - not currently of interest */
| "AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER_BUT_DEPRECATED" /* mjh - not currently of interest */
| "AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_6"
| "AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4"
| "AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4"
| "AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5"
| "AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5"
| "AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4"
| "AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5"
| "AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5"
| "AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_6"
| "AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0"
| "AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0"
| "AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER" /* mjh - not currently of interest */
| "AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED" /* mjh - not currently of interest */
| "AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER_BUT_DEPRECATED" /* mjh - not currently of interest */
| "AVAILABLE_IN_WEBKIT_VERSION_4_0" /* mjh - not currently of interest */
| "NP_LOADDS" /* mjh - not currently of interest */
| "NS_REQUIRES_NIL_TERMINATION"
| "UNAVAILABLE_ATTRIBUTE"
| <"," "NS_NONATOMIC_IPHONEONLY"> /* mjh - not currently of interest */
| "NS_FORMAT_FUNCTION" : FORMAT_FUNC
| "CF_FORMAT_ARGUMENT" : FORMAT_FUNC
| "__OSX_AVAILABLE_STARTING" : FORMAT_FUNC /* mjh - same sort of thing */
| "WEBKIT_OBJC_METHOD_ANNOTATION" : FORMAT_FUNC /* mjh - same sort of thing */
| "(void (^)" : VOID_BLOCK
}
/* mjh - we try to just ignore the parameter list */
SKIP :
{
"))" : DEFAULT
}
MORE:
{
< ~[")"] >
}
SKIP:
{
"\n" : DEFAULT
}
MORE:
{
"\\\n"
|
"\\\r\n"
|
< ~[] >
}
/* mjh - we try to just ignore the "(" whatever ")" */
SKIP :
{
")" : DEFAULT
}
SPECIAL_TOKEN :
{
}
MORE :
{
"\\\n"
|
"\\\r\n"
|
< ~[")"] >
}
/* COMMENTS */
MORE :
{
"/*" : IN_MULTI_LINE_COMMENT
}
SPECIAL_TOKEN :
{
}
SPECIAL_TOKEN :
{
: DEFAULT
}
MORE :
{
< ~[] >
}
/* OPERATORS */
TOKEN :
{
< ASSIGN: "=" >
| < LT: "<" >
| < GT: ">" >
| < BANG: "!" >
| < TILDE: "~" >
| < HOOK: "?" >
| < COLON: ":" >
| < EQ: "==" >
| < LE: "<=" >
| < GE: ">=" >
| < NE: "!=" >
| < SC_OR: "||" >
| < SC_AND: "&&" >
| < INCR: "++" >
| < DECR: "--" >
| < PLUS: "+" >
| < MINUS: "-" >
| < STAR: "*" >
| < SLASH: "/" >
| < BIT_AND: "&" >
| < BIT_OR: "|" >
| < XOR: "^" >
| < REM: "%" >
| < LSHIFT: "<<" >
| < PLUSASSIGN: "+=" >
| < MINUSASSIGN: "-=" >
| < STARASSIGN: "*=" >
| < SLASHASSIGN: "/=" >
| < ANDASSIGN: "&=" >
| < ORASSIGN: "|=" >
| < XORASSIGN: "^=" >
| < REMASSIGN: "%=" >
| < LSHIFTASSIGN: "<<=" >
| < RSIGNEDSHIFTASSIGN: ">>=" >
| < RUNSIGNEDSHIFTASSIGN: ">>>=" >
| < ELLIPSIS: "..." >
}
TOKEN :
{
< ESCAPE_SEQUENCE :
"\\" ["'","\"","?","\\","a","b","f","n","r","t","v"] /* SIMPLE_ESCAPE_SEQUENCE */
| "\\" ( ()?)? /* OCTAL_ESCAPE_SEQUENCE */
| "\\" "x" ()+ /* HEX_ESCAPE_SEQUENCE */
>
}
TOKEN : {
(["l","L"] | ("ul" | "UL") )? | (["l","L","U"])? | (["l","L"])?>
| <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* | (["0"])+>
| <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+>
| <#OCTAL_LITERAL: "0" (["0"-"7"])*>
| )? (["f","F","d","D"])? | "." (["0"-"9"])+ ()? (["f","F","d","D"])? | (["0"-"9"])+ (["f","F","d","D"])? | (["0"-"9"])+ ()? ["f","F","d","D"]>
| <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+>
|
|
|
}
TOKEN :
{
< DIGIT: ["0"-"9"] >
|
< NONZERO_DIGIT : ["1"-"9"] >
|
< OCTAL_DIGIT : ["1"-"7"] >
|
< #HEX_DIGIT : | ["a"-"f"] | ["A"-"F"] >
|
< #HEX_QUAD : >
|
< #UNSIGNED_SUFFIX : ["u","U"] | ("UL" | "ul") >
|
< #LONG_SUFFIX : ["l","L"] | ("LL" | "ll") >
|
< #INTEGER_SUFFIX : ()? | ()? >
|
< DECIMAL_CONSTANT : ()* >
|
< OCTAL_CONSTANT : "0" | >
|
< HEX_PREFIX : "0" ["x","X"] >
|
< HEX_CONSTANT : ()+ >
}
TOKEN :
{
< INTEGER_CONSTANT :
()?
| ()?
| ()?
>
}
TOKEN : {
}
TOKEN : {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
TOKEN : {
|
|
|
|
|
|
}
/* mjh - see ProtocolQualifier
TOKEN :
{
}
*/
TOKEN :
{
}
TOKEN :
{
|
|
|
|
|
|
}
TOKEN :
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
TOKEN :
{
|
|
|
|
}
TOKEN : {
| "_")*>
| | "_")*>
}
TOKEN : { }
TOKEN :
{
< IDENT : ( | )* >
| <#IDENT_NONDIGIT : | > // "may include other implementation-defined characters"
| <#NONDIGIT : ["a"-"z"] | ["A"-"Z"] | "_" | "$" | >
| <#NONDIGIT_UNICODE : [ /* source: http://stackoverflow.com/questions/30933785 */
"\u0024",
"\u0041"-"\u005a",
"\u005f",
"\u0061"-"\u007a",
"\u00c0"-"\u00d6",
"\u00d8"-"\u00f6",
"\u00f8"-"\u00ff",
"\u0100"-"\u1fff"
] >
| <#UNIVERSAL_CHARACTER_NAME : ("\\u" ) | ("\\U" ) >
}
TOKEN : { }
/***********************************************
* THE OBJECTIVEC LANGUAGE GRAMMAR STARTS HERE *
***********************************************/
void TranslationUnit() : {}
{
(ExternalDeclaration())+
}
void ExternalDeclaration() : {}
{
( LOOKAHEAD( FunctionDefinition() ) FunctionDefinition()
| LOOKAHEAD(3) StrippedParens() /* mjh if we skip all but parens for something like __attribute__((__objc_exception__)) */
| Declaration()
| LOOKAHEAD(3) ClassInterface()
| LOOKAHEAD(3) ClassImplementation()
| CategoryInterface()
| CategoryImplementation()
| ProtocolDeclaration()
| ClassDeclarationList() )
}
void StrippedParens() : {} /* See ExternalDeclaration above */
{
[ StrippedParens() ]
}
void FunctionDefinition() : {}
{
[LOOKAHEAD(DeclarationSpecifiers()) DeclarationSpecifiers()] Declarator() [ DeclarationList() ]
CompoundStatement()
}
void Declaration() : {}
{
DeclarationSpecifiers() [ InitDeclaratorList() ] [ "(" ParameterTypeList() ")" "(" ParameterTypeList() ")" ] /* ugly hack for single header typedef */ ";"
}
void ClassInterface() : {}
{
ClassName() (ColonSuperClassName())? (ProtocolReferenceList())?
[ LOOKAHEAD(2) ["{"] ClassName() (ColonSuperClassName())? (ProtocolReferenceList())? ] /* dup for preprocessor #else */
(InstanceVariables())? (InterfaceDeclaration())*
}
void ClassImplementation() : {}
{
ClassName() (LOOKAHEAD(2) ColonSuperClassName())? (InstanceVariables())? (ImplementationDefinition())*
}
void CategoryInterface() : {}
{
ClassName() (CategoryName())? (ProtocolReferenceList())? (InterfaceDeclaration())*
}
void CategoryImplementation() : {}
{
ClassName() CategoryName() (ImplementationDefinition())*
}
void ProtocolDeclaration() : {}
{
ProtocolList() (ProtocolReferenceList())? ProtocolInterfaceDeclaration() ( | ";" )
}
void ClassDeclarationList() : {}
{
ClassList() ";"
}
void ClassList() : {}
{
ClassName() ["," ClassList()]
}
void ProtocolReferenceList() : {}
{
ProtocolList() [ ProtocolList() /* if preproc #else, see AppKit NSWindow */ ]
}
void ProtocolList() : {}
{
ProtocolName() ["," ProtocolList()]
}
net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken ObjCIDENT() : { net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken t; }
{
t = { return t; } | t = { return t; } | t = { return t; }
}
void ClassName() : {}
{
ObjCIDENT()
}
void SuperClassName() : {}
{
ObjCIDENT()
}
void ColonSuperClassName() : {}
{
SuperClassName()
}
void CategoryName() : {}
{
| |
}
void ProtocolName() : {}
{
| |
}
void InstanceVariables() : {}
{
(InstanceVariableDeclaration())* [ ";" ]
}
void InstanceVariableDeclaration() : {}
{
VisibilitySpecification()
| LOOKAHEAD(3) InstanceVariableDeclarator()
| StructDeclaration()
}
void InstanceVariableDeclarator() : {}
{
( LOOKAHEAD(3) [ IBOutlet() ]
(LOOKAHEAD(2) ClassName() "*" | [ ProtocolReferenceList() ]) ";"
| Declaration() )
}
void VisibilitySpecification() : {}
{
[ ";" ]
|
|
|
}
void IBOutlet() : {} /* mjh */
{
}
void ProtocolInterfaceDeclaration() : {}
{
(InterfaceDeclaration())* (QualifiedProtocolInterfaceDeclaration())*
}
void QualifiedProtocolInterfaceDeclaration() : {}
{
(InterfaceDeclaration())*
| (InterfaceDeclaration())*
}
void InterfaceDeclaration() : {}
{
Declaration()
| PropertyDeclaration()
| MethodDeclaration()
}
void PropertyDeclaration() : {}
{
(PropertyAttributesDeclaration())? ( LOOKAHEAD(3) StructDeclaration() | (ProtocolReferenceList())? ";" )
}
void PropertyAttributesDeclaration() : {}
{
PropertyAttributesList()
}
void PropertyAttributesList() : {}
{
PropertyAttribute() ["," PropertyAttributesList()]
}
void PropertyAttribute() : {}
{
LOOKAHEAD(3) /* prop */ [ ] // setter
// | LOOKAHEAD(2) /* getter or ivar */ // getter ivar
| // nonatomic, readwrite, readonly, retain, assign, copy
| /* NS_NONATOMIC_IPHONEONLY */
}
void MethodDeclaration() : {}
{
ClassMethodDeclaration()
| InstanceMethodDeclaration()
}
void ClassMethodDeclaration() : {}
{
(MethodType())? MethodSelector()
}
void InstanceMethodDeclaration() : {}
{
(MethodType())? MethodSelector()
}
void ImplementationDefinition() : {}
{
( LOOKAHEAD( FunctionDefinition() ) FunctionDefinition()
| Declaration()
| PropertyImplementation()
| MethodDefinition() )
}
void PropertyImplementation() : {}
{
PropertySynthesizeList()
| PropertySynthesizeList()
}
void PropertySynthesizeList() : {}
{
PropertySynthesizeItem() ["," PropertySynthesizeList()]
/*
PropertySynthesizeList() "," PropertySynthesizeItem()
| PropertySynthesizeItem()
*/
}
void PropertySynthesizeItem() : {}
{
LOOKAHEAD(2)
|
}
void MethodDefinition() : {}
{
ClassMethodDefinition()
| InstanceMethodDefinition()
}
void ClassMethodDefinition() : {}
{
(MethodType())? MethodSelectorNoList() (Declaration())* ()? CompoundStatement()
}
void InstanceMethodDefinition() : {}
{
(MethodType())? MethodSelectorNoList() (Declaration())* ()? CompoundStatement()
}
void MethodSelectorNoList() : {}
{
LOOKAHEAD(3) KeywordSelector() [LOOKAHEAD(2) (",..." | "," "...")]
| UnarySelector()
}
void MethodSelector() : {}
{
LOOKAHEAD(3) MethodSelectorNoList()
| KeywordSelector() "," ParameterTypeList() // this is correct according to objcbook, but causes conflict if followed by declaration*
}
void UnarySelector() : {}
{
Selector()
}
void KeywordSelector() : {}
{
(LOOKAHEAD(2) KeywordDeclarator())+
}
void KeywordDeclarator() : {}
{
(Selector())? (MethodType())?
}
void Selector() : {}
{
}
void MethodType() : {}
{
(LOOKAHEAD(3) Block() | TypeNameWithUnknownType())
}
void SelectorExpression() : {}
{
SelectorName()
}
void SelectorName() : {}
{
LOOKAHEAD(2) Selector()
| (KeywordName())+
}
void KeywordName() : {}
{
(Selector())?
}
void ProtocolExpression() : {}
{
ProtocolName()
}
void EncodeExpression() : {}
{
TypeNameWithUnknownType()
}
void DeclarationList() : {}
{
( LOOKAHEAD(Declaration()) Declaration() )+
}
void DeclarationSpecifiers() : {}
{
/**
* We enumerate the possibilities (closure?) like SpecifierQualifierList
* instead of the standard C grammar recursive definition
* Although more complex it might actually end up cleaner?
* (For one thing you don't keep recursively matching types
* in TypeSpecifier(), this can muddle things or require semantic lookahead
* workarounds, see the sample javacc C implementation of this nonterminal)
*
* Assumes none actually should be duplicated
*/
LOOKAHEAD(3) TypeSpecifier() [ StorageClassSpecifier() ] [ TypeQualifier() ]
| TypeSpecifier() [ TypeQualifier() ] [ StorageClassSpecifier() ]
| LOOKAHEAD(3) StorageClassSpecifier() [ TypeQualifier() ] [ LOOKAHEAD(2) TypeSpecifier() ]
| LOOKAHEAD(3) StorageClassSpecifier() [ LOOKAHEAD(2) TypeSpecifier() ] [ TypeQualifier() ]
| LOOKAHEAD(3) TypeQualifier() [ StorageClassSpecifier() ] [ LOOKAHEAD(2) TypeSpecifier() ]
| LOOKAHEAD(2) TypeQualifier() [ LOOKAHEAD(2) TypeSpecifier() ] [ StorageClassSpecifier() ]
}
void StorageClassSpecifier() : {}
{
( | | | |
{
typedefParsingStack.push(Boolean.TRUE);
} )
}
void TypeSpecifier() : {}
{
( GreedyFixedNumType() | | | | | |
/* mjh - same as void */ | | /* Cocoa additions */
|
| | | | | |