settingsengines/sdb/group/RSS.g
changeset 1 b538b70cbe51
child 2 87cfa131b535
equal deleted inserted replaced
0:2e8eeb919028 1:b538b70cbe51
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // RSS.g
       
    15 //
       
    16 
       
    17 grammar RSS;
       
    18 options {backtrack=true; memoize=true;}
       
    19 
       
    20 @lexer::header {
       
    21 package com.symbian.sdb.resource;
       
    22 }
       
    23 
       
    24 @lexer::members {
       
    25   List<RecognitionException> exceptions = new ArrayList<RecognitionException>();
       
    26 
       
    27   public List<RecognitionException> getExceptions() {
       
    28     return exceptions;
       
    29 }
       
    30 
       
    31   @Override
       
    32   public void reportError(RecognitionException e) {
       
    33     super.reportError(e);
       
    34     exceptions.add(e);
       
    35   }
       
    36   
       
    37   @Override
       
    38   public void emitErrorMessage(String arg0) {
       
    39   }
       
    40 }
       
    41  
       
    42 @header {
       
    43 package com.symbian.sdb.resource;
       
    44 
       
    45 import java.util.HashMap;
       
    46 import java.util.HashSet;
       
    47 import java.util.LinkedHashMap;
       
    48 import java.util.Set;
       
    49 
       
    50 import com.symbian.sdb.contacts.template.Field;
       
    51 import com.symbian.sdb.contacts.template.FieldContainer;
       
    52 import com.symbian.sdb.contacts.template.Flag;
       
    53 }
       
    54 
       
    55 @members {
       
    56 
       
    57   List<RecognitionException> exceptions = new ArrayList<RecognitionException>();
       
    58 
       
    59   public List<RecognitionException> getExceptions() {
       
    60     return exceptions;
       
    61   }
       
    62 
       
    63   @Override
       
    64   public void reportError(RecognitionException e) {
       
    65     super.reportError(e);
       
    66     exceptions.add(e);
       
    67   }
       
    68   
       
    69   @Override
       
    70   public void emitErrorMessage(String arg0) {
       
    71   }
       
    72 
       
    73  	FieldContainer container = new FieldContainer();
       
    74     	Field field = new Field();
       
    75    
       
    76         // private Set<String> set = new HashSet<String>();
       
    77          private Integer index = 0;
       
    78          
       
    79          public void displayRecognitionError(){
       
    80          }
       
    81          
       
    82          public FieldContainer getContainer() {
       
    83              return container;
       
    84          }
       
    85                 
       
    86              // field type mapping         
       
    87              protected HashMap<String, String> fieldTypeMapping = new HashMap<String, String>();
       
    88              // mapping for category field      
       
    89              protected HashMap<String, String> categoryMapping = new HashMap<String, String>();    
       
    90              // mapping for storage field      
       
    91              protected HashMap<String, String> storageMapping = new HashMap<String, String>();    
       
    92              // mapping for flag field
       
    93              protected HashMap<String, String> flagMapping = new HashMap<String, String>();    
       
    94      
       
    95              public void setFieldTypeMapping(HashMap<String, String> m)  {
       
    96                  fieldTypeMapping = m;
       
    97              }         
       
    98                       
       
    99              public void setCategoryMapping(HashMap<String, String> m)  {
       
   100                  categoryMapping = m;
       
   101              }
       
   102              
       
   103              public void setStorageMapping(HashMap<String, String> m)  {
       
   104                  storageMapping = m;
       
   105              }     
       
   106                       
       
   107              public void setFlagMapping(HashMap<String, String> m)  {
       
   108                  flagMapping = m;
       
   109              } 
       
   110          
       
   111          
       
   112          // private methods 
       
   113          private String resolveMapping(String value, HashMap<String, String> map) {
       
   114         	 String resolved = map.get(value);
       
   115         	 if (resolved != null) {
       
   116         		 return resolved;
       
   117         	 }	else {
       
   118         		 return value;
       
   119         	 }
       
   120          }
       
   121 }
       
   122 
       
   123 
       
   124 document 
       
   125 	:	( defineDeclaration | resourceDeclaration )*;
       
   126 
       
   127 defineDeclaration
       
   128 	:	'#define' Identifier literal { 
       
   129 	//TODO add this to the field mapping thing?
       
   130 	};
       
   131 
       
   132 literal :	 (HexLiteral | DecimalLiteral)?;
       
   133 	
       
   134 resourceDeclaration
       
   135 	:	'RESOURCE' (arrayDeclaration | rssDeclaration);
       
   136 	
       
   137 rssDeclaration
       
   138 	:	'RSS_SIGNATURE' '{' '}' 	;	
       
   139 	
       
   140 arrayDeclaration
       
   141 	:	'ARRAY' 'r_cntui_new_field_defns' '{' itemsDeclaration ';' '}' ;
       
   142 	
       
   143 itemsDeclaration
       
   144 	:	'items' '=' '{' ( options {greedy=false;} : fieldDeclaration* ) '}'  { };
       
   145 
       
   146 fieldDeclaration
       
   147 	:	'FIELD' ( '{' fields* '}' ','? )* { 
       
   148 
       
   149             		field.setIndex(index);
       
   150               		index++;
       
   151               	     
       
   152               	     	container.add(field.getVCardMapping(), field);
       
   153               	     	field = new Field();  		
       
   154 	}	;
       
   155 	
       
   156 fields	:	(flags | category | fieldStorageType | contactFieldType | vCardMappingField | extraMapping | fieldName | other ) ';' ;
       
   157 
       
   158 
       
   159 fieldsdef 
       
   160 	:	Identifier ( '|' fieldsdef )* { 
       
   161 		//set.add($Identifier.text); 
       
   162 		};
       
   163 		
       
   164 other 	:	Identifier '=' fieldsdef	{  
       
   165 		//addSetFieldMember($Identifier.text);
       
   166 		} ;
       
   167 
       
   168 flags	:	'flags' '=' flagsdef {
       
   169 		//addSetFieldMember("flags");		
       
   170 		};
       
   171 
       
   172 flagsdef 
       
   173 	:	Identifier ( '|' flagsdef )* { 		
       
   174 	        String value = $Identifier.text;
       
   175                         String flag = resolveMapping(value, flagMapping);
       
   176                             	
       
   177             			int result;
       
   178             			if (flag.startsWith("0x")) {
       
   179             				result = Integer.parseInt(flag.replace("0x", ""), 16);
       
   180             			} else {
       
   181             				result = Integer.parseInt(flag);
       
   182             			}
       
   183             			Flag f = new Flag(value, result);
       
   184                     	
       
   185                     	field.addFlag(f);
       
   186 		};
       
   187 
       
   188 extraMapping
       
   189 	:	'extraMapping' '=' '{' ( mapping )* '}'  {  
       
   190 		//addSetFieldMember("extraMapping");
       
   191 	}  ;
       
   192 	
       
   193 mapping	:	'MAPPING' '{' 'mapping' '=' Identifier ';' '}' ','? {
       
   194               		String value = $Identifier.text; 
       
   195               		field.addProperty(value);
       
   196 	};
       
   197 
       
   198 category
       
   199 	:	'category' '=' Identifier {
       
   200 		String value =  $Identifier.text;
       
   201               	String category = resolveMapping(value, categoryMapping);	
       
   202               	field.setCategory(category);
       
   203 		};
       
   204 
       
   205 contactFieldType
       
   206 	:	'contactFieldType' '=' Identifier {  
       
   207 		String value =  $Identifier.text;
       
   208               	field.setFieldType(value);
       
   209 		}	; 
       
   210 
       
   211 fieldStorageType
       
   212 	:	'fieldStorageType' '=' Identifier {
       
   213 		//storageMapping
       
   214 		 String value = $Identifier.text;
       
   215               	 String storage = resolveMapping(value, storageMapping);
       
   216               	 field.setStorageType(storage);
       
   217 		} ;
       
   218 
       
   219 vCardMappingField
       
   220 	:	'vCardMapping' '=' Identifier  { 
       
   221               		String value = $Identifier.text;
       
   222 			field.setVCardMapping(value);       
       
   223 		};
       
   224 
       
   225 fieldName
       
   226 	:	'fieldName' '=' Identifier  { 
       
   227               		String value = $Identifier.text;
       
   228 			field.setFieldName(value);      
       
   229 		};
       
   230 
       
   231 
       
   232 // LEXER
       
   233 
       
   234 
       
   235 HexLiteral : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;
       
   236 
       
   237 DecimalLiteral : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
       
   238 
       
   239 fragment
       
   240 HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;
       
   241 
       
   242 fragment
       
   243 IntegerTypeSuffix : ('l'|'L') ;
       
   244 
       
   245 Identifier 
       
   246     :   Letter (Letter|JavaIDDigit)*
       
   247     ;
       
   248 
       
   249 fragment
       
   250 Letter
       
   251     :  '\u0024' |
       
   252        '\u0041'..'\u005a' |
       
   253        '\u005f' |
       
   254        '\u0061'..'\u007a' |
       
   255        '\u00c0'..'\u00d6' |
       
   256        '\u00d8'..'\u00f6' |
       
   257        '\u00f8'..'\u00ff' |
       
   258        '\u0100'..'\u1fff' |
       
   259        '\u3040'..'\u318f' |
       
   260        '\u3300'..'\u337f' |
       
   261        '\u3400'..'\u3d2d' |
       
   262        '\u4e00'..'\u9fff' |
       
   263        '\uf900'..'\ufaff'
       
   264     ;
       
   265 
       
   266 fragment
       
   267 JavaIDDigit
       
   268     :  '\u0030'..'\u0039' |
       
   269        '\u0660'..'\u0669' |
       
   270        '\u06f0'..'\u06f9' |
       
   271        '\u0966'..'\u096f' |
       
   272        '\u09e6'..'\u09ef' |
       
   273        '\u0a66'..'\u0a6f' |
       
   274        '\u0ae6'..'\u0aef' |
       
   275        '\u0b66'..'\u0b6f' |
       
   276        '\u0be7'..'\u0bef' |
       
   277        '\u0c66'..'\u0c6f' |
       
   278        '\u0ce6'..'\u0cef' |
       
   279        '\u0d66'..'\u0d6f' |
       
   280        '\u0e50'..'\u0e59' |
       
   281        '\u0ed0'..'\u0ed9' |
       
   282        '\u1040'..'\u1049'
       
   283    ;
       
   284 
       
   285 WS  :  (' '|'\r'|'\t'|'\u000C'|'\n') {$channel=HIDDEN;}
       
   286     ;
       
   287 
       
   288 COMMENT
       
   289     :   '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;} ;
       
   290 
       
   291 LINE_COMMENT
       
   292     : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;} ;
       
   293     
       
   294 INCLUDE 
       
   295 	: '#include' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;} ;
       
   296 
       
   297 STRUCT	:	'STRUCT' ( options {greedy=false;} : . )* '}' {$channel=HIDDEN;} ;	
       
   298 
       
   299 IF_STM
       
   300     : '#if' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;} ;
       
   301     
       
   302 ENDIF_STM
       
   303     : '#endif' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;} ;
       
   304     
       
   305     
       
   306