1# 2# KDOM IDL parser 3# 4# Copyright (C) 2005 Nikolas Zimmermann <wildfox@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# aint 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 22package IDLStructure; 23 24use Class::Struct; 25 26# Used to represent a parsed IDL document 27struct( idlDocument => { 28 module => '$', # Module identifier 29 classes => '@', # All parsed interfaces 30 fileName => '$' # file name 31}); 32 33# Used to represent 'interface' / 'exception' blocks 34struct( domClass => { 35 name => '$', # Class identifier (without module) 36 parents => '@', # List of strings 37 constants => '@', # List of 'domConstant' 38 functions => '@', # List of 'domFunction' 39 attributes => '@', # List of 'domAttribute' 40 extendedAttributes => '$', # Extended attributes 41}); 42 43# Used to represent domClass contents (name of method, signature) 44struct( domFunction => { 45 signature => '$', # Return type/Object name/extended attributes 46 parameters => '@', # List of 'domSignature' 47 raisesExceptions => '@', # Possibly raised exceptions. 48}); 49 50# Used to represent domClass contents (name of attribute, signature) 51struct( domAttribute => { 52 type => '$', # Attribute type (including namespace) 53 signature => '$', # Attribute signature 54 getterExceptions => '@', # Possibly raised exceptions. 55 setterExceptions => '@', # Possibly raised exceptions. 56}); 57 58# Used to represent a map of 'variable name' <-> 'variable type' 59struct( domSignature => { 60 name => '$', # Variable name 61 type => '$', # Variable type 62 extendedAttributes => '$' # Extended attributes 63}); 64 65# Used to represent string constants 66struct( domConstant => { 67 name => '$', # DOM Constant identifier 68 type => '$', # Type of data 69 value => '$', # Constant value 70}); 71 72# Helpers 73$idlId = '[a-zA-Z0-9]'; # Generic identifier 74$idlIdNs = '[a-zA-Z0-9:]'; # Generic identifier including namespace 75$idlIdNsList = '[a-zA-Z0-9:,\ ]'; # List of Generic identifiers including namespace 76 77$idlType = '[a-zA-Z0-9_]'; # Generic type/"value string" identifier 78$idlDataType = '[a-zA-Z0-9\ ]'; # Generic data type identifier 79 80# Magic IDL parsing regular expressions 81my $supportedTypes = "((?:unsigned )?(?:int|short|(?:long )?long)|(?:$idlIdNs*))"; 82 83# Special IDL notations 84$extendedAttributeSyntax = '\[[^]]*\]'; # Used for extended attributes 85 86# Regular expression based IDL 'syntactical tokenizer' used in the IDLParser 87$moduleSelector = 'module\s*(' . $idlId . '*)\s*{'; 88$moduleNSSelector = 'module\s*(' . $idlId . '*)\s*\[ns\s*(' . $idlIdNs . '*)\s*(' . $idlIdNs . '*)\]\s*;'; 89$constantSelector = 'const\s*' . $supportedTypes . '\s*(' . $idlType . '*)\s*=\s*(' . $idlType . '*)'; 90$raisesSelector = 'raises\s*\((' . $idlIdNsList . '*)\s*\)'; 91$getterRaisesSelector = '\bgetter\s+raises\s*\((' . $idlIdNsList . '*)\s*\)'; 92$setterRaisesSelector = '\bsetter\s+raises\s*\((' . $idlIdNsList . '*)\s*\)'; 93 94$typeNamespaceSelector = '((?:' . $idlId . '*::)*)\s*(' . $idlDataType . '*)'; 95 96$exceptionSelector = 'exception\s*(' . $idlIdNs . '*)\s*([a-zA-Z\s{;]*};)'; 97$exceptionSubSelector = '{\s*' . $supportedTypes . '\s*(' . $idlType . '*)\s*;\s*}'; 98 99$interfaceSelector = 'interface\s*((?:' . $extendedAttributeSyntax . ' )?)(' . $idlIdNs . '*)\s*(?::(\s*[^{]*))?{([a-zA-Z0-9_=\s(),;:\[\]]*)'; 100$interfaceMethodSelector = '\s*((?:' . $extendedAttributeSyntax . ' )?)' . $supportedTypes . '\s*(' . $idlIdNs . '*)\s*\(\s*([a-zA-Z0-9:\s,=\[\]]*)'; 101$interfaceParameterSelector = 'in\s*((?:' . $extendedAttributeSyntax . ' )?)' . $supportedTypes . '\s*(' . $idlIdNs . '*)'; 102 103$interfaceAttributeSelector = '\s*(readonly attribute|attribute)\s*(' . $extendedAttributeSyntax . ' )?' . $supportedTypes . '\s*(' . $idlType . '*)'; 104 1051; 106