Attribute.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Xml.Linq;
  5. namespace csharp_sccd_compiler
  6. {
  7. public class Attribute : Visitable
  8. {
  9. public string name { get; private set; }
  10. public string type { get; private set; }
  11. public string init_value { get; private set; }
  12. public Attribute(XElement xml)
  13. {
  14. XAttribute name_attribute = xml.Attribute("name");
  15. if (name_attribute == null)
  16. throw new CompilerException("Missing attribute name.");
  17. this.name = name_attribute.Value.Trim();
  18. if (this.name == "")
  19. throw new CompilerException("Empty attribute name.");
  20. if (Constants.Reserved.Contains(this.name))
  21. throw new CompilerException(string.Format("Reserved word '{0}' used as attribute name.", this.name));
  22. XAttribute type_attribute = xml.Attribute("type");
  23. if (type_attribute == null)
  24. throw new CompilerException("Missing attribute type.");
  25. this.type = type_attribute.Value.Trim();
  26. if (this.type == "")
  27. throw new CompilerException("Empty attribute type.");
  28. XAttribute init_attribute = xml.Attribute("init-value");
  29. if (init_attribute == null || init_attribute.Value == "")
  30. this.init_value = null;
  31. else
  32. this.init_value = init_attribute.Value;
  33. }
  34. public override void accept(Visitor visitor)
  35. {
  36. visitor.visit (this);
  37. }
  38. }
  39. }