json.jsf (4230B)
1 # JSON highlighter per json.org 2 3 # Written by Rebecca Turner (@ReBecaOrg) 4 5 # Define colors 6 7 =Idle 8 =Comma 9 =PairSep 10 =Bracket +Brace 11 =Brace +Control +Operator 12 =Constant 13 =Number +Constant 14 =Boolean +Constant 15 =Null +Constant 16 =String +Constant 17 =Key +Attr +Type +String 18 =Escape 19 =StringEscape +Escape +String 20 21 =Bad 22 =ERROR +Bad 23 24 :json Idle 25 * end noeat call=.value() 26 " \t\n" json 27 28 :end Idle 29 * endBAD noeat 30 " \t\n" end 31 32 :endBAD Bad 33 * end 34 35 .subr value 36 37 :value Idle 38 * valueBAD noeat 39 "\"" end noeat call=.string() 40 "-0-9" end noeat call=.number() 41 "tfn" end noeat call=.bareword() 42 "{" end noeat call=.object() 43 "[" end noeat call=.array() 44 45 :valueBAD Bad 46 * value 47 48 :end Idle 49 * NULL noeat return 50 51 .end 52 53 .subr object 54 55 :object Brace 56 * objectBAD noeat 57 "{" maybeempty 58 59 :objectBAD ERROR 60 * end 61 62 :maybeempty Brace 63 * key noeat 64 " \t\n" maybeempty 65 "}" end recolor=-1 66 67 :key Idle 68 * keyBAD noeat 69 "\"" pairsep noeat call=.keystring() 70 " \t\n" key 71 72 :keyBAD Bad 73 * key 74 75 :pairsep PairSep 76 * pairsepBAD noeat 77 ":" value 78 " \t\n" pairsep 79 80 :pairsepBAD Bad 81 * pairsep 82 83 :value Idle 84 * nextpair noeat call=.value() 85 " \t\n" value 86 87 :nextpair Comma 88 * nextpairBAD noeat 89 "}" end recolor=-1 90 "," key 91 " \t\n" nextpair 92 93 :nextpairBAD Bad 94 * nextpair 95 96 :end Brace 97 * NULL noeat return 98 .end 99 100 .subr array 101 102 :array Bracket 103 * arrayBAD noeat 104 "[" maybeempty 105 106 :arrayBAD ERROR 107 * end 108 109 :maybeempty Bracket 110 * value noeat 111 " \t\n" maybeempty 112 "]" end recolor=-1 113 114 :value Idle 115 * nextvalue noeat call=.value() 116 " \t\n" value 117 118 :nextvalue Comma 119 * nextvalueBAD noeat 120 "]" end recolor=-1 121 "," value 122 " \t\n" nextvalue 123 124 :nextvalueBAD Bad 125 * nextvalue 126 127 :end Bracket 128 * NULL noeat return 129 130 .end 131 132 .subr string 133 134 :string String string 135 * stringBAD noeat 136 "\"" body 137 138 :body String string 139 * body 140 "\"" end 141 "\\" escape recolor=-1 142 143 :stringBAD ERROR 144 * end 145 146 :escape StringEscape string 147 * escapeBAD recolor=-2 noeat 148 "\"/bfnrt\\" body 149 "u" unicode1 150 151 :escapeBAD Bad 152 * body 153 154 :unicode1 StringEscape string 155 * unicodeBAD recolor=-3 noeat 156 "0-9a-fA-F" unicode2 157 158 :unicode2 StringEscape string 159 * unicodeBAD recolor=-4 noeat 160 "0-9a-fA-F" unicode3 161 162 :unicode3 StringEscape string 163 * unicodeBAD recolor=-5 noeat 164 "0-9a-fA-F" unicode4 165 166 :unicode4 StringEscape string 167 * unicodeBAD recolor=-6 noeat 168 "0-9a-fA-F" body 169 170 :unicodeBAD Bad 171 * body 172 173 :end Idle 174 * NULL noeat return 175 176 .end 177 178 .subr keystring 179 180 :string Key 181 * stringBAD noeat 182 "\"" body 183 184 :body Key 185 * body 186 "\"" end 187 "\\" escape recolor=-1 188 189 :stringBAD ERROR 190 * end 191 192 :escape Escape 193 * escapeBAD recolor=-2 noeat 194 "\"/bfnrt\\" body 195 "u" unicode1 196 197 :escapeBAD Bad 198 * body 199 200 :unicode1 Escape 201 * unicodeBAD recolor=-3 noeat 202 "0-9a-fA-F" unicode2 203 204 :unicode2 Escape 205 * unicodeBAD recolor=-4 noeat 206 "0-9a-fA-F" unicode3 207 208 :unicode3 Escape 209 * unicodeBAD recolor=-5 noeat 210 "0-9a-fA-F" unicode4 211 212 :unicode4 Escape 213 * unicodeBAD recolor=-6 noeat 214 "0-9a-fA-F" body 215 216 :unicodeBAD Bad 217 * body 218 219 :end Idle 220 * NULL noeat return 221 222 .end 223 224 .subr bareword 225 226 :bareword Idle 227 * body noeat mark buffer 228 229 :body Bad 230 * end noeat markend strings 231 "true" boolean 232 "false" boolean 233 "null" null 234 235 done 236 "truefalsn" body 237 238 :boolean Boolean 239 * end noeat 240 241 :null Null 242 * end noeat 243 244 :end Idle 245 * NULL noeat return 246 247 .end 248 249 .subr number 250 251 :number Number 252 * numberBAD 253 "0-9" numberA noeat 254 "-" numberA 255 256 :numberBAD ERROR 257 * end 258 259 :numberA Number 260 "0" decimalpoint 261 "1-9" integer 262 263 :integer Number 264 * end noeat 265 "0-9" integer 266 "." decimalpart 267 "eE" exponentpart 268 269 :decimalpoint Number 270 * end noeat 271 "0-9" decimalpointBAD 272 "eE" exponentpart 273 "." decimalpart 274 275 :decimalpointBAD Bad 276 * end 277 278 :decimalpart Number 279 * decimalpartBAD 280 "0-9" decimalpartA 281 282 :decimalpartBAD Bad 283 * end 284 285 :decimalpartA Number 286 * end noeat 287 "0-9" decimalpartA 288 "eE" exponentpart 289 290 :exponentpart Number 291 * exponentpartBAD 292 "-+" exponentpartA 293 "0-9" exponentpartB 294 295 :exponentpartBAD Bad 296 * end 297 298 :exponentpartA Number 299 * exponentpartBAD 300 "0-9" exponentpartB 301 302 :exponentpartB Number 303 * end noeat 304 "0-9" exponentpartB 305 306 :end Idle 307 * NULL noeat return 308 309 .end