'*******************************************************************************
' $Log9: C:\Archive\Versions\Programs\EverEdit\syntax\nodebrain.nbd $
' 
'   EverEdit syntax file for NodeBrain 0.6.5.
' 
' Revision 1.22  by: Roman Mishin  Rev date: 2014-10-02 14:18:50
'   Recognize Cell near to 'not' and comma.
' 
' Revision 1.21  by: Roman Mishin  Rev date: 2014-09-30 08:44:16
'   Add 'not' to Operator. Recognize Cell near to 'assert'. Add Time
'   Expression to the top level.
' 
' Revision 1.20  by: Roman Mishin  Rev date: 2014-09-24 08:56:11
'   Fix: Multiline strings are not allowed.
' 
' Revision 1.19  by: Roman Mishin  Rev date: 2014-09-22 13:27:05
'   Add semicolon as another boundary match for the end of Servant region.
'   This allows Comment highlight after Servant.
' 
' Revision 1.18  by: Roman Mishin  Rev date: 2014-09-21 11:07:11
'   Use region instead of item to highlight Expert Tree. Highlight Time
'   Expression.
' 
' Revision 1.17  by: Roman Mishin  Rev date: 2014-09-20 13:59:49
'   Highlight Parenthesized Expression.
' 
' Revision 1.16  by: Roman Mishin  Rev date: 2014-09-20 10:45:23
'   Add more items to some regions. Improve Cell recognition in Condition.
' 
' Revision 1.15  by: Roman Mishin  Rev date: 2014-09-20 10:11:41
'   Extract all items, regions and words into separate named definitions. 
'   Decouple creation from addition.
' 
' Revision 1.14  by: Roman Mishin  Rev date: 2014-09-19 20:00:59
'   Create separate region for Condition. Define Sequence region.
' 
' $Endlog$
'*******************************************************************************

Include( ".\const.mac" )

Set nb = Parser.CreateParser()

