lang-n.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (C) 2011 Zimin A.V.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview
  16. * Registers a language handler for the Nemerle language.
  17. * http://nemerle.org
  18. * @author Zimin A.V.
  19. */
  20. (function () {
  21. var keywords = 'abstract|and|as|base|catch|class|def|delegate|enum|event|extern|false|finally|'
  22. + 'fun|implements|interface|internal|is|macro|match|matches|module|mutable|namespace|new|'
  23. + 'null|out|override|params|partial|private|protected|public|ref|sealed|static|struct|'
  24. + 'syntax|this|throw|true|try|type|typeof|using|variant|virtual|volatile|when|where|with|'
  25. + 'assert|assert2|async|break|checked|continue|do|else|ensures|for|foreach|if|late|lock|new|nolate|'
  26. + 'otherwise|regexp|repeat|requires|return|surroundwith|unchecked|unless|using|while|yield';
  27. var shortcutStylePatterns = [
  28. [PR.PR_STRING, /^(?:\'(?:[^\\\'\r\n]|\\.)*\'|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/, null, '"'],
  29. [PR.PR_COMMENT, /^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/, null, '#'],
  30. [PR.PR_PLAIN, /^\s+/, null, ' \r\n\t\xA0']
  31. ];
  32. var fallthroughStylePatterns = [
  33. [PR.PR_STRING, /^@\"(?:[^\"]|\"\")*(?:\"|$)/, null],
  34. [PR.PR_STRING, /^<#(?:[^#>])*(?:#>|$)/, null],
  35. [PR.PR_STRING, /^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/, null],
  36. [PR.PR_COMMENT, /^\/\/[^\r\n]*/, null],
  37. [PR.PR_COMMENT, /^\/\*[\s\S]*?(?:\*\/|$)/, null],
  38. [PR.PR_KEYWORD, new RegExp('^(?:' + keywords + ')\\b'), null],
  39. [PR.PR_TYPE, /^(?:array|bool|byte|char|decimal|double|float|int|list|long|object|sbyte|short|string|ulong|uint|ufloat|ulong|ushort|void)\b/, null],
  40. [PR.PR_LITERAL, /^@[a-z_$][a-z_$@0-9]*/i, null],
  41. [PR.PR_TYPE, /^@[A-Z]+[a-z][A-Za-z_$@0-9]*/, null],
  42. [PR.PR_PLAIN, /^'?[A-Za-z_$][a-z_$@0-9]*/i, null],
  43. [PR.PR_LITERAL, new RegExp(
  44. '^(?:'
  45. // A hex number
  46. + '0x[a-f0-9]+'
  47. // or an octal or decimal number,
  48. + '|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)'
  49. // possibly in scientific notation
  50. + '(?:e[+\\-]?\\d+)?'
  51. + ')'
  52. // with an optional modifier like UL for unsigned long
  53. + '[a-z]*', 'i'), null, '0123456789'],
  54. [PR.PR_PUNCTUATION, /^.[^\s\w\.$@\'\"\`\/\#]*/, null]
  55. ];
  56. PR.registerLangHandler(PR.createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns), ['n', 'nemerle']);
  57. })();