File indexing completed on 2024-05-12 15:37:28
0001 # 0002 # KDOM IDL parser 0003 # 0004 # Copyright (C) 2005 Nikolas Zimmermann <wildfox@kde.org> 0005 # 0006 # This file is part of the KDE project 0007 # 0008 # This library is free software; you can redistribute it and/or 0009 # modify it under the terms of the GNU Library General Public 0010 # License as published by the Free Software Foundation; either 0011 # version 2 of the License, or (at your option) any later version. 0012 # 0013 # This library is distributed in the hope that it will be useful, 0014 # but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 # Library General Public License for more details. 0017 # 0018 # You should have received a copy of the GNU Library General Public License 0019 # aint with this library; see the file COPYING.LIB. If not, write to 0020 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 # Boston, MA 02110-1301, USA. 0022 # 0023 0024 package IDLStructure; 0025 0026 use Class::Struct; 0027 0028 # Used to represent a parsed IDL document 0029 struct( idlDocument => { 0030 module => '$', # Module identifier 0031 classes => '@', # All parsed interfaces 0032 fileName => '$' # file name 0033 }); 0034 0035 # Used to represent 'interface' / 'exception' blocks 0036 struct( domClass => { 0037 name => '$', # Class identifier (without module) 0038 parents => '@', # List of strings 0039 constants => '@', # List of 'domConstant' 0040 functions => '@', # List of 'domFunction' 0041 attributes => '@', # List of 'domAttribute' 0042 extendedAttributes => '$', # Extended attributes 0043 }); 0044 0045 # Used to represent domClass contents (name of method, signature) 0046 struct( domFunction => { 0047 signature => '$', # Return type/Object name/extended attributes 0048 parameters => '@', # List of 'domSignature' 0049 raisesExceptions => '@', # Possibly raised exceptions. 0050 }); 0051 0052 # Used to represent domClass contents (name of attribute, signature) 0053 struct( domAttribute => { 0054 type => '$', # Attribute type (including namespace) 0055 signature => '$', # Attribute signature 0056 getterExceptions => '@', # Possibly raised exceptions. 0057 setterExceptions => '@', # Possibly raised exceptions. 0058 }); 0059 0060 # Used to represent a map of 'variable name' <-> 'variable type' 0061 struct( domSignature => { 0062 name => '$', # Variable name 0063 type => '$', # Variable type 0064 extendedAttributes => '$' # Extended attributes 0065 }); 0066 0067 # Used to represent string constants 0068 struct( domConstant => { 0069 name => '$', # DOM Constant identifier 0070 type => '$', # Type of data 0071 value => '$', # Constant value 0072 }); 0073 0074 # Helpers 0075 $idlId = '[a-zA-Z0-9]'; # Generic identifier 0076 $idlIdNs = '[a-zA-Z0-9:]'; # Generic identifier including namespace 0077 $idlIdNsList = '[a-zA-Z0-9:,\ ]'; # List of Generic identifiers including namespace 0078 0079 $idlType = '[a-zA-Z0-9_]'; # Generic type/"value string" identifier 0080 $idlDataType = '[a-zA-Z0-9\ ]'; # Generic data type identifier 0081 0082 # Magic IDL parsing regular expressions 0083 my $supportedTypes = "((?:unsigned )?(?:int|short|long)|(?:$idlIdNs*))"; 0084 0085 # Special IDL notations 0086 $extendedAttributeSyntax = '\[[^]]*\]'; # Used for extended attributes 0087 0088 # Regular expression based IDL 'syntactical tokenizer' used in the IDLParser 0089 $moduleSelector = 'module\s*(' . $idlId . '*)\s*{'; 0090 $moduleNSSelector = 'module\s*(' . $idlId . '*)\s*\[ns\s*(' . $idlIdNs . '*)\s*(' . $idlIdNs . '*)\]\s*;'; 0091 $constantSelector = 'const\s*' . $supportedTypes . '\s*(' . $idlType . '*)\s*=\s*(' . $idlType . '*)'; 0092 $raisesSelector = 'raises\s*\((' . $idlIdNsList . '*)\s*\)'; 0093 $getterRaisesSelector = '\bgetter\s+raises\s*\((' . $idlIdNsList . '*)\s*\)'; 0094 $setterRaisesSelector = '\bsetter\s+raises\s*\((' . $idlIdNsList . '*)\s*\)'; 0095 0096 $typeNamespaceSelector = '((?:' . $idlId . '*::)*)\s*(' . $idlDataType . '*)'; 0097 0098 $exceptionSelector = 'exception\s*(' . $idlIdNs . '*)\s*([a-zA-Z\s{;]*};)'; 0099 $exceptionSubSelector = '{\s*' . $supportedTypes . '\s*(' . $idlType . '*)\s*;\s*}'; 0100 0101 $interfaceSelector = 'interface\s*((?:' . $extendedAttributeSyntax . ' )?)(' . $idlIdNs . '*)\s*(?::(\s*[^{]*))?{([a-zA-Z0-9_=\s(),;:\[\]]*)'; 0102 $interfaceMethodSelector = '\s*((?:' . $extendedAttributeSyntax . ' )?)' . $supportedTypes . '\s*(' . $idlIdNs . '*)\s*\(\s*([a-zA-Z0-9:\s,=\[\]]*)'; 0103 $interfaceParameterSelector = 'in\s*((?:' . $extendedAttributeSyntax . ' )?)' . $supportedTypes . '\s*(' . $idlIdNs . '*)'; 0104 0105 $interfaceAttributeSelector = '\s*(readonly attribute|attribute)\s*(' . $extendedAttributeSyntax . ' )?' . $supportedTypes . '\s*(' . $idlType . '*)'; 0106 0107 1;