#include <iostream>
#include <limits>
#include <list>
#include <sstream>

#include <osmscout/TypeConfig.h>

#include <osmscout/util/String.h>

COMPILER OSS

typedef std::list<FillStyleRef>   FillStyleList;
typedef std::list<IconStyleRef>   IconStyleList;
typedef std::list<LabelStyleRef>  LabelStyleList;
typedef std::list<LineStyleRef>   LineStyleList;
typedef std::list<SymbolStyleRef> SymbolStyleList;

inline std::string Destring(const char* str)
{
  std::string result(str);

  if (result.length()>=2 &&
      result[0]=='"' &&
      result[result.length()-1]=='"') {
    result=result.substr(1,result.length()-2);
  }

  return result;
}

inline bool StringToDouble(const char* string, double& value)
{
  std::istringstream buffer(string);

  buffer.imbue(std::locale::classic());

  buffer >> value;

  return !buffer.fail() && !buffer.bad() && buffer.eof();
}

inline size_t GetHexDigitValue(char c)
{
  if (c>='0' && c<='9') {
    return c-'0';
  }
  else if (c>='a' && c<='f') {
    return 10+(c-'a');
  }

  assert(false);
}

inline void ToRGBA(const char* str, Color& color)
{
  double r=(16*GetHexDigitValue(str[1])+GetHexDigitValue(str[2]))/255.0;
  double g=(16*GetHexDigitValue(str[3])+GetHexDigitValue(str[4]))/255.0;
  double b=(16*GetHexDigitValue(str[5])+GetHexDigitValue(str[6]))/255.0;
  double a;

  if (strlen(str)==9) {
    a=(16*GetHexDigitValue(str[7])+GetHexDigitValue(str[8]))/255.0;
  }
  else {
    a=1.0;
  }
  
  color=Color(r,g,b,a);
}

CHARACTERS
  letter     = 'a'..'z' + 'A'..'Z'.
  digit      = '0'..'9'.
  hexdigit   = 'a'..'f' + '0'..'9'.
  eol        = '\n'.
  stringchar = ANY - '"'.
  quotchar   = ANY.

TOKENS
  ident      = letter {letter | '_'}.
  number     = ['-'] digit {digit}.
  double     = ['-'] digit {digit} '.' digit {digit}.
  color      = "#" hexdigit hexdigit hexdigit hexdigit hexdigit hexdigit [hexdigit hexdigit].
  string     = '"' {stringchar | '\\' quotchar} '"'.

COMMENTS FROM "/*" TO "*/" NESTED
COMMENTS FROM "//" TO eol

IGNORE ' ' + '\t' + '\r' + '\n'

