1 # 2 # KDOM IDL parser 3 # 4 # Copyright (C) 2005 Nikolas Zimmermann <wildfox (at] kde.org> 5 # 6 # This library is free software; you can redistribute it and/or 7 # modify it under the terms of the GNU Library General Public 8 # License as published by the Free Software Foundation; either 9 # version 2 of the License, or (at your option) any later version. 10 # 11 # This library is distributed in the hope that it will be useful, 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 # Library General Public License for more details. 15 # 16 # You should have received a copy of the GNU Library General Public License 17 # along with this library; see the file COPYING.LIB. If not, write to 18 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 # Boston, MA 02110-1301, USA. 20 # 21 22 package IDLStructure; 23 24 use strict; 25 26 use Class::Struct; 27 28 # Used to represent a parsed IDL document 29 struct( idlDocument => { 30 module => '$', # Module identifier 31 classes => '@', # All parsed interfaces 32 fileName => '$' # file name 33 }); 34 35 # Used to represent 'interface' / 'exception' blocks 36 struct( domClass => { 37 name => '$', # Class identifier (without module) 38 parents => '@', # List of strings 39 constants => '@', # List of 'domConstant' 40 functions => '@', # List of 'domFunction' 41 attributes => '@', # List of 'domAttribute' 42 extendedAttributes => '$', # Extended attributes 43 }); 44 45 # Used to represent domClass contents (name of method, signature) 46 struct( domFunction => { 47 signature => '$', # Return type/Object name/extended attributes 48 parameters => '@', # List of 'domSignature' 49 raisesExceptions => '@', # Possibly raised exceptions. 50 }); 51 52 # Used to represent domClass contents (name of attribute, signature) 53 struct( domAttribute => { 54 type => '$', # Attribute type (including namespace) 55 signature => '$', # Attribute signature 56 getterExceptions => '@', # Possibly raised exceptions. 57 setterExceptions => '@', # Possibly raised exceptions. 58 }); 59 60 # Used to represent a map of 'variable name' <-> 'variable type' 61 struct( domSignature => { 62 direction => '$', # Variable direction (in or out) 63 name => '$', # Variable name 64 type => '$', # Variable type 65 extendedAttributes => '$' # Extended attributes 66 }); 67 68 # Used to represent string constants 69 struct( domConstant => { 70 name => '$', # DOM Constant identifier 71 type => '$', # Type of data 72 value => '$', # Constant value 73 }); 74 75 # Helpers 76 our $idlId = '[a-zA-Z0-9]'; # Generic identifier 77 our $idlIdNs = '[a-zA-Z0-9:]'; # Generic identifier including namespace 78 our $idlIdNsList = '[a-zA-Z0-9:,\ ]'; # List of Generic identifiers including namespace 79 80 our $idlType = '[a-zA-Z0-9_]'; # Generic type/"value string" identifier 81 # Match a string value, a hexadecimal number, or an integral number. 82 # Note: some of the characters that are allowed in the string value may not be allowed by 83 # interfaceSelector. 84 our $constValue = '("[^"\r\n]*")|(0[xX][a-fA-F0-9]+)|(-?[0-9]*)'; 85 our $idlDataType = '[a-zA-Z0-9\ ]'; # Generic data type identifier 86 87 # Magic IDL parsing regular expressions 88 my $supportedTypes = "((?:unsigned )?(?:int|short|(?:long )?long)|(?:$idlIdNs*))"; 89 90 # Special IDL notations 91 our $extendedAttributeSyntax = '\[[^]]*\]'; # Used for extended attributes 92 93 # Regular expression based IDL 'syntactical tokenizer' used in the IDLParser 94 our $moduleSelector = 'module\s*(' . $idlId . '*)\s*{'; 95 our $moduleNSSelector = 'module\s*(' . $idlId . '*)\s*\[ns\s*(' . $idlIdNs . '*)\s*(' . $idlIdNs . '*)\]\s*;'; 96 our $constantSelector = 'const\s*' . $supportedTypes . '\s*(' . $idlType . '*)\s*=\s*(' . $constValue . ')'; 97 our $raisesSelector = 'raises\s*\((' . $idlIdNsList . '*)\s*\)'; 98 our $getterRaisesSelector = '\bgetter\s+raises\s*\((' . $idlIdNsList . '*)\s*\)'; 99 our $setterRaisesSelector = '\bsetter\s+raises\s*\((' . $idlIdNsList . '*)\s*\)'; 100 101 our $typeNamespaceSelector = '((?:' . $idlId . '*::)*)\s*(' . $idlDataType . '*)'; 102 103 our $exceptionSelector = 'exception\s*(' . $idlIdNs . '*)\s*([a-zA-Z\s{;]*};)'; 104 our $exceptionSubSelector = '{\s*' . $supportedTypes . '\s*(' . $idlType . '*)\s*;\s*}'; 105 106 our $interfaceSelector = 'interface\s*((?:' . $extendedAttributeSyntax . ' )?)(' . $idlIdNs . '*)\s*(?::(\s*[^{]*))?{([-a-zA-Z0-9_"=\s(),;:\[\]&\|]*)'; 107 our $interfaceMethodSelector = '\s*((?:' . $extendedAttributeSyntax . ' )?)' . $supportedTypes . '\s*(' . $idlIdNs . '*)\s*\(\s*([a-zA-Z0-9:\s,=\[\]]*)'; 108 our $interfaceParameterSelector = '(in|out)\s*((?:' . $extendedAttributeSyntax . ' )?)' . $supportedTypes . '\s*(' . $idlIdNs . '*)'; 109 110 our $interfaceAttributeSelector = '\s*(readonly attribute|attribute)\s*(' . $extendedAttributeSyntax . ' )?' . $supportedTypes . '\s*(' . $idlType . '*)'; 111 112 1; 113