vb.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * VB.NET
  4. *
  5. * Language spec:
  6. * http://msdn.microsoft.com/en-us/library/aa712050(v=vs.71).aspx
  7. *
  8. * TODO: IIRC vb can be embedded in asp pages like php or ruby on rails,
  9. * and XML literals: these are a little bit confusing, something
  10. * like "<xyz>.something" appears to be a valid XML fragment (i.e. the <xyz>
  11. * is a complete fragment), but at other times, the fragment would run until
  12. * the root tag is popped. Need to find a proper description of the grammar
  13. * to figure it out
  14. */
  15. class LuminousVBScanner extends LuminousSimpleScanner {
  16. public $case_sensitive = false;
  17. public function init() {
  18. $this->add_pattern('PREPROCESSOR', "/^[\t ]*#.*/m");
  19. $this->add_pattern('COMMENT', "/'.*/");
  20. $this->add_pattern('COMMENT', '/\\bREM\\b.*/i');
  21. // float
  22. $this->add_pattern('NUMERIC', '/ (?<!\d)
  23. \d+\.\d+ (?: e[+\\-]?\d+)?
  24. |\.\d+ (?: e[+\\-]?\d+)?
  25. | \d+ e[+\\-]?\d+
  26. /xi');
  27. // int
  28. $this->add_pattern('NUMERIC', '/ (?:
  29. &H[0-9a-f]+
  30. | &O[0-7]+
  31. | (?<!\d)\d+
  32. ) [SIL]*/ix');
  33. $this->add_pattern('CHARACTER', '/"(?:""|.)"c/i');
  34. $this->add_pattern('STRING', '/" (?> [^"]+ | "" )* ($|")/x');
  35. // in theory we should also match unicode quote chars
  36. // in reality, well, I read the php docs and I have no idea if it's
  37. // even possible.
  38. // The chars are:
  39. // http://www.fileformat.info/info/unicode/char/201c/index.htm
  40. // and
  41. // http://www.fileformat.info/info/unicode/char/201d/index.htm
  42. // date literals, this isn't as discriminating as the grammar specifies.
  43. $this->add_pattern('VALUE', "/#[ \t][^#\n]*[ \t]#/");
  44. $this->add_pattern('OPERATOR', '/[&*+\\-\\/\\\\^<=>,\\.]+/');
  45. // http://msdn.microsoft.com/en-us/library/aa711645(v=VS.71).aspx
  46. // XXX: it warns about ! being ambiguous but I don't see how it can be
  47. // ambiguous if we use this regex?
  48. $this->add_pattern('IDENT', '/[a-z_]\w*[%&@!#$]?/i');
  49. // we'll borrow C#'s list of types (ie modules, classes, etc)
  50. include(dirname(__FILE__) . '/include/vb.php');
  51. include(dirname(__FILE__) . '/include/csharp_list.php');
  52. $this->add_identifier_mapping('VALUE', $luminous_vb_values);
  53. $this->add_identifier_mapping('OPERATOR', $luminous_vb_operators);
  54. $this->add_identifier_mapping('TYPE', $luminous_vb_types);
  55. $this->add_identifier_mapping('KEYWORD', $luminous_vb_keywords);
  56. $this->add_identifier_mapping('TYPE', $luminous_csharp_type_list);
  57. }
  58. public static function guess_language($src, $info) {
  59. $p = 0.0;
  60. if (preg_match('/^Imports\s+System/i', $src)) $p += 0.1;
  61. if (preg_match('/Dim\s+\w+\s+As\s+/i', $src)) $p += 0.2;
  62. if (preg_match('/(Public|Private|Protected)\s+Sub\s+/i', $src)) $p += 0.1;
  63. return $p;
  64. }
  65. }