nb.SetPairs( "[]{}()""""''" )
nb.CommentLine( "# " )

Set rComment1 = nb.CreateRegion( COLOR_COMMENT1, "^\s*#", "$", True )
Set rComment2 = nb.CreateRegion( COLOR_COMMENT2, "+;+", "$", True )
Set iToDo = nb.CreateItem( COLOR_HIGHLIGHT1, "\b(TODO|FIX|FIXME|TBD)\b", False )
Set rString = nb.CreateStringRegion( COLOR_STRING2, """", "", False, "" )
Set rQuotedTerm = nb.CreateStringRegion( COLOR_STRING2, "'", "", False, "" )
Set iNumber = nb.CreateItem( COLOR_NUMBER, "(?<!\w)[-+]?\d+(\.\d+)?", True )
Set iOperator = nb.CreateItem( COLOR_OPERATOR, "\-|\+|\*|/|\\|=|==|\||<|>|&|:|,|\^|`|~|?|!|\b(and|or)\b|\bnot\b", True )
Set iUnknown = nb.CreateItem( COLOR_HIGHLIGHT6, "\?\?", True )
Set iReduce = nb.CreateItem( COLOR_WORD2, "\$(?= )", True )
Set rSymbolicSubstitution2 = nb.CreateRegion( COLOR_VAR, "\$+(\{|\(|\[)", "(\}|\)|\])", True )
Set rSymbolicSubstitution3 = nb.CreateRegion( COLOR_VAR, "%{1,2}\{", "\}", True )
Set iSymbolicSubstitution1 = nb.CreateItem( COLOR_VAR, "(\$|%)\w+", True )
Set iObjectType = nb.CreateItem( COLOR_WORD1, "(?<=\s+)(brain|identity|calendar|module|skill|cell|expert|file|listener|macro|nerve|translator)", True )
Set wCommand = nb.CreateWord( COLOR_FUNCTION, "address alert archive assert copy consult declare define disable enable exit forecast identify pipe portray rank set show solve source stop undefine use windows createService startService stopService deleteService", True, "" )
Set iDirective = nb.CreateItem( COLOR_MACRO, "(?<=^\s*)%(assert|default|if|elseif|else|endif|include|quit)(?=\s+)", True )
Set iCell1 = nb.CreateItem( COLOR_VAR, "\$+(\{|\(|\[)?@?[\.|\w]+(\}|\)|\])?", True )
Set iCell2 = nb.CreateItem( COLOR_VAR, "(?<!^\s*)%{1,2}\{?@?[\.|\w]+\}?", True )
Set iCell3 = nb.CreateItem( COLOR_VAR, "\w+(?=\s*(cell|;|=|+|-|*|/|<|>|\s+(and|or|not)\s+))", True )
Set iCell4 = nb.CreateItem( COLOR_VAR, "(?<=(=|+|-|*|/|<|>|\s+(and|or|not)\s+|(^|\)\s*:)\s*((@|\w+)\.)*\s*(set|alert|assert)\s+)\s*((@|\w+)\.)*)\w+", True )
Set iCell5 = nb.CreateItem( COLOR_VAR, "(?<=(\)|,)\s*((@|\w+)\.)*)\w+(?=\s*($|,))", True )
Set iCell6 = nb.CreateItem( COLOR_VAR, "(?<=((@|\w+)\.)*)\w+(?=\s*\))", True )
Set rTimeExpression = nb.CreateRegion( COLOR_HIGHLIGHT3, "~\(", "\)", True )
Set rParenthesizedTimeExpression = nb.CreateRegion( COLOR_HIGHLIGHT3, "(?<!~)\(", "\)", True )
Set rConditon = nb.CreateRegion( COLOR_WORD4, "(on|onif|if|when)\s*\(", "\)", True )
Set iRule = nb.CreateItem( COLOR_WORD4, "\w+(?=\s+(on|onif|if|when)\s*\()", True )
Set iPriority = nb.CreateItem( COLOR_HIGHLIGHT7, "(?<=\)\s*)\[-?\d{1,3}\](?=\s*(:|@|\w+|\.))", True )
Set iContext = nb.CreateItem( COLOR_WORD3, "((@|\w+|\.+)\.)+", True )
Set iExpert = nb.CreateItem( COLOR_WORD3, "\w+(?=\s+expert)", True )
Set rExpertTree = nb.CreateRegion( COLOR_VAR, "(?!(on|onif|if|when)\s*\()\b\w+\(", "\)", True )
Set iObject = nb.CreateItem( COLOR_HIGHLIGHT2, "\w+(?=\s+(file|listener|nerve|translator))", True )
Set iSpecialObject1 = nb.CreateItem( COLOR_HIGHLIGHT6, "\w+(?=\s+(brain|identity|calendar|module|skill))", True )
Set iSpecialObject2 = nb.CreateItem( COLOR_HIGHLIGHT6, "(?<=portray\s+)\w+", True )
Set iSpecialObject3 = nb.CreateItem( COLOR_HIGHLIGHT6, "(?<=address\s+>\s*((@|\w+)\.)*)\w+", True )
Set iMacro = nb.CreateItem( COLOR_MACRO, "\w+(?=\s+macro)", True )
Set iAddress = nb.CreateItem( COLOR_HIGHLIGHT4, "(?<=address\s+)>(?=\s*((@|\w+)\.)*\w+)", True )
Set rServant = nb.CreateRegion( COLOR_DEFAULT, "(?<=:\s*(\$\s+)?(((@|\w+)\.)+\s+)?)(-|=)", "((?=;)|$)", True )
Set iServantCommand = nb.CreateItem( COLOR_MACRO, "(?<=:\s*(\$\s+)?(((@|\w+)\.)+\s+)?)(-|=)", True )
Set iShellCommand = nb.CreateItem( COLOR_FUNCTION, "(?<=:\s*(\$\s+)?(((@|\w+)\.)+\s+)?(-|=)\s*[^\w]?\s*)(""[^""]+""|[^""\s]+)", True )
Set iShellParameter = nb.CreateItem( COLOR_TAG, "-\w+", True )
Set iOutputRedirect1 = nb.CreateItem( COLOR_HIGHLIGHT4, "(\d?(<|>{1,2})(&\d)?|\|{1,2}|&{1,2})", True )
Set iOutputRedirect2 = nb.CreateItem( COLOR_HIGHLIGHT4, "(?<=:\s*(\$\s+)?(((@|\w+)\.)+\s+)?(-|=)\s*)([!|%:]\s*)?>{1,2}\s*(""[^""]+""|[^""\s]+)(\s*[!|%:])?", True )
Set iOutputRedirect3 = nb.CreateItem( COLOR_HIGHLIGHT4, "(?<=:\s*(\$\s+)?(((@|\w+)\.)+\s+)?(-|=)\s*)[!|%:](\s*[!|%:])?", True )
Set rSequence = nb.CreateRegion( COLOR_DEFAULT, "{", "}", True )
Set iCommandTerminator = nb.CreateItem( COLOR_COMMENT2, ";", True )
Set rParenthesizedExpression = nb.CreateRegion( COLOR_DEFAULT, "(?<!(on|onif|if|when)\s*|\w)\(", "\)", True )

rComment1.AddItem( iToDo )
rComment2.AddItem( iToDo )
rSymbolicSubstitution2.AddItem( iContext )
rSymbolicSubstitution3.AddItem( iContext )
rString.AddItem( iSymbolicSubstitution1 )
rString.AddRegion( rSymbolicSubstitution2 )
rString.AddRegion( rSymbolicSubstitution3 )
rParenthesizedExpression.AddItem( nb.CreateItem( COLOR_VAR, "((@|\w+)\.)*\w+", True ) )
rParenthesizedExpression.AddItem( iCell1 )
rParenthesizedExpression.AddItem( iCell2 )
rParenthesizedExpression.AddItem( iCell3 )
rParenthesizedExpression.AddItem( iCell4 )
rParenthesizedExpression.AddItem( iCell5 )
rParenthesizedExpression.AddItem( iCell6 )
rParenthesizedExpression.AddItem( iContext )
rParenthesizedExpression.AddItem( iNumber )
rParenthesizedExpression.AddItem( iOperator )
rParenthesizedExpression.AddItem( iUnknown )
rParenthesizedExpression.AddRegion( rQuotedTerm )
rParenthesizedExpression.AddRegion( rString )
rParenthesizedExpression.AddRegion( rExpertTree )
rParenthesizedExpression.AddRegion( rSymbolicSubstitution2 )
rParenthesizedExpression.AddRegion( rSymbolicSubstitution3 )
rParenthesizedExpression.AddRegion( rTimeExpression )
rTimeExpression.AddRegion( rParenthesizedTimeExpression )
rConditon.AddItem( iCell1 )
rConditon.AddItem( iCell2 )
rConditon.AddItem( iCell3 )
rConditon.AddItem( iCell4 )
rConditon.AddItem( iCell5 )
rConditon.AddItem( iCell6 )
rConditon.AddItem( iContext )
rConditon.AddItem( iNumber )
rConditon.AddItem( iOperator )
rConditon.AddItem( iUnknown )
rConditon.AddItem( nb.CreateItem( COLOR_DEFAULT, "\s+", True ) )
rConditon.AddRegion( rQuotedTerm )
rConditon.AddRegion( rString )
rConditon.AddRegion( rExpertTree )
rConditon.AddRegion( rSymbolicSubstitution2 )
rConditon.AddRegion( rSymbolicSubstitution3 )
rConditon.AddRegion( rParenthesizedExpression )
rConditon.AddRegion( rTimeExpression )
rServant.AddItem( iNumber )
rServant.AddItem( iServantCommand )
rServant.AddItem( iShellCommand )
rServant.AddItem( iShellParameter )
rServant.AddRegion( rString )
rServant.AddRegion( rSymbolicSubstitution2 )
rServant.AddRegion( rSymbolicSubstitution3 )
rServant.AddItem( iOutputRedirect1 )
rServant.AddItem( iOutputRedirect2 )
rServant.AddItem( iOutputRedirect3 )
rSequence.AddItem( iCell1 )
rSequence.AddItem( iCell2 )
rSequence.AddItem( iCell3 )
rSequence.AddItem( iCell4 )
rSequence.AddItem( iCell5 )
rSequence.AddItem( iContext )
rSequence.AddItem( iDirective )
rSequence.AddItem( iExpert )
rSequence.AddItem( iNumber )
rSequence.AddItem( iOperator )
rSequence.AddItem( iUnknown )
rSequence.AddItem( iCommandTerminator )
rSequence.AddWord( wCommand )
rSequence.AddRegion( rConditon )
rSequence.AddRegion( rQuotedTerm )
rSequence.AddRegion( rString )
rSequence.AddRegion( rExpertTree )
rSequence.AddRegion( rSymbolicSubstitution2 )
rSequence.AddRegion( rSymbolicSubstitution3 )
rSequence.AddRegion( rTimeExpression )
nb.AddItem( iAddress )
nb.AddItem( iCell1 )
nb.AddItem( iCell2 )
nb.AddItem( iCell3 )
nb.AddItem( iCell4 )
nb.AddItem( iCell5 )
nb.AddItem( iContext )
nb.AddItem( iDirective )
nb.AddItem( iExpert )
nb.AddItem( iMacro )
nb.AddItem( iNumber )
nb.AddItem( iObject )
nb.AddItem( iObjectType )
nb.AddItem( iOperator )
nb.AddItem( iPriority )
nb.AddItem( iReduce )
nb.AddItem( iRule )
nb.AddItem( iSpecialObject1 )
nb.AddItem( iSpecialObject2 )
nb.AddItem( iSpecialObject3 )
nb.AddItem( iUnknown )
nb.AddWord( wCommand )
nb.AddRegion( rComment1 )
nb.AddRegion( rComment2 )
nb.AddRegion( rConditon )
nb.AddRegion( rQuotedTerm )
nb.AddRegion( rSequence )
nb.AddRegion( rServant )
nb.AddRegion( rString )
nb.AddRegion( rExpertTree )
nb.AddRegion( rSymbolicSubstitution2 )
nb.AddRegion( rSymbolicSubstitution3 )
nb.AddRegion( rParenthesizedExpression )
nb.AddRegion( rTimeExpression )
