Menu

[dc0a3d]: / syntax / python.jsf  Maximize  Restore  History

Download this file

404 lines (340 with data), 7.0 kB

# JOE syntax highlight file for Python

=Idle
=Ident
=Comment
=Docstring	+Comment
=DocstringLabel	+Docstring
=DocEscape	+Escape +Docstring
=Constant
=String		+Constant
=Number		+Constant
=Boolean	+Constant
=StringEscape	+Escape
=Keyword
=Statement	+Keyword
=Loop		+Statement
=Conditional	+Statement
=StorageClass	+Type +Keyword
=Operator	+Keyword
=Bad
=Brace

=DefinedIdent	+Ident
=DefinedFunction +DefinedIdent
=DefinedType	+DefinedIdent
=SpecialIdent	+Ident
=Decorator	+Define +Preproc
=Builtin	+DefinedFunction

:idle Idle
	*		idle
	"#"		comment		recolor=-1
	"0-9"		first_digit	recolor=-1
	"'\""		string_quot_1	recolor=-1 save_c
	"\i"		ident		noeat
	"{}"		brace		recolor=-1
	"@"		decorator	recolor=-1

:brace Brace
	*		idle		noeat

# annotations
:decorator Decorator
	*		decorator
	" (\t\r\n"	idle		noeat

:comment Comment comment
	*		comment
	# might be TODO label
	"BFHNTX"	comment		noeat call=comment_todo.comment_todo()
	"\n"		idle

:first_digit Number
	*		idle		noeat
	"xX"		hex
	"."		float
	"eE"		epart
	"0-9"		first_number

:hex Number
	*		idle		noeat
	"0-9A-Fa-f"	hex

:first_number Number
	*		idle		noeat
	"0-9"		first_number
	"."		float

:maybe_float Number
	*		idle		recolor=-2	noeat
	"0-9"		float		recolor=-2

:float Number
	*		idle		noeat
	"eE"		epart
	"0-9"		float

:epart Number
	*		idle		noeat
	"0-9+\-"	enum

:enum Number
	*		idle		noeat
	"0-9"		enum

:ident Ident
	*		ident1		noeat buffer
	"_"		priv_member	recolor=-1

:ident1 Ident
	*		idle		noeat strings
	"and"		oper
	"as"		stmt
	"assert"	stmt
	"break"		loop
	"class"		classstmt
	"continue"	loop
	"def"		defstmt
	"del"		stmt
	"elif"		cond
	"else"		cond
	"except"	stmt
	"finally"	stmt
	"for"		loop
	"from"		stmt
	"global"	stmt
	"if"		cond
	"import"	stmt
	"in"		oper
	"is"		oper
	"lambda"	kw
	"not"		oper
	"or"		oper
	"pass"		stmt
	"raise"		stmt
	"return"	stmt
	"try"		stmt
	"while"		loop
	"with"		stmt
	"yield"		stmt
	
	# quasi-keywords
	"False"		bool
	"True"		bool
	"None"		kw
	
	# builtins
	"abs"		builtin
	"all"		builtin
	"any"		builtin
	"ascii"		builtin
	"bin"		builtin
	"bool"		builtin
	"bytearray"	builtin
	"bytes"		builtin
	"callable"	builtin
	"chr"		builtin
	"classmethod"	builtin
	"compile"	builtin
	"complex"	builtin
	"copyright"	builtin
	"credits"	builtin
	"delattr"	builtin
	"dict"		builtin
	"dir"		builtin
	"divmod"	builtin
	"enumerate"	builtin
	"eval"		builtin
	"exec"		builtin
	"exit"		builtin
	"filter"	builtin
	"float"		builtin
	"format"	builtin
	"frozenset"	builtin
	"getattr"	builtin
	"globals"	builtin
	"hasattr"	builtin
	"hash"		builtin
	"help"		builtin
	"hex"		builtin
	"id"		builtin
	"input"		builtin
	"int"		builtin
	"isinstance"	builtin
	"issubclass"	builtin
	"iter"		builtin
	"len"		builtin
	"license"	builtin
	"list"		builtin
	"locals"	builtin
	"map"		builtin
	"max"		builtin
	"memoryview"	builtin
	"min"		builtin
	"next"		builtin
	"object"	builtin
	"oct"		builtin
	"open"		builtin
	"ord"		builtin
	"pow"		builtin
	"print"		builtin
	"property"	builtin
	"quit"		builtin
	"range"		builtin
	"repr"		builtin
	"reversed"	builtin
	"round"		builtin
	"set"		builtin
	"setattr"	builtin
	"slice"		builtin
	"sorted"	builtin
	"staticmethod"	builtin
	"str"		builtin
	"sum"		builtin
	"super"		builtin
	"tuple"		builtin
	"type"		builtin
	"vars"		builtin
	"zip"		builtin
	
