Merge pull request #13 from iarna/rewrite-js-highlighter

Rewrite JavaScript syntax highlighting
This commit is contained in:
Christian Nicolai 2014-09-13 22:20:37 +02:00
commit 8fdee52d35
1 changed files with 421 additions and 281 deletions

702
js.jsf
View File

@ -1,373 +1,513 @@
# JOE syntax highlight file for JavaScript # JOE syntax highlight file for JavaScript
# the real one - not a pimped Java file... # Define colors
# just getting this idea seams crazy...
# TODO: regex escape highlighter ignored \x (and other?) sequences =Idle
=Idle
=Comment green =Comment green
=CommentLabel bold green =CommentLabel bold green
=Constant cyan =Constant cyan
=Escape bold cyan =String cyan
=StringEscape bold cyan
=Regexp cyan
=RegexpEscape bold cyan
=RegexpOptions cyan
=Number cyan
=Type bold =Type bold
=CustomType
=Keyword bold =Keyword bold
=Global bold =Global bold
=Exports bold black =Exports
=ExportItem
=Operator bold =Operator bold
=Bad inverse bold red =Bad inverse bold red
=Brace magenta =Brace magenta
=Control =Assign bold
=Paren
=Bracket
=Semicolon
=Comma
=PropSep
=Syntax
=Ident
=Method
# additional classes not present everywhere but useful # from html.jsf to support embedded languages
=Methods
=Number cyan #fg_520 # orange
# from html.jsf to support <?php?>
=TagEdge green =TagEdge green
:begin Idle :begin Idle
* begin noeat call=.js() * begin noeat call=.js()
.subr js .subr js
:idle Idle :idle Idle
* idle * idle
"\n" idle "/" re_or_comment recolor=-1
"/" slash "0" first_digit recolor=-1
"0" first_digit recolor=-1 "1-9" decimal recolor=-1
"1-9" decimal recolor=-1 "." maybe_float
"." maybe_float "\"" string recolor=-1 save_c
"\"" string recolor=-1 "'" string recolor=-1 save_c
"'" char recolor=-1 "A-Z" type_match mark buffer recolor=-1
"a-zA-Z_" ident mark buffer "$a-z_" ident mark buffer recolor=-1
"{}" brace recolor=-1 "{}" brace recolor=-1
"()" paren noeat recolor=-1
";" semicolon recolor=-1
"," comma recolor=-1
"=" assign_maybe recolor=-1
"[]" bracket noeat recolor=-1
"\-" subtract recolor=-1
"+" add recolor=-1
"*|&^%" mutate_maybe recolor=-1
":?~" syntax recolor=-1
.ifdef html .ifdef html
",:;=()>[]*&|!?~+\-%^" control recolor=-1 "<" maybe_done recolor=-1
"<" maybe_done recolor=-1 ">!" eqmixer_maybe recolor=-1
.else .else
.ifdef php .ifdef php
",:;=()>[]*&|!?~+\-%^" control recolor=-1 "<" maybe_done recolor=-1
"<" maybe_done recolor=-1 ">!" eqmixer_maybe recolor=-1
.else .else
",:;=()><[]*&|!?~+\-%^" control recolor=-1 .ifdef mason
"<" maybe_done recolor=-1
">!" eqmixer_maybe recolor=-1
.else
"<>!" eqmixer_maybe recolor=-1
.endif
.endif .endif
.endif .endif
# / / regex not allowed after terms :subtract Assign
# class Control to handle ')' right * mutate_maybe noeat
:after_term Control "\-" assign recolor=-2
* idle noeat
" \t)" after_term :add Assign
"%" control recolor=-1 * mutate_maybe noeat
"/" after_term_slash "+" assign recolor=-2
:mutate_maybe Assign
* syntax recolor=-2 noeat
"=" assign recolor=-2
:syntax Syntax
* idle recolor=-1 noeat
:assign Assign
* idle recolor=-1 noeat
:eqmixer_maybe Syntax
* idle recolor=-1 noeat
"=" eqmixer_maybe
:assign_maybe Assign
* idle recolor=-1 noeat
"=" equality recolor=-2
:equality Syntax
* idle recolor=-1 noeat
"=" syntax
:maybe_done TagEdge :maybe_done TagEdge
* idle noeat * eqmixer_maybe noeat
"/" idle noeat return recolor=-2 "/" idle noeat return recolor=-2
.ifdef php .ifdef php
"?%" rtn_php call=php.php() "?" rtn_embed call=php.php()
.endif
.ifdef mason
"&%" rtn_embed call=perl.perl()
.endif .endif
# this state allows php and perl to recolor the ?> %> or &> properly. :rtn_embed TagEdge
:rtn_php TagEdge * idle noeat
* idle noeat
:brace Brace :no_regex Idle
* idle noeat * idle noeat
"/" maybe_comment recolor=-1
" " no_regex
:control Control :after_term Idle
* idle noeat * after_term
"\n" idle
"/" maybe_comment recolor=-1
"." prop_sep recolor=-1
"a-z" infix_operator buffer recolor=-1
"\"'A-Z_0-9" bad_after_term recolor=-1
"{}" brace recolor=-1
"()" paren noeat recolor=-1
";" semicolon recolor=-1
"=" assign_maybe recolor=-1
"," comma recolor=-1
"[]" bracket noeat recolor=-1
"\-" subtract recolor=-1
"+" add recolor=-1
"*|&^%" mutate_maybe recolor=-1
":?~" syntax recolor=-1
.ifdef html
"<" maybe_done recolor=-1
">!" eqmixer_maybe recolor=-1
.else
.ifdef php
"<" maybe_done recolor=-1
">!" eqmixer_maybe recolor=-1
.else
.ifdef mason
"<" maybe_done recolor=-1
">!" eqmixer_maybe recolor=-1
.else
"<>!" eqmixer_maybe recolor=-1
.endif
.endif
.endif
:slash Idle :ident_only Idle
* regex noeat recolor=-2 * bad_after_term recolor=-1
"*" comment recolor=-2 "A-Z" type_match mark buffer recolor=-1
"/" line_comment recolor=-2 "$a-z_" ident mark buffer recolor=-1
" \t" ident_only
"\n" idle
# allow // and /* after terms :bad_after_term Bad
:after_term_slash Idle * after_term noeat markend strings
* idle noeat done
"*" comment recolor=-2 "\"'" after_term
"/" line_comment recolor=-2 "a-zA-Z0-9_." bad_after_term
:re_or_comment Syntax
* regex recolor=-2
"*/" maybe_comment noeat
:maybe_comment Syntax
* syntax noeat
"*" comment recolor=-2
"/" line_comment recolor=-2
"=" assign recolor=-2
:comment Comment :comment Comment
* comment * comment
# might be TODO label # might be TODO label
"BFHNTX" comment noeat call=.comment_todo() "BFHNTX" comment noeat call=.comment_todo()
"*" maybe_end_comment "*" maybe_end_comment
:maybe_end_comment Comment :maybe_end_comment Comment
* comment noeat * comment noeat
"/" idle "/" idle
"*" maybe_end_comment "*" maybe_end_comment
:line_comment Comment :line_comment Comment
* line_comment * line_comment
# might be TODO label # might be TODO label
"BFHNTX" line_comment noeat call=.comment_todo() "BFHNTX" line_comment noeat call=.comment_todo()
"\n" idle "\n" idle
:regex Constant :regex Regexp
* regex * regex
"\\" regex_quote recolor=-1 "\\" regex_quote recolor=-1
"/" regex_mod "/" regex_mod
:regex_quote Escape :regex_quote RegexpEscape
* regex * regex
:regex_mod Constant :regex_mod RegexpOptions
* after_term noeat * after_term noeat
"igm" regex_mod "igm" regex_mod
:brace Brace
* idle noeat
:paren Paren
"(" idle
")" no_regex
:bracket Bracket
"[" idle
"]" after_term
:syntax Syntax
* idle noeat
:comma Comma
* idle noeat
:semicolon Semicolon
* idle noeat
:first_digit Number :first_digit Number
* after_term noeat * after_term noeat
"xX" hex "xX" hex
"." float "." float
"eE" epart "eE" epart
"0-7" octal "0-7" octal
"89" bad_number recolor=-1 "89" bad_number recolor=-1
:bad_number Bad :bad_number Bad
* after_term noeat * after_term noeat
"0-9" bad_number "0-9" bad_number
:octal Number :octal Number
* after_term noeat * after_term noeat
"0-7" octal "0-7" octal
"89" bad_number recolor=-1 "89" bad_number recolor=-1
:hex Number :hex Number
* after_term noeat * after_term noeat
"0-9A-Fa-f" hex "0-9A-Fa-f" hex
:decimal Number :decimal Number
* after_term noeat * after_term noeat
"0-9" decimal "0-9" decimal
"eE" epart "eE" epart
"." float "." float
:maybe_float Number :maybe_float Number
* after_term recolor=-2 noeat * prop_sep noeat recolor=-2
"0-9" float recolor=-2 "0-9" float recolor=-2
:prop_sep PropSep
* ident_only noeat
:float Number :float Number
* after_term noeat * after_term noeat
"eE" epart "eE" epart
"0-9" float "0-9" float
:epart Number :epart Number
* after_term noeat * after_term noeat
"0-9+\-" enum "0-9+\-" enum
:enum Number :enum Number
* after_term noeat * after_term noeat
"0-9" enum "0-9" enum
:string Constant :string String
* string * string_body noeat mark
"\"" after_term
"\\" string_escape recolor=-1
"%" string_control recolor=-1
:string_escape Escape :string_body String
* string * string
"x" string_hex1 "\n" string_bad
"0-7" string_octal2 & after_term
"\n" string recolor=-2 "\\" string_escape recolor=-1
:string_hex1 Escape :string_bad Bad
* string noeat * string_bad
"0-9a-fA-F" string_hex2 "\\" string_bad_escape
& after_term
:string_hex2 Escape :string_bad_escape Bad
* string noeat * string_bad
"0-9a-fA-F" string
:string_octal2 Escape :string_escape StringEscape
* string noeat * string
"0-7" string_octal3 "x" string_hex1
"0-7" string_octal2
"\n" string_bad noeat
:string_octal3 Escape :string_hex1 StringEscape
* string noeat * string noeat
"0-7" string "0-9a-fA-F" string_hex2
:string_control Escape :string_hex2 StringEscape
* string_control * string noeat
"\n" reset "0-9a-fA-F" string
"diouxXeEfFgGaAcspn%SC" string
:char Constant :string_octal2 StringEscape
* char * string noeat
"\n" reset "0-7" string_octal3
"'" after_term
"\\" char_escape recolor=-1
:char_escape Escape :string_octal3 StringEscape
* char * string noeat
"x" char_hex1 "0-7" string
"0-7" char_octal2
"\n" char recolor=-2
:char_hex1 Escape :infix_operator Bad
* char noeat * bad_op noeat markend strings
"0-9a-fA-F" char_hex2 "in" operator
"instanceof" operator
:char_hex2 Escape
* char noeat
"0-9a-fA-F" char
:char_octal2 Escape
* char noeat
"0-7" char_octal3
:char_octal3 Escape
* char noeat
"0-7" char
:ident Idle
* ident_end noeat markend strings
"arguments" kw
"Array" type
"ArrayBuffer" type
"break" kw
"Boolean" type
"case" kw
"catch" kw
"const" global
"continue" kw
"DataView" type
"decodeURI" global
"decodeURIComponent" global
"default" kw
"delete" operator
"do" kw
"Date" type
"else" kw
"encodeURI" global
"encodeURIComponent" global
"Error" type
"escape" global
"eval" global
"EvalError" type
"false" lit
"finally" kw
"for" kw
"function" kw
"Function" type
"Float32Array" type
"Float64Array" type
"if" kw
"in" kw
"Infinity" lit
"instanceof" operator
"Int16Array" type
"Int32Array" type
"Int8Array" type
"isFinite" global
"isNaN" global
"JSON" type
"let" kw
"Math" type
"NaN" lit
"new" operator
"null" lit
"Number" type
"Object" type
"parseFloat" global
"parseInt" global
"return" kw
"RangeError" type
"ReferenceError" type
"RegExp" type
"switch" kw
"String" type
"SyntaxError" type
"this" kw
"throw" kw
"true" lit
"try" kw
"typeof" operator
"TypeError" type
"Uint16Array" type
"Uint32Array" type
"Uint8Array" type
"Uint8ClampedArray" type
"undefined" lit
"unescape" global
"URIError" type
"var" kw
"void" kw
"while" kw
"with" kw
# quasi-keywords
"prototype" kw
# Node.js
"module" global
"exports" export
"process" global
"global" global
"console" global
"setTimeout" global
"setInterval" global
"clearInterval" global
"Buffer" type
# Node.js globals that we'll pretend are keywords
"require" kw
"__filename" kw
"__dirname" kw
# By convention...
"self" kw
done done
"a-zA-Z0-9_" ident "a-zA-Z0-9_" infix_operator
:type Type :bad_op Bad
* after_term noeat * idle noeat
"a-zA-Z0-9_" bad_op
:kw Keyword
* idle noeat
:global Global
* idle noeat
:export Exports
* idle noeat
:lit Constant
* after_term noeat
:operator Operator :operator Operator
* idle noeat * idle noeat
:type_match CustomType
* type_end noeat markend strings
"Infinity" lit
"NaN" lit
"Array" type
"ArrayBuffer" type
"Boolean" type
"DataView" type
"Date" type
"Error" type
"EvalError" type
"Function" type
"Float32Array" type
"Float64Array" type
"Int16Array" type
"Int32Array" type
"Int8Array" type
"JSON" type
"Math" type
"Number" type
"Object" type
"RangeError" type
"ReferenceError" type
"RegExp" type
"String" type
"SyntaxError" type
"TypeError" type
"Uint16Array" type
"Uint32Array" type
"Uint8Array" type
"Uint8ClampedArray" type
"URIError" type
# node.js
"Buffer" type
done
"a-zA-Z0-9_" type_match
:type_end Idle
* after_term noeat
" " type_end
"." prop_sep recolor=-1
:ident Ident
* ident_end noeat markend strings
"delete" operator
"in" operator
"instanceof" operator
"typeof" operator
"new" operator
"arguments" kw
"break" kw
"case" kw
"catch" kw
"continue" kw
"default" kw
"do" kw
"else" kw
"finally" kw
"for" kw
"function" kw
"if" kw
"let" kw
"return" kw
"switch" kw
"throw" kw
"try" kw
"var" kw
"void" kw
"while" kw
"with" kw
"false" lit
"null" lit
"true" lit
"const" global
"decodeURI" global
"decodeURIComponent" global
"encodeURI" global
"encodeURIComponent" global
"escape" global
"eval" global
"isFinite" global
"isNaN" global
"parseFloat" global
"parseInt" global
"undefined" global
"unescape" global
"setImmediate" global
"this" quasikw
"prototype" quasikw
# node.js
"exports" export
"module" global
"process" global
"global" global
"console" global
"setTimeout" global
"setInterval" global
"clearInterval" global
"clearTimeout" global
"require" quasikw
"__filename" quasikw
"__dirname" quasikw
# By convention...
"self" quasikw
done
"$a-zA-Z0-9_" ident
:ident_end Idle :ident_end Idle
* after_term noeat * after_term noeat
" " ident_end " " ident_end
"(" method_end noeat recolormark "." prop_sep recolor=-1
"(" method_start recolor=-1
:method_end Methods :method_start Paren
* idle noeat * method_end noeat recolormark
:method_end Method
* idle noeat
:type Type
* after_term noeat
:kw Keyword
* idle noeat
:quasikw Keyword
* after_term noeat
:global Global
* after_term noeat
:export Exports
* export_end noeat
:export_end Exports
* after_term noeat
" " export_end
"." export_item_start
:export_item_start ExportItem
* bad_after_term recolor=-1 noeat
" " export_item_start
"a-zA-Z_" export_item
:export_item ExportItem
* after_term noeat
"a-zA-Z0-9_" export_item
:lit Constant
* lit_end noeat
:lit_end Constant
* after_term noeat
" " lit_end
"." prop_sep recolor=-1
.end .end
.subr comment_todo .subr comment_todo
# initial state # initial state
:comment_todo_init Comment :todo_init Comment
* comment_todo_guess buffer * todo_guess buffer
# highlight common TODO labels # highlight common TODO labels
:comment_todo_guess Comment :todo_guess Comment
* comment_todo_unknown noeat strings * todo_unknown noeat strings
"BUG" comment_todo "BUG" todo
"FIXME" comment_todo "FIXME" todo
"HACK" comment_todo "HACK" todo
"NOTE" comment_todo "NOTE" todo
"TODO" comment_todo "TODO" todo
"XXX" comment_todo "XXX" todo
done done
"A-Z" comment_todo_guess "A-Z" todo_guess
:comment_todo_unknown Comment :todo_unknown Comment
* NULL noeat return * NULL noeat return
:comment_todo CommentLabel :todo CommentLabel
* NULL noeat return * NULL noeat return
.end .end