//------------------------------------------------ //--- 010 Editor v9.0 Binary Template // // File: G.bt // Authors: Inidimus // Version: 1.0 // Purpose: Syntax highlighting for G files. These are // G-code files with additional features suggested // by RepRap.org. // Category: Syntax // File Mask: *.g // ID Bytes: // History: // 1.0 2021-12-12 Inidimus: Initial version. // // See https://reprap.org/wiki/RepRap_Firmware_G-Codes // https://reprap.org/wiki/Updating_RepRap_Firmware_config.g_file //------------------------------------------------ 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 stringStyle = HighlightFindStyle( "code-string" ); local int dataTypeStyle = HighlightFindStyle( "code-data-type" ); local int dataTagStyle = HighlightFindStyle( "tag-data" ); local int attrStyle = HighlightFindStyle( "tag-attribute" ); // Types of rules we may be applying that may span multiple lines const int RULE_NONE = 0; const int RULE_MULTILINE_COMMENT = 1; const int RULE_SQUAREBRACKETS = 2; const int RULE_CURVEBRACKETS = 3; const int RULE_STRING = 4; const int RULE_MULTILINE_STRING = 5; // Build list of keywords // Build list of datatypes int isDig( char c ) { return IsCharNumW(c); } int isCommandChar( char c ) { int p = Strchr("MmGgOo", c ); if ( p==-1 ) return 0; else return 1; } int goodPrev( char c ) { int p = Strchr(" -+*/(}{$=<>,[", c ); if ( p==-1 ) return 0; else return 1; } int goodParam( char c1, char c2, char c3 ) { if (IsCharWhitespace(c1) && IsCharAlpha(c2) && (IsCharNum(c3)||(c3='"'))) return 1; else return 0; } // 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, n, rule = flags; int hex; while( i < count ) { // Check single-line comments: ; Sensors for thermal fans if( (text[i] == ';') && HighlightCheckCommentRule( text, count, ";", i, foreColors, backColors, commentStyle ) ) continue; // 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 multi-line string - could be continued from a previous line: M308 S3 Y"mcu-temp" A"MCUTemp" if( (text[i] == '"' || rule == RULE_MULTILINE_STRING) && HighlightCheckMultiLineRule( text, count, "\"", "\"", i, rule, RULE_NONE, RULE_MULTILINE_STRING, foreColors, backColors, stringStyle ) ) continue; if( (text[i] == '%') && (i==0)) { HighlightApplyStyle( foreColors, backColors, i, 1, keywordStyle ); i++; continue; } // Check M,G commands: M308 S1 if( (isCommandChar(text[i])==1) && ((i==0)||(goodPrev(text[i-1])==1)) ) { n = 0; while (i+n < count) { if ( (n>0)&&(isDig(text[i+n])!=1) ) break; n++; } if( n > 1 ) { HighlightApplyStyle( foreColors, backColors, i, n, keywordStyle ); i += n; continue; } } //Check parameter: X80.00 Y80.00 Z397.44 E811.62 if( (i>0)&&(i