//------------------------------------------------ //--- 010 Editor v9.0 Binary Template // // File: JavaScript.bt // Authors: SweetScape Software // Version: 1.0 // Purpose: Syntax highlighting for JavaScript files. // Category: Syntax // File Mask: *.js,*.jsm // ID Bytes: // History: // 1.0 2018-11-01 SweetScape Software: Initial version. //------------------------------------------------ RequiresVersion( 9 ); // To save memory, allow a single copy of this template to provide // syntax highlighting for all open files that match the file mask. HighlightAllowInstanceSharing( true ); // Get list of coloring styles local int commentStyle = HighlightFindStyle( "code-comment" ); local int keywordStyle = HighlightFindStyle( "code-keyword" ); local int dataTypeStyle = HighlightFindStyle( "code-data-type" ); local int stringStyle = HighlightFindStyle( "code-string" ); // Types of rules we may be applying that may span multiple lines const int RULE_NONE = 0; const int RULE_MULTILINE_COMMENT = 1; // Build list of keywords local TKeywordList keywordList = HighlightBuildKeywordList( HIGHLIGHT_WHOLEWORD, "abstract", "arguments", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "void", "volatile", "while", "with", "yield" ); // Build list of datatypes local TKeywordList dataTypeList = HighlightBuildKeywordList( HIGHLIGHT_WHOLEWORD, "var" ); // Main function to apply syntax highlighting to a line of text. // flags is preserved between lines and allows us to do multi-line comments. void HighlightLineRealtime( int64 line, wchar_t text[], int foreColors[], int backColors[], int count, ushort &flags ) { int i, len, pos, rule = flags; while( i < count ) { // Check multi-line comment - could be continued from a previous line if( (text[i] == '/' || rule == RULE_MULTILINE_COMMENT) && HighlightCheckMultiLineRule( text, count, "/*", "*/", i, rule, RULE_NONE, RULE_MULTILINE_COMMENT, foreColors, backColors, commentStyle ) ) continue; // Check single-line comments if( (text[i] == '/') && HighlightCheckCommentRule( text, count, "//", i, foreColors, backColors, commentStyle ) ) continue; // Check single-line string if( (text[i] == '\"') && HighlightCheckSingleLineRule( text, count, "\"", "\"", i, foreColors, backColors, stringStyle, HIGHLIGHT_CSTRING ) ) continue; // Check character constant if( (text[i] == '\'') && HighlightCheckSingleLineRule( text, count, "\'", "\'", i, foreColors, backColors, stringStyle, HIGHLIGHT_CSTRING ) ) continue; // Check keywords if( HighlightCheckKeywordRule( text, count, keywordList, i, foreColors, backColors, keywordStyle ) ) continue; // Check data types if( HighlightCheckKeywordRule( text, count, dataTypeList, i, foreColors, backColors, dataTypeStyle ) ) continue; // Nothing found - skip over whole words i = HighlightGetNextToken( text, count, i ); } // Save rule in the flags for the next line flags = rule; }