done
	"'\""		idle 		noeat istrings
	"u"		string_pre
	"b"		string_pre
	"r"		string_raw_pre
	"br"		string_raw_pre
	"rb"		string_raw_pre
done
	"\c"		ident1

:kw Keyword
	*		idle		noeat

:cond Conditional
	*		idle		noeat

:oper Operator
	*		idle		noeat

:bool Boolean
	*		idle		noeat

:loop Loop
	*		idle		noeat

:stmt Statement
	*		idle		noeat

:builtin Builtin
	*		idle		noeat

:classstmt Statement
	*		idle 		noeat recolor=-1
	"\i"		classstmt
	" \t"		classname_1

:classname_1 DefinedType
	*		classname

:classname DefinedType
	*		idle		noeat recolor=-1
	"\c"		classname

:defstmt Statement
	*		idle		noeat recolor=-1
	"\i"		defstmt
	" \t"		defname_1

:defname_1 DefinedFunction
	*		defname

:defname DefinedFunction
	*		idle		noeat recolor=-1
	"\c"		defname

:priv_member SpecialIdent
	*		idle		noeat
	"\c"		priv_member

# Handle string prefixes up to the string itself.
:string_pre String string
	*		idle noeat
	"'\""		string_quot_1 	save_c

:string_raw_pre String string
	*		idle noeat
	"'\""		string_quot_raw_1 save_c

# Differentiate between docstrings and regular strings, carrying with it raw state
:string_quot_1 String string
	*		idle call=.string() noeat
	&		string_quot_2

:string_quot_2 String string
	*		idle noeat
	&		idle call=.string(docstring) recolor=-3

:string_quot_raw_1 String string
	*		idle call=.string(raw)
	&		string_quot_raw_2

:string_quot_raw_2 String string
	*		idle noeat
	&		idle call=.string(docstring raw) recolor=-3

.subr string

.ifdef docstring	# Long strings
:string Docstring string
	*		string
	"BFHNTX"	string		noeat call=.comment_todo_docstr()
.ifdef raw
.else
	"\\"		string_esc	mark
.endif
	&		doc_end_1

:doc_end_1 Docstring string
	*		string noeat
	&		doc_end_2

:doc_end_2 Docstring string
	*		string noeat
	&		string return

.else			# Short strings

:string String string
	*		string
	"\n"		string return
.ifdef raw
.else
	"\\"		string_esc mark
.endif
	&		string return

.endif

:string_esc String string
	*		string_esc_done
	"x"		string_hex2
	"u"		string_hex4
	"U"		string_hex8
	"0-7"		string_octal2
	"\n"		string_esc_done

# Recolor whole escape sequence based on whether this is a docstring.
:string_esc_done String string
	*		string_esc_really_done noeat markend recolormark

.ifdef docstring
:string_esc_really_done DocEscape
	*		string 		noeat
.else
:string_esc_really_done StringEscape string
	*		string 		noeat
.endif

:string_hex1 StringEscape string
	*		string_esc_done	noeat
	"0-9a-fA-F"	string_esc_done

:string_hex2 StringEscape string
	*		string_esc_done	noeat
	"0-9a-fA-F"	string_hex1

:string_hex3 StringEscape string
	*		string_esc_done	noeat
	"0-9a-fA-F"	string_hex2

:string_hex4 StringEscape string
	*		string_esc_done	noeat
	"0-9a-fA-F"	string_hex3

:string_hex5 StringEscape string
	*		string_esc_done	noeat
	"0-9a-fA-F"	string_hex4

:string_hex6 StringEscape string
	*		string_esc_done	noeat
	"0-9a-fA-F"	string_hex5

:string_hex7 StringEscape string
	*		string_esc_done	noeat
	"0-9a-fA-F"	string_hex6

:string_hex8 StringEscape string
	*		string_esc_done	noeat
	"0-9a-fA-F"	string_hex7

:string_octal1 StringEscape string
	*		string_esc_done	noeat
	"0-7"		string_esc_done

:string_octal2 StringEscape string
	*		string_esc_done	noeat
	"0-7"		string_octal1

.end

.subr comment_todo_docstr
# initial state
:comment_todo_init Docstring string
	*		comment_todo_guess	buffer

# highlight common TODO labels
:comment_todo_guess Docstring string
	*		comment_todo_unknown	noeat strings
	"BUG"		comment_todo
	"FIXME"		comment_todo
	"HACK"		comment_todo
	"NOTE"		comment_todo
	"TODO"		comment_todo
	"XXX"		comment_todo
done
	"A-Z"		comment_todo_guess

:comment_todo_unknown Docstring string
	*		NULL		noeat return

:comment_todo DocstringLabel string
	*		NULL		noeat return
.end
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.