Menu

[517113]: / syntax / batch.jsf  Maximize  Restore  History

Download this file

187 lines (155 with data), 3.0 kB

# JOE syntax highlight file for Windows batch scripts

=Idle
=Comment
=Command	+Type
=Statement	+Keyword
=Brace
=Variable	+DefinedIdent
=StringVariable	+StringEscape
=Label
=Conditional	+Statement
=Loop		+Statement
=String		+Constant

:reset Idle
	*		linebegin	noeat
	" \t\r\n"	reset

:linebegin Idle
	*		stmtorcommand	noeat buffer
	":"		labelorcomment
	"@"		linebegin
	"%"		args		call=.variable() recolor=-1
	"\""		qargs		recolor=-1
	"'"		sqargs		recolor=-1		# These two encountered in 
	"`"		bqargs		recolor=-1		# certain varieties of for-loops

:stmtorcommand Command
	*		command		noeat istrings
	"call"		stmt
	"cd"		stmt
	"chdir"		stmt
	"cls"		stmt
	"copy"		stmt
	"del"		stmt
	"dir"		stmt
	"echo"		echostmt
	"echo."		echostmt
	"endlocal"	stmt
	"erase"		stmt
	"exit"		stmt
	"for"		cond
	"goto"		loop
	"if"		cond
	"move"		stmt
	"pause"		stmt
	"popd"		stmt
	"pushd"		stmt
	"rd"		stmt
	"rem"		comment
	"ren"		stmt
	"rename"	stmt
	"rmdir"		stmt
	"set"		stmt
	"setlocal"	stmt
	"setx"		stmt
	"shift"		stmt
	"sleep"		stmt
	"start"		stmt
	"type"		stmt
	"xcopy"		stmt
done
	"a-zA-Z."	stmtorcommand
	"\"\\_0-9"	command
	")"		rparen		recolor=-1

:labelorcomment Idle
	*		label		recolor=-2
	":"		comment		recolor=-2

:label Label
	*		label
	"\r\n"		reset

:comment Comment comment
	*		comment
	"BFHNTX"        comment		noeat call=comment_todo.comment_todo()
	"\r\n"		reset

:loop Loop
	*		args		noeat

:cond Conditional
	*		args		noeat

:stmt Statement
	*		args		noeat

:echostmt Statement
	*		echoargs	noeat

:echoargs String string
	*		echoargs
	"%"		echoargs	call=.strvariable() recolor=-1
	"&"		and		recolor=-1
	">|"		reset		recolor=-1
	"\r\n"		reset

:command Command
	*		command
	"\""		qcommand
	" \t"		args
	"\r\n"		reset

:qcommand Command
	*		qcommand
	"\""		command
	"\r\n"		reset

:args Idle
	*		args
	"%"		args		call=.variable() recolor=-1
	"("		lparen		recolor=-1
	")"		rparen		recolor=-1
	"\r\n"		reset
	"\""		qargs		recolor=-1
	"&"		and		recolor=-1

# Double-quoted args
:qargs String string
	*		qargs
	"\""		args
	"%"		qargs		call=.strvariable() recolor=-1
	"\r\n"		reset

# Single-quoted args
:sqargs String string
	*		sqargs
	"'"		args
	"%"		sqargs		call=.strvariable() recolor=-1
	"\r\n"		reset

# Back-quoted (`) args, found in some for-loops
:bqargs String string
	*		bqargs
	"`"		args
	"%"		bqargs		call=.strvariable() recolor=-1
	"\r\n"		reset

:and Idle
	"&"		and
	*		reset		noeat

:lparen Brace
	*		linebegin	noeat

:rparen Brace
	*		args		noeat

.subr variable

:variable Variable
	*		args		noeat return
	"%~"		shortvar
	"\*"		noeat		return
	"0-9"		variable	return
	"A-Za-z_"	varbody

:shortvar Variable
	*		args		noeat return
	"A-Za-z0-9_"	shortvar

:varbody Variable
	*		varbody
	"%"		args		return

.end

.subr strvariable

:variable StringVariable string
	*		args		noeat return
	"%~"		shortvar
	"\*"		noeat		return
	"0-9"		variable	return
	"A-Za-z_"	varbody

:shortvar StringVariable string
	*		args		noeat return
	"A-Za-z0-9_"	shortvar

:varbody StringVariable string
	*		varbody
	"%"		args		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.