PRODUCTIONS
  OSS         = SYNC "OSS"
                [
                  WAYORDER
                ]
                {
                  (. StyleFilter filter; .)
                  STYLE<filter>
                }
                "END"
                (.
                /*
              	  for (TypeId type=0; type<=config.GetTypeConfig()->GetMaxTypeId(); type++) {
              	    if (config.GetTypeConfig()->GetTypeInfo(type).CanBeWay()) {
	              	  if (config.GetWayPrio(type)==std::numeric_limits<size_t>::max() &&
	              	      config.GetWayLineStyle(type)!=NULL) {
	                    std::string e="Way type '"+config.GetTypeConfig()->GetTypeInfo(type).GetName()+"' has style but is not in a group";
	                    SemWarning(e.c_str());
	              	  }
		              else if (config.GetWayPrio(type)!=std::numeric_limits<size_t>::max() &&
		                       config.GetWayLineStyle(type)==NULL) {
	                    std::string e="Way type '"+config.GetTypeConfig()->GetTypeInfo(type).GetName()+"' is in group but has no style";
	                    SemWarning(e.c_str());
	              	  }
              	    }
              	  }*/
                .)
                .
  
  WAYORDER    = "ORDER" "WAYS"
                (. size_t priority=1;.)
                {
                  WAYGROUP<priority>
                  (. priority++;.)
                }
                .
  WAYGROUP<size_t priority>
              = "GROUP"
                [
                  (.
                     std::string wayTypeName;
                     TypeId      wayType;
                  .)
                  string (. wayTypeName=Destring(t->val); .)
                  (.
      	              wayType=config.GetTypeConfig()->GetWayTypeId(wayTypeName);

                      if (wayType==typeIgnore) {
                        std::string e="Unknown way type '"+wayTypeName+"'";
                        SemErr(e.c_str());
                      }
                      else {
                        config.SetWayPrio(wayType,priority);
                      }
                  .)
                ]
                {
                  (.
                     std::string wayTypeName;
                     TypeId      wayType;
                  .)
                  ","
                  string (. wayTypeName=Destring(t->val); .)
                  (.
      	              wayType=config.GetTypeConfig()->GetWayTypeId(wayTypeName);

                      if (wayType==typeIgnore) {
                        std::string e="Unknown way type '"+wayTypeName+"'";
	                    SemErr(e.c_str());
                      }
                      else {
                        config.SetWayPrio(wayType,priority);
                      }
                  .)
                }
                .                 

  STYLE<StyleFilter filter>
              = [
                  STYLEFILTER<filter>
                ]  
                (
                  (
                    "{"
                    {
                      STYLE<filter>
                    }
                    "}"
                  )    
                  | STYLEDEF<filter>
                )  
                .
                 
  STYLEFILTER<StyleFilter& filter>
              = "["
                   [
                     (.TypeSet types;.)
                     
                     "TYPE"
                     string
                     (.
                       std::string name=Destring(t->val);
                       TypeId      type=config.GetTypeConfig()->GetTypeId(name);
                  
                       if (type==typeIgnore) {
                         std::string e="Unknown type '"+name+"'";

                         SemErr(e.c_str());
                       }
                       else if (filter.HasTypes() &&
                                !filter.HasType(type)) {
                         std::string e="Type '"+name+"' is not included by parent filter";

                         SemErr(e.c_str());
                       }
                       else {
                         types.SetType(type);
                       }
                     .)
                     {
                       ","
                       string
                       (.
                         std::string name=Destring(t->val);
                         TypeId      type=config.GetTypeConfig()->GetTypeId(name);
                  
                         if (type==typeIgnore) {
                           std::string e="Unknown type '"+name+"'";

                           SemErr(e.c_str());
                         }
                         else if (filter.HasTypes() &&
                                  !filter.HasType(type)) {
                           std::string e="Type '"+name+"' is not included by parent filter";

                           SemErr(e.c_str());
                         }
                         else {
                           types.SetType(type);
                         }
                       .)
                     }
                     
                     (. filter.SetTypes(types); .)
                   ]
                   [
                     "MAG"
                     [
                       (. Mag mag; .)
                       MAG<mag>
                       (.
                          size_t level=MagToLevel(mag);
                          
                          if (level<filter.GetMinLevel()) {
                           std::string e="The magnification interval start is not within the parent magnification range";

                           SemErr(e.c_str());
                          }
                          else {
                            filter.SetMinLevel(level);
                          }
                       .)
                     ]
                     "-"
                     [
                       (. Mag mag; .)
                       MAG<mag>
                       (.
                          size_t level=MagToLevel(mag);
                          
                          if (level>filter.GetMaxLevel()) {
                           std::string e="The magnification interval end is not within the parent magnification range";

                           SemErr(e.c_str());
                          }
                          else {
                            filter.SetMaxLevel(level);
                          }
                       .)
                     ]
                   ]
                "]"
                .
                
  STYLEDEF<StyleFilter filter>
              =   NODESTYLEDEF<filter>
                | WAYSTYLEDEF<filter>
                | AREASTYLEDEF<filter>
                .
                
  NODESTYLEDEF<StyleFilter filter>
              = SYNC "NODE" "."
                (
                  NODELABELSTYLE<filter>
                | NODEREFSTYLE<filter>
                | NODESYMBOLSTYLE<filter>
                | NODEICONSTYLE<filter>
                )
                .
                
  NODELABELSTYLE<StyleFilter filter>
              = SYNC "LABEL"
                [
                  STYLEFILTER<filter>
                ]
                (.
                  LabelStyleList labelStyles;
                
                  config.GetNodeNameLabelStyles(filter,labelStyles); 
                .)
                SYNC "{"
                {
                  LABELDEF<labelStyles>
                }
                SYNC "}"
                .  

  NODEREFSTYLE<StyleFilter filter>
              = SYNC "REF"  
                [
                  STYLEFILTER<filter>
                ]
                (.
                  LabelStyleList labelStyles;
                    
                  config.GetNodeRefLabelStyles(filter,labelStyles); 
                .)
                SYNC "{"
                {
                	REFDEF<labelStyles>
                }
                SYNC "}"  
                .

  NODESYMBOLSTYLE<StyleFilter filter>
              = SYNC "SYMBOL"  
                [
                  STYLEFILTER<filter>
                ]
                (.
                  SymbolStyleList symbolStyles;
                    
                  config.GetNodeSymbolStyles(filter,symbolStyles); 
                .)
                SYNC "{"
                {
                  SYMBOLDEF<symbolStyles>
                }
                SYNC "}"  
                .

  NODEICONSTYLE<StyleFilter filter>
              = SYNC "ICON"
                [
                  STYLEFILTER<filter>
                ]
                (.
                  IconStyleList iconStyles;
                    
                  config.GetNodeIconStyles(filter,iconStyles); 
                .)
                SYNC "{"
                {
                  ICONDEF<iconStyles>
                }
                SYNC "}"  
                .
               
  WAYSTYLEDEF<StyleFilter filter>
              = SYNC "WAY"
                (
                  WAYSTYLE<filter>
                | "."
                  (
                     WAYLABELSTYLE<filter>
                  |  WAYREFSTYLE<filter>
                  )
                )
                .  
                
  WAYSTYLE<StyleFilter filter>
              = [
                  STYLEFILTER<filter>
                ]
                (.
                  LineStyleList lineStyles;
                    
                  config.GetWayLineStyles(filter,lineStyles); 
                .)
                SYNC "{"
                {
                   LINEDEF<lineStyles>
                }
                SYNC "}"   
                   .

  WAYLABELSTYLE<StyleFilter filter>
              = SYNC "LABEL"
                [
                  STYLEFILTER<filter>
                ]
                (.
                  LabelStyleList labelStyles;
                    
                  config.GetWayNameLabelStyles(filter,labelStyles); 
                .)
                "{"
                {
                  LABELDEF<labelStyles>
                }
                "}"  
                .

  WAYREFSTYLE<StyleFilter filter>
              = SYNC "REF"
                [
                  STYLEFILTER<filter>
                ]
                (.
                  LabelStyleList labelStyles;
                    
                  config.GetWayRefLabelStyles(filter,labelStyles); 
                .)
                SYNC "{"
                {
                  LABELDEF<labelStyles>
                }
                SYNC "}"  
                .
              
  AREASTYLEDEF<StyleFilter filter>
              = SYNC "AREA"
                (
                  AREASTYLE<filter>
                | "."
                  (
                    AREALABELSTYLE<filter>
                  | AREASYMBOLSTYLE<filter>
                  | AREAICONSTYLE<filter>
                  )
                )
                .  
                
  AREASTYLE<StyleFilter filter>
              = [
                  STYLEFILTER<filter>
                ]
                  
                (.
                  FillStyleList fillStyles;
                    
                  config.GetAreaFillStyles(filter,fillStyles); 
                .)
                SYNC "{"  
                {
                  FILLDEF<fillStyles>
                }
                SYNC "}"  
                .

  AREALABELSTYLE<StyleFilter filter>
              = SYNC "LABEL"
                [
                  STYLEFILTER<filter>
                ]
                (.
                  LabelStyleList labelStyles;
                
                  config.GetAreaLabelStyles(filter,labelStyles); 
                .)
                SYNC "{"  
                {
                  LABELDEF<labelStyles>
                }
                SYNC "}"  
                .

  AREASYMBOLSTYLE<StyleFilter filter>
              = SYNC "SYMBOL"
                [
                  STYLEFILTER<filter>
                ]
                (.
                  SymbolStyleList symbolStyles;
                 
                  config.GetAreaSymbolStyles(filter,symbolStyles); 
                .)
                SYNC "{"  
                {
                  SYMBOLDEF<symbolStyles>
                }
                SYNC "}"  
                .

  AREAICONSTYLE<StyleFilter filter>
              = SYNC "ICON"
                [
                  STYLEFILTER<filter>
                ]
                (.
                  IconStyleList iconStyles;
                
                  config.GetAreaIconStyles(filter,iconStyles); 
                .)
                SYNC "{"  
                {
                  ICONDEF<iconStyles>
                }
                SYNC "}"  
                .


  LINEDEF<LineStyleList& styles>
              = (
                  (. Color lineColor; .)
                  "color" ":" COLOR<lineColor> WEAK ";"
                  (.
                     for (LineStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LineStyleRef style(*s);   
                          
                  	   style->SetLineColor(lineColor);
                  	 }  
                  .)
                | (. Color alternateColor; .)
                  "altColor" ":" COLOR<alternateColor> WEAK ";"               // OBSOLETE!
                  (.
                     for (LineStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LineStyleRef style(*s);
                          
                  	   style->SetAlternateColor(alternateColor);
                  	 }  
                  .)
                | (. Color outlineColor;.)
                  "outlineColor" ":" COLOR<outlineColor> WEAK ";"
                  (.
                     for (LineStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LineStyleRef style(*s);
                          
                  	   style->SetOutlineColor(outlineColor);
                  	 }  
                  .)
                | (.
                    std::vector<double> dashes;
                    double              dash;
                   .)
                  "dash" ":"
                   DOUBLE<dash>   (. dashes.push_back(dash); .)
                  {
                    ","
                    DOUBLE<dash>  (. dashes.push_back(dash); .)
                  }
                  (.
                     for (LineStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LineStyleRef style(*s);
                          
                       style->SetDashes(dashes);
                     }
                  .)
                  WEAK ";"
                | (. Color gapColor; .)
                  "gapColor" ":" COLOR<gapColor> WEAK ";"
                  (.
                     for (LineStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LineStyleRef style(*s);
                          
                  	   style->SetGapColor(gapColor);
                  	 }  
                  .)
                | (. double displayWidth; .)
                  "displayWidth" ":"  DISPLAYSIZE<displayWidth> WEAK ";"
                  (.
                     for (LineStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LineStyleRef style(*s);
                          
                  	   style->SetDisplayWidth(displayWidth);
                  	 }  
                  .)
                | (. double width; .)
                  "width" ":" MAPSIZE<width> WEAK ";"
                  (.
                     for (LineStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LineStyleRef style(*s);
                          
                  	   style->SetWidth(width);
                  	 }  
                  .)
                | (. double outline; .)
                  "outline" ":" DISPLAYSIZE<outline> WEAK ";"
                  (.
                     for (LineStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LineStyleRef style(*s);
                          
                  	   style->SetOutline(outline);
                  	 }  
                  .)
                )
                .

  FILLDEF<FillStyleList& styles>
              = (
                  (. Color fillColor; .)
                  "color" ":" COLOR<fillColor> WEAK ";"
                  (.
                     for (FillStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       FillStyleRef style(*s);
                          
                  	   style->SetFillColor(fillColor);
                  	 }  
                  .)
                | (. std::string patternName; .)
                  "pattern" ":" string
                  (. patternName=Destring(t->val); .)
                   WEAK ";"
                  (.
                     for (FillStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       FillStyleRef style(*s);
                          
                  	   style->SetPattern(patternName);
                  	 }  
                  .)
                | (. Mag minMag; .)
                  "patternMinMag" ":" MAG<minMag> WEAK ";"
                  (.
                     for (FillStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       FillStyleRef style(*s);
                          
                  	   style->SetPatternMinMag(minMag);
                  	 }  
                  .)
                | (. Color borderColor; .)
                  "borderColor" ":" COLOR<borderColor> WEAK ";"
                  (.
                     for (FillStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       FillStyleRef style(*s);
                          
                  	   style->SetBorderColor(borderColor);
                  	 }  
                  .)
                | (. double width; .)
	              "borderWidth" ":" DISPLAYSIZE<width> WEAK ";"
                  (.
                     for (FillStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       FillStyleRef style(*s);
                          
                  	   style->SetBorderWidth(width);
                  	 }  
                  .)
                | (.
                    std::vector<double> dashes;
                    double              dash;
                   .)
                  "borderDash" ":"
                   DOUBLE<dash>   (. dashes.push_back(dash); .)
                  {
                    ","
                    DOUBLE<dash>  (. dashes.push_back(dash); .)
                  }
                  (.
                     for (FillStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       FillStyleRef style(*s);
                       
                       style->SetBorderDashes(dashes);
                     }  
                  .)
                  WEAK ";"
                )  
                .

  LABELDEF<LabelStyleList& styles>
              = (
                  (. LabelStyle::Style labelStyle; .)
                  "style" ":" LABELSTYLE<labelStyle> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetStyle(labelStyle);
                  	 }  
                  .)
                | (. Color textColor; .)
                  "color" ":" COLOR<textColor> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetTextColor(textColor);
                  	 }  
                  .)
                | (. Color bgColor; .)
                  "backgroundColor" ":" COLOR<bgColor> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetBgColor(bgColor);
                  	 }  
                  .)
                | (. Color borderColor; .)
	              "borderColor" ":" COLOR<borderColor> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetBorderColor(borderColor);
                  	 }  
                  .)
                | (. double size; .)
                  "size" ":" DOUBLE<size> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetSize(size);
                  	 }  
                  .)
                | (. Mag scaleMag; .)
                  "scaleMag" ":" MAG<scaleMag> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetScaleAndFadeMag(scaleMag);
                  	 }  
                  .)
                | (. size_t priority; .)
                  "priority" ":" INTEGER<priority> WEAK ";"
	              (.
	                if (priority>=0 && priority<std::numeric_limits<uint8_t>::max()) {
                      for (LabelStyleList::iterator s=styles.begin();
                           s!=styles.end();
                           ++s) {
                        LabelStyleRef style(*s);   
                       
                  	    style->SetPriority((uint8_t)priority);
                  	  }  
	                }
	                else {
	                  std::string e="Priority must be in the interval [0,"+
	                                NumberToString(std::numeric_limits<uint8_t>::max())+"[";
	                                
	                  SemErr(e.c_str());
	                }
	               .)
                )
                .

  REFDEF<LabelStyleList& styles>
              = (.
                  for (LabelStyleList::iterator s=styles.begin();
                       s!=styles.end();
                       ++s) {
                    LabelStyleRef style(*s);   
                       
                    style->SetStyle(LabelStyle::plate);
                  }  
                .)
                (
                  (. LabelStyle::Style labelStyle; .)
                  "style" ":" LABELSTYLE<labelStyle> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetStyle(labelStyle);
                  	 }  
                  .)
                | (. Color textColor; .)
                  "color" ":" COLOR<textColor> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetTextColor(textColor);
                  	 }  
                  .)
                | (. Color bgColor; .)
                  "backgroundColor" ":" COLOR<bgColor> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetBgColor(bgColor);
                  	 }  
                  .)
                | (. Color borderColor; .)
	              "borderColor" ":" COLOR<borderColor> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetBorderColor(borderColor);
                  	 }  
                  .)
                | (. double size; .)
                  "size" ":" DOUBLE<size> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetSize(size);
                  	 }  
                  .)
                | (. Mag scaleMag; .)
                  "scaleMag" ":" MAG<scaleMag> WEAK ";"
                  (.
                     for (LabelStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       LabelStyleRef style(*s);   
                       
                  	   style->SetScaleAndFadeMag(scaleMag);
                  	 }  
                  .)
                | (. size_t priority; .)
                  "priority" ":" INTEGER<priority> WEAK ";"
	              (.
	                if (priority>=0 && priority<std::numeric_limits<uint8_t>::max()) {
                      for (LabelStyleList::iterator s=styles.begin();
                           s!=styles.end();
                           ++s) {
                        LabelStyleRef style(*s);   
                       
                  	    style->SetPriority((uint8_t)priority);
                  	  }  
	                }
	                else {
	                  std::string e="Priority must be in the interval [0,"+
	                                NumberToString(std::numeric_limits<uint8_t>::max())+"[";
	                                
	                  SemErr(e.c_str());
	                }
	               .)
                )
                .

  SYMBOLDEF<SymbolStyleList& styles>
              = (
                  (. SymbolStyle::Style symbolStyle; .)
                  "style" ":" SYMBOLSTYLE<symbolStyle> WEAK ";"
                  (.
                     for (SymbolStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       SymbolStyleRef style(*s);   
                       
                  	   style->SetStyle(symbolStyle);
                  	 }  
                  .)
                | (. Color fillColor; .)
                  "color" ":" COLOR<fillColor> WEAK ";"
                  (.
                     for (SymbolStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       SymbolStyleRef style(*s);   
                       
                  	   style->SetFillColor(fillColor);
                  	 }  
                  .)
                | (. double size; .)
                  "size" ":" DOUBLE<size> WEAK ";"
                  (.
                     for (SymbolStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       SymbolStyleRef style(*s);   
                       
                  	   style->SetSize(size);
                  	 }  
                  .)
                )  
                .

  ICONDEF<IconStyleList& styles>
              = (
                  (. std::string name; .)
                  "name" ":" ident
                  (. name=Destring(t->val); .)
                  WEAK ";"
                  (.
                     for (IconStyleList::iterator s=styles.begin();
                          s!=styles.end();
                          ++s) {
                       IconStyleRef style(*s);   
                       
                  	   style->SetIconName(name);
                  	 }  
                  .)
                )
                .

  LABELSTYLE<LabelStyle::Style& style>
              = (
                  "normal"    (. style=LabelStyle::normal; .)
                | "contour"   (. style=LabelStyle::contour; .)
                | "plate"     (. style=LabelStyle::plate; .)
                | "emphasize" (. style=LabelStyle::emphasize; .)
                ).

  SYMBOLSTYLE<SymbolStyle::Style& style>
              = (
                  "none"      (. style=SymbolStyle::none; .)
                | "box"       (. style=SymbolStyle::box; .)
                | "triangle"  (. style=SymbolStyle::triangle; .)
                | "circle"    (. style=SymbolStyle::circle; .)
                ).

  COLOR<Color& color>
              = color
                (.
                  if (strlen(t->val)==7 ||
                      strlen(t->val)==9) {
                    ToRGBA(t->val,color);
                  }
                  else {
                    color=Color();
                  }
                .).

  MAG<Mag& mag>
              =  "world"     (. mag=magWorld; .)
               | "continent" (. mag=magContinent; .)
               | "state"     (. mag=magState; .)
               | "stateOver" (. mag=magStateOver; .)
               | "county"    (. mag=magCounty; .)
               | "region"    (. mag=magRegion; .)
               | "proximity" (. mag=magProximity; .)
               | "cityOver"  (. mag=magCityOver; .)
               | "city"      (. mag=magCity; .)
               | "suburb"    (. mag=magSuburb; .)
               | "detail"    (. mag=magDetail; .)
               | "close"     (. mag=magClose; .)
               | "veryClose" (. mag=magVeryClose; .)
               | "block"     (. mag=magBlock; .)
               .

  /** Size in units of screen (currently millimeter) */ 
  DISPLAYSIZE <double& value>
              = DOUBLE<value> "mm".
              
  /** Size in units of map (currently meter) */ 
  MAPSIZE <double& value>
              = DOUBLE<value> "m".

  DOUBLE<double& value>
              = (  number
                  (.
                    if (!StringToDouble(t->val,value)) {
                      std::string e="Cannot parse double '"+std::string(t->val)+"'";

                      SemErr(e.c_str());
                    }
                  .)
                | double
                  (.
                    if (!StringToDouble(t->val,value)) {
                      std::string e="Cannot parse double '"+std::string(t->val)+"'";

                      SemErr(e.c_str());
                    }
                  .)
                ).

  INTEGER<size_t& value>
              = (  number
                  (.
                    if (!StringToNumber(t->val,value)) {
                      std::string e="Cannot parse number '"+std::string(t->val)+"'";

                      SemErr(e.c_str());
                    }
                  .)
                ).
END OSS.

