prolog.js (1563B)
1 /* 2 Language: Prolog 3 Description: Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics. 4 Author: Raivo Laanemets <raivo@infdot.com> 5 Website: https://en.wikipedia.org/wiki/Prolog 6 */ 7 8 function prolog(hljs) { 9 10 var ATOM = { 11 12 begin: /[a-z][A-Za-z0-9_]*/, 13 relevance: 0 14 }; 15 16 var VAR = { 17 18 className: 'symbol', 19 variants: [ 20 {begin: /[A-Z][a-zA-Z0-9_]*/}, 21 {begin: /_[A-Za-z0-9_]*/}, 22 ], 23 relevance: 0 24 }; 25 26 var PARENTED = { 27 28 begin: /\(/, 29 end: /\)/, 30 relevance: 0 31 }; 32 33 var LIST = { 34 35 begin: /\[/, 36 end: /\]/ 37 }; 38 39 var LINE_COMMENT = { 40 41 className: 'comment', 42 begin: /%/, end: /$/, 43 contains: [hljs.PHRASAL_WORDS_MODE] 44 }; 45 46 var BACKTICK_STRING = { 47 48 className: 'string', 49 begin: /`/, end: /`/, 50 contains: [hljs.BACKSLASH_ESCAPE] 51 }; 52 53 var CHAR_CODE = { 54 55 className: 'string', // 0'a etc. 56 begin: /0\'(\\\'|.)/ 57 }; 58 59 var SPACE_CODE = { 60 61 className: 'string', 62 begin: /0\'\\s/ // 0'\s 63 }; 64 65 var PRED_OP = { // relevance booster 66 begin: /:-/ 67 }; 68 69 var inner = [ 70 71 ATOM, 72 VAR, 73 PARENTED, 74 PRED_OP, 75 LIST, 76 LINE_COMMENT, 77 hljs.C_BLOCK_COMMENT_MODE, 78 hljs.QUOTE_STRING_MODE, 79 hljs.APOS_STRING_MODE, 80 BACKTICK_STRING, 81 CHAR_CODE, 82 SPACE_CODE, 83 hljs.C_NUMBER_MODE 84 ]; 85 86 PARENTED.contains = inner; 87 LIST.contains = inner; 88 89 return { 90 name: 'Prolog', 91 contains: inner.concat([ 92 {begin: /\.$/} // relevance booster 93 ]) 94 }; 95 } 96 97 module.exports = prolog;