# This file is intended to cover everything that is common
# among the markup languages XML and HTML (pre-XHTML)
# 
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
# 
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
# 
# The Original Code is Komodo code.
# 
# The Initial Developer of the Original Code is ActiveState Software Inc.
# Portions created by ActiveState Software Inc are Copyright (C) 2000-2007
# ActiveState Software Inc. All Rights Reserved.
# 
# Contributor(s):
#   ActiveState Software Inc
# 
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
# 
# ***** END LICENSE BLOCK *****
# Author(s):
#   Eric Promislow <ericp@activestate.com>

family markup

pattern CS = '-\w\d._\x80-\xff'
pattern WS = '\s\t\r\n'

# \z in a pattern means end-of-buffer
# currently patterns with '\z' may contain only \z

initial IN_M_DEFAULT

# Unrecognized state names (starting with "IN_") are interned as
# small state numbers, and have nothing to do with colors.

state IN_M_DEFAULT:
'<?' : paint(upto, M_DEFAULT), => IN_M_PI_1
'<![CDATA[' : paint(upto, M_DEFAULT), => IN_M_CDATA

# Handle "downlevel" conditional comments with hidden HTML
# Ref (as of 2007-04-11):
# http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/ccomment_ovw.asp
/<!--\[if\s[^\[\]]+\]>/ : paint(upto, M_DEFAULT), paint(include, M_COMMENT)
/<!\[endif\s*\]\s*-->/ : paint(upto, M_DEFAULT), paint(include, M_COMMENT)

# And regular comments go here
'<!--' : paint(upto, M_DEFAULT), => IN_M_COMMENT

# These are more complicated, because if they aren't followed
# by a character we want to leave them as text.

'</' : paint(upto, M_DEFAULT), paint(include, M_ETAGO), => IN_M_ETAG_1
'&#' : paint(upto, M_DEFAULT), => IN_M_ENT_CREF_1
'&' : paint(upto, M_DEFAULT), => IN_M_ENT_REF_1
'<' : paint(upto, M_DEFAULT), => IN_M_STAG_EXP_TNAME

# This state is a placeholder for transition modules,
# like html2php, to hook on

state IN_M_PI_1:
/[$CS][:$CS]*/ : paint(include, M_PI), => IN_M_PI_2
/./ : paint(upto, M_PI), redo, => IN_M_PI_2

# Color instances of <name>=<value> as
# SCE_UDL_M_ATTRNAME, M_OPERATOR, M_STRING
# Color whitespace as M_TAGSPACE
# Color the "?>" as M_PI
# Color everything else as M_PI

state IN_M_PI_2:
'?>' : paint(include, M_PI) => IN_M_DEFAULT
/[$WS]+/ : #stay
/[$CS][:$CS]*/ : paint(upto, M_PI), => IN_M_PI_IN_ATTRNAME_1
/\z/ : paint(include, M_PI) 

# /[$CS][:$CS]*(?=[$WS]*=)/ : paint(upto, M_PI), paint(include, M_ATTRNAME), => IN_M_PI_POST_ATTRNAME_1
# Watch out for names at the end of a line
# /[$CS][:$CS]*(?=\r?$)/ : paint(upto, M_PI), paint(include, M_ATTRNAME), => IN_M_PI_IN_ATTRNAME_1

# 
state IN_M_PI_IN_ATTRNAME_1:
/[$WS]*(?==)/ : paint(upto, M_ATTRNAME), => IN_M_PI_POST_ATTRNAME_1
# Concession: color name at the end of a line as an attrname even if it
# isn't eventually followed by an '='
/\r?\n?$/ : paint(upto, M_ATTRNAME), => IN_M_PI_POST_ATTRNAME_1
/./ : paint(upto, M_PI), redo => IN_M_PI_2

# This state allows for [name]=... to span multiple lines
state IN_M_PI_POST_ATTRNAME_1:
/[$WS]+/ : #stay
# Make sure the '=' is followed by something
/=(?=[^\r\n])/ : paint(upto, M_PI), paint(include, M_OPERATOR) => IN_M_PI_POST_ATTRNAME_2
/./ : paint(upto, M_PI), redo => IN_M_PI_2
/\z/ : paint(include, M_PI) 

state IN_M_PI_POST_ATTRNAME_2:
'?>' : paint(include, M_PI) => IN_M_DEFAULT
'\"' : paint(upto, M_PI), => IN_M_PI_ATTR_DSTRING
'\'' : paint(upto, M_PI), => IN_M_PI_ATTR_SSTRING
/[^$WS]/ : paint(upto, M_PI), => IN_M_PI_ATTR_USTRING

state IN_M_PI_ATTR_DSTRING:
'?>' : paint(upto, M_STRING), paint(include, M_PI) => IN_M_DEFAULT
'"' : paint(include, M_STRING), => IN_M_PI_2
/\z/ : paint(upto, M_STRING)

state IN_M_PI_ATTR_SSTRING:
'?>' : paint(upto, M_STRING), paint(include, M_PI) => IN_M_DEFAULT
"'" : paint(include, M_STRING), => IN_M_PI_2
/\z/ : paint(upto, M_STRING)

state IN_M_PI_ATTR_USTRING:
'?>' : paint(upto, M_STRING), paint(include, M_PI) => IN_M_DEFAULT
/[$WS]+/ : paint(upto, M_STRING), => IN_M_PI_2
/\z/ : paint(upto, M_STRING)

state IN_M_CDATA:
']]>' : paint(include, M_CDATA) => IN_M_DEFAULT

state IN_M_COMMENT:
'-->' : paint(include, M_COMMENT) => IN_M_DEFAULT

state IN_M_STAG_EXP_TNAME:
/[$CS]/ : paint(upto, M_STAGO), => IN_M_STAG_IN_TAGNAME_1
/./  : paint(upto, M_DEFAULT), redo => IN_M_DEFAULT  # </ not followed by a tagname
/\z/ : paint(upto, M_DEFAULT)

state IN_M_STAG_IN_TAGNAME_1:
':' : => IN_M_STAG_IN_TAGNAME_2
/[^$CS]/ : paint(upto, M_TAGNAME), redo, => IN_M_STAG_POST_TAGNAME

state IN_M_STAG_IN_TAGNAME_2:
':' : => IN_M_STAG_IN_TAGNAME_2
/[^$CS]/ : paint(upto, M_TAGNAME), redo, => IN_M_STAG_POST_TAGNAME

state IN_M_STAG_POST_TAGNAME:
'>' : paint(upto, M_TAGSPACE), paint(include, M_STAGC) => IN_M_DEFAULT
'/>' : paint(upto, M_TAGSPACE), paint(include, M_EMP_TAGC) => IN_M_DEFAULT
'<' : paint(upto, M_TAGSPACE), redo => IN_M_DEFAULT
/[$CS]/ :    paint(upto, M_TAGSPACE) => IN_M_STAG_IN_ATTRNAME

state IN_M_STAG_IN_ATTRNAME
':' : #stay
/[^$CS]/ :  paint(upto, M_ATTRNAME), redo, => IN_M_STAG_POST_ATTRNAME_1

state IN_M_STAG_POST_ATTRNAME_1
'=' : paint(upto, M_TAGSPACE), paint(include, M_OPERATOR) => IN_M_STAG_POST_ATTRNAME_2
/[^$WS]/ : paint(upto, M_TAGSPACE), redo => IN_M_STAG_POST_TAGNAME

#****************************************************************
# NOTE:
# 
# Clients that use this file have to specify what to do in
# IN_M_STAG_POST_ATTRNAME_2 when an unquoted attribute value
# is detected.
#****************************************************************

state IN_M_STAG_POST_ATTRNAME_2
'\"' : paint(upto, M_TAGSPACE), => IN_M_STAG_ATTR_DSTRING
'\'' : paint(upto, M_TAGSPACE), => IN_M_STAG_ATTR_SSTRING
'>' : paint(upto, M_TAGSPACE), paint(include, M_STAGC), => IN_M_DEFAULT
'/>' : paint(upto, M_TAGSPACE), paint(include, M_EMP_TAGC), => IN_M_DEFAULT

state IN_M_STAG_ATTR_DSTRING:
'"' : paint(include, M_STRING), => IN_M_STAG_POST_TAGNAME
# Assume a < means we're way out of sync
'<'    : paint(upto, M_STRING), => IN_M_STAG_EXP_TNAME

state IN_M_STAG_ATTR_SSTRING:
'\'' : paint(include, M_STRING), => IN_M_STAG_POST_TAGNAME
# Assume a < means we're way out of sync
'<'    : paint(upto, M_STRING), => IN_M_STAG_EXP_TNAME

state IN_M_ETAG_1:
':' : #stay
/[^$CS]/ : paint(upto, M_TAGNAME), redo, => IN_M_ETAG_3

state IN_M_ETAG_3:
/[$WS]+/ : #stay
'>' : paint(upto, M_TAGSPACE), paint(include, M_ETAGC) => IN_M_DEFAULT
/./ : paint(upto, M_TAGSPACE), redo => IN_M_DEFAULT

state IN_M_ENT_CREF_1:
'x' : => IN_M_ENT_CREF_HEX_1
';'  : paint(include, M_ENTITY), => IN_M_DEFAULT
/\z/   : paint(upto, M_DEFAULT)
/[^0-9;x]/ : paint(upto, M_ENTITY), redo, => IN_M_DEFAULT # Give up

state IN_M_ENT_CREF_HEX_1:
';'  : paint(include, M_ENTITY), => IN_M_DEFAULT
/[^0-9a-fA-F]/ : paint(upto, M_ENTITY), redo,  => IN_M_DEFAULT

state IN_M_ENT_REF_1:
';'  : paint(include, M_ENTITY), => IN_M_DEFAULT
/[^$CS]/ : paint(upto, M_ENTITY), redo, => IN_M_DEFAULT

################ Fold info

# Markup -- look at the end of the tag to determine fold levels

fold ">" M_STAGC +
fold ">" M_ETAGC -

fold "<!--" M_COMMENT +
fold "-->" M_COMMENT -

fold "{{{" M_COMMENT +
fold "}}}" M_COMMENT -

fold "<?" M_PI +
fold "?>" M_PI -

# lineup * M_TAGNAME 

