Code character highlight display method and device, electronic equipment and readable storage medium

By loading the configuration file and responding to the highlighting trigger condition, determining the code area and highlighting it, the problems of high resource consumption and high technical requirements in the existing technology are solved, and flexible and simple code highlighting is achieved.

CN119576299APending Publication Date: 2025-03-07FUTAIHUA PRECISION ELECTRONICS (ZHENGZHOU) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411765623.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-03
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

The prior art requires additional computer resources in code highlighting, and the plug-in quality is different, resulting in performance impact, and requires high requirements for technicians, so they need to learn TextMate syntax.

Method used

By loading a preset configuration file, responding to character highlighting trigger conditions, determining the measured code area in the target code file, and highlighting the target characters according to the highlighting rules in the configuration file.

Benefits of technology

It realizes flexible and simple code highlighting, which reduces the consumption of computer resources, improves the implementation efficiency and speed of the solution, and reduces the requirements for technicians.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576299A_ABST
    Figure CN119576299A_ABST
Patent Text Reader

Abstract

The invention discloses a code character highlight display method and device, electronic equipment and a readable storage medium, and is applied to the technical field of computers. According to the invention, hit and highlight display of the code characters are realized based on the configuration file. The configuration file is provided with a highlight display rule used for hit and highlight display of characters in a tested code area, and the highlight display rule can be used for real-time highlight display of the code file as a configuration item; the configuration file is easy to implement, TextMate grammar does not need to be learned, and loading of the configuration file is lighter, so that the code characters are highlighted by loading the configuration file, the consumed computer resources are few, the scheme implementation efficiency is high, and the scheme implementation speed is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a code character highlighting display method, a code character highlighting display device, an electronic device and a computer-readable storage medium. Background Art

[0002] Currently, after VSCode defines the rules for code highlighting based on TextMate syntax, it can organize the rules into a JSON structure in a specific format, and then load this JSON structure as a plug-in in the code editor to highlight the hit elements of the corresponding code file in the code editor. However, since plug-ins require additional computer resources to run and the quality of plug-ins varies, VSCode needs to perform computationally intensive processing for complex grammar rules and regular expressions, which may affect performance. TextMate syntax also requires relevant personnel to learn in advance, which places high demands on technical personnel. Summary of the invention

[0003] In view of this, the purpose of the present application is to provide a code character highlighting method, a code character highlighting device, an electronic device and a computer-readable storage medium to achieve flexible and simple code highlighting.

[0004] In order to solve the above technical problems, the present application provides a code character highlighting method, comprising:

[0005] In response to a character highlighting trigger condition, loading a preset configuration file;

[0006] Determine at least one tested code region in the target code file according to the configuration file;

[0007] If the highlighting rule for the target code file in the configuration file matches the target character in the tested code area, the target character is highlighted according to the highlighting rule.

[0008] Optionally, in response to the character highlighting trigger condition, loading a preset configuration file includes:

[0009] If it is detected that the target code file is in an editing state, and / or a character highlighting instruction for the target code file is detected, the character highlighting triggering condition is generated, and the preset configuration file is loaded.

[0010] Optionally, the step of determining at least one tested code region in the target code file according to the configuration file includes:

[0011] The tested code region in the target code file is determined based on the regular expressions representing the region start position and the region end position in the configuration file.

[0012] Optionally, highlighting the target character according to the highlighting rule includes:

[0013] Obtaining a target grammatical element category corresponding to the target character;

[0014] According to the configuration file, obtaining a target coloring rule regular expression corresponding to the target syntax element category;

[0015] The target characters are grammatically colored based on the target coloring rule regular expression.

[0016] Optionally, the target syntax element category includes a keyword category, an identifier category, an operator category, a literal category or a separator category.

[0017] Optionally, after determining at least one tested code region in the target code file according to the configuration file, the method further includes:

[0018] If the automatic line break and indentation symbol defined in the configuration file is detected in the tested code area, automatic line break and indentation are implemented after the automatic line break and indentation symbol in the tested code area.

[0019] Optionally, after determining at least one tested code region in the target code file according to the configuration file, the method further includes:

[0020] If a running breakpoint is detected during the running of the tested code area, the execution of the target code file is suspended, and the suspension position and the running area are marked.

[0021] The present application also provides a code character highlighting display device, comprising:

[0022] A loading module, used for loading a preset configuration file in response to a character highlighting trigger condition;

[0023] A determination module, used to determine at least one tested code region in the target code file according to the configuration file;

[0024] The display module is used for highlighting the target character according to the highlighting rule when the highlighting rule for the target code file in the configuration file hits the target character in the tested code area.

[0025] Optionally, the loading module is specifically used for:

[0026] If it is detected that the target code file is in an editing state, and / or a character highlighting instruction for the target code file is detected, the character highlighting triggering condition is generated, and the preset configuration file is loaded.

[0027] Optionally, the determining module is specifically used to:

[0028] The tested code region in the target code file is determined based on the regular expressions representing the region start position and the region end position in the configuration file.

[0029] Optionally, the display module is specifically used for:

[0030] Obtaining a target grammatical element category corresponding to the target character;

[0031] According to the configuration file, obtaining a target coloring rule regular expression corresponding to the target syntax element category;

[0032] The target characters are grammatically colored based on the target coloring rule regular expression.

[0033] Optionally, the target syntax element category includes a keyword category, an identifier category, an operator category, a literal category or a separator category.

[0034] Optionally, the device further comprises:

[0035] An automatic line break and indentation module is used to, after determining at least one code area under test in a target code file according to the configuration file, if an automatic line break and indentation symbol defined in the configuration file is detected in the code area under test, implement automatic line break and indentation after the automatic line break and indentation symbol in the code area under test.

[0036] Optionally, the device further comprises:

[0037] The automatic interrupt module is used to determine at least one tested code area in the target code file according to the configuration file, and if a running breakpoint is detected during the running of the tested code area, the execution of the target code file is suspended, and the suspension position and the running area are marked.

[0038] The present application also provides an electronic device, including a memory and a processor, wherein:

[0039] The memory is used to store the computer program;

[0040] The processor is used to execute the computer program to implement the above-mentioned code character highlighting method.

[0041] The present application also provides a computer-readable storage medium for storing a computer program, wherein the computer program implements the above-mentioned code character highlighting method when executed by a processor.

[0042] The code character highlighting method provided in the present application includes: loading a preset configuration file in response to a character highlighting trigger condition; determining at least one tested code area in a target code file based on the configuration file; if the highlighting rule for the target code file in the configuration file hits a target character in the tested code area, highlighting the target character according to the highlighting rule.

[0043] It can be seen that the present application implements the hitting and highlighting of code characters based on the configuration file. When the character highlighting trigger condition is triggered, the preset configuration file is loaded, and then at least one tested code area in the target code file is determined according to the configuration file; if the highlighting rule for the target code file in the configuration file hits the target character in the tested code area, the target character is highlighted according to the highlighting rule. It can be seen that the configuration file is provided with highlighting rules for hitting and highlighting characters in the tested code area, which can be used as a configuration item for real-time highlighting of code files; since the configuration file is easy to implement, there is no need to learn TextMate syntax, and the loading of the configuration file is lighter, so the code characters are highlighted by loading the configuration file, which consumes less computer resources, and the solution is efficient and fast to implement.

[0044] In addition, the present application also provides a code character highlighting display device, an electronic device and a computer-readable storage medium, which also have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0046] Figure 1 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0047] Figure 2 A flowchart of a code character highlighting method provided in an embodiment of the present application;

[0048] Figure 3 A schematic diagram of the structure of a code character highlighting display device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0050] Each step in this application can be performed by a designated electronic device, the form of which is not limited, for example, it can be a general computing device such as a computer or a server. Figure 1 , Figure 1 The electronic device 100 may include a processor 101 and a memory 102 , and may further include one or more of a multimedia component 103 , an information input / information output (I / O) interface 104 , and a communication component 105 .

[0051] The processor 101 is used to control the overall operation of the electronic device 100 to complete all or part of the steps in the above-mentioned code character highlighting method; the memory 102 is used to store various types of data to support the operation of the electronic device 100, and these data may include, for example, instructions for any application or method operated on the electronic device 100, and application-related data. The memory 102 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0052] The multimedia component 103 may include a screen and an audio component. The screen may be, for example, a touch screen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone, which is used to receive external audio signals. The received audio signal may be further stored in the memory 102 or sent through the communication component 105. The audio component also includes at least one speaker for outputting audio signals. The I / O interface 104 provides an interface between the processor 101 and other interface modules, and the above-mentioned other interface modules may be a keyboard, a mouse, buttons, etc. These buttons may be virtual buttons or physical buttons. The communication component 105 is used for wired or wireless communication between the electronic device 100 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G or 4G, or a combination of one or more of them, so the corresponding communication component 105 may include: Wi-Fi component, Bluetooth component, NFC component.

[0053] The electronic device 100 can be implemented by one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), controllers, microcontrollers, microprocessors or other electronic components to execute the code character highlighting method proposed in this application.

[0054] Please refer to Figure 2 , Figure 2 A flowchart of a code character highlighting method provided in an embodiment of the present application. The method provided in an embodiment of the present application includes:

[0055] S201. In response to a character highlighting trigger condition, load a preset configuration file.

[0056] It should be noted that the function of highlighting code characters can be enabled in real time during code editing, or when a code file is opened or run, and can also be triggered by the user for the code in a specified area. Therefore, in one embodiment, in response to a character highlighting trigger condition, a preset configuration file is loaded, including: if it is detected that the target code file is in an editing state, and / or a character highlighting instruction for the target code file is detected, a character highlighting trigger condition is generated, and a preset configuration file is loaded.

[0057] In this embodiment, the configuration file can be used as a configuration item of the code editor, and can be specifically a JSON file. JSON (Java Script Object Notation) is a lightweight data exchange format that is easy for humans to read and write, and easy for machines to parse and generate. JSON files use key-value pairs and arrays to represent data structures, and are suitable for scenarios such as configuration files.

[0058] S202: Determine at least one code region to be tested in the target code file according to the configuration file.

[0059] It should be noted that the configuration file contains a regular expression that detects the code in a specific area, and one area can correspond to a start regular expression R begin and a closing regular expression R end For example: R begin (S[i:j])=true, R end (S[k:l])=true means: start the regular expression R begin and end the regular expression R end A code region starting at (S[i:j]) and ending at (S[k:l]) is hit; S represents a character in the code, and (i:j<k:l), and (S[i:j]) is the beginning part of the region, and (S[k:l]) is the ending part of the region. Then in one embodiment, according to the configuration file, the step of determining at least one tested code region in the target code file includes: determining the tested code region in the target code file based on a regular expression representing the starting position and the ending position of the region in the configuration file.

[0060] Regular Expression (regex) is a tool used to describe text patterns, which can match, search, and operate strings. Regular expressions are composed of characters and special symbols, and match specific character combinations in text by defining patterns.

[0061] The tested code region in this embodiment represents: a group of adjacent or non-adjacent code fragments, which have certain grammatical correlations and may have similar structures or semantics. These regions may represent different code blocks in program editing, such as functions, loops, conditional statements, etc., or user-defined code fragments.

[0062] S203: If the highlighting rule for the target code file in the configuration file hits the target character in the tested code area, the target character is highlighted according to the highlighting rule.

[0063] Correspondingly, for the code in a specific area of ​​the target code file, a highlighting rule for the area is provided in the configuration file, and the highlighting rule can highlight the following elements: keywords, identifiers, operators, literals, separators or syntax elements. Moreover, the colors displayed for different elements can be the same or different. Specifically, the highlighting rule can be specifically: a coloring rule regular expression for the target syntax element. Therefore, in one embodiment, highlighting the target characters according to the highlighting rule includes: obtaining the target syntax element category corresponding to the target characters; obtaining the target coloring rule regular expression corresponding to the target syntax element category according to the configuration file; and grammatically coloring the target characters based on the target coloring rule regular expression.

[0064] The target syntax element category is a keyword category, an identifier category, an operator category, a literal category, or a separator category.

[0065] Furthermore, the configuration file may also be configured with an automatic line break and indentation function and a code execution automatic interruption function. Therefore, in one embodiment, after determining at least one tested code area in the target code file according to the configuration file, it further includes: if an automatic line break and indentation symbol defined in the configuration file is detected in the tested code area, automatic line break and indentation are implemented after the automatic line break and indentation symbol in the tested code area. In one embodiment, after determining at least one tested code area in the target code file according to the configuration file, it further includes: if an operation breakpoint is detected during the operation of the tested code area, the execution of the target code file is paused, and the pause position and the area that has been run are marked.

[0066] It can be seen that the present embodiment realizes the hitting and highlighting of code characters based on the configuration file. When the character highlighting trigger condition is triggered, the preset configuration file is loaded, and then at least one tested code area in the target code file is determined according to the configuration file; if the highlighting rule for the target code file in the configuration file hits the target character in the tested code area, the target character is highlighted according to the highlighting rule. It can be seen that the configuration file is provided with highlighting rules for hitting and highlighting characters in the tested code area, which can be used as a configuration item for real-time highlighting of code files; since the configuration file is easy to implement, there is no need to learn TextMate syntax, and the loading of the configuration file is lighter, so the code characters are highlighted by loading the configuration file, which consumes less computer resources, and the solution is efficient and fast to implement.

[0067] In one example, a code highlighting process includes:

[0068] Step 1: Import the JSON configuration file and complete file loading and reading.

[0069] The Python code example for implementing step 1 is as follows:

[0070] import re

[0071] import JSON# Load JSON configuration file

[0072] with open('config.JSON', 'r', encoding='utf-8') as f:

[0073] config = JSON.load(f)# Read the code file to be processed

[0074] with open('code_file.txt', 'r', encoding='utf-8') as f:

[0075] code = f.read()

[0076] The following is an example of a JSON configuration file: (config.JSON)

[0077] {

[0078] "regions": [

[0079] {

[0080] "start": "\\bdef\\b",

[0081] "end": "\\bend\\b"

[0082] }

[0083] ],

[0084] "syntax_rules": [

[0085] {

[0086] "pattern": "\\bdef\\b",

[0087] "color": "#0000FF"

[0088] },

[0089] {

[0090] "pattern": "\\bend\\b",

[0091] "color": "#FF0000"

[0092] } ]

[0094] }

[0095] Step 2: Implement block-level matching based on the JSON configuration file. One block corresponds to one tested code area.

[0096] A series of tested code regions are defined in the JSON configuration file. Each region contains a start and end regular expression. The code editor can identify different regions (i.e. different blocks) in the code based on this and highlight the rule-matching characters in each block.

[0097] Step 2 defines clear start and end regular expressions, which can accurately identify the boundaries of code blocks and avoid mismatches. Regular expressions in JSON files are easy to modify and expand to adapt to different programming languages ​​and syntax requirements. Using JSON files to centrally manage regular expressions makes syntax highlighting rules easier to maintain and update.

[0098] The Python code example for implementing step 2 is as follows:

[0099] In the following code example, the highlight_blocks function matches the start and end regular expressions according to the regions definition in the JSON configuration file, and marks the start and end of the block with HTML tags.

[0100] Example code:

[0101] def highlight_blocks(code, regions):

[0102] highlighted_code = code

[0103] for region in regions:

[0104] start_re = re.compile(region['start'])

[0105] end_re = re.compile(region['end'])

[0106] highlighted_code = start_re.sub('<highlight_start> ',highlighted_code)

[0107] highlighted_code = end_re.sub('<highlight_end> ', highlighted_code)

[0108] return highlighted_code

[0109] Step 3: Use the configuration file to achieve automatic indentation.

[0110] In the configuration file, a context-free grammar is defined to specify that the set symbol is followed by one or more spaces or tabs for indentation. This method does not rely on a specific context, but indents according to the specified symbol followed by one or more spaces or tabs. In this method, a set of general indentation rules is defined, which is not restricted by a specific context, making the indentation operation more flexible and unified.

[0111] The following is a Python code example to implement step 3:

[0112] def auto_indent(code, grammar_rules):

[0113] indented_code = ''

[0114] indent_level = 0

[0115] for line in code.split('\n'):

[0116] for rule in grammar_rules:

[0117] match = re.match(rule['pattern'], line)

[0118] if match:

[0119] if rule['action'] == 'increase':

[0120] indent_level += 1

[0121] elif rule['action'] == 'decrease' and indent_level >0:

[0122] indent_level -= 1

[0123] indented_code += ' ' * (indent_level * 4) + line.strip() + '\n'

[0124] return indented_code

[0125] Step 4: Use the configuration file to implement syntax highlighting.

[0126] A series of classes are defined in the configuration file. Each class contains a set of regular expressions for matching specific syntax elements and corresponding color codes (i.e., coloring rule regular expressions). When the text editor parses, different syntax elements are colored according to these classes; by defining a set of regular expressions , each Matches a specific syntax element. If C represents a set of characters in the code, the match can be expressed as: , which means that for each character c in the code, there is at least one regular expression Match it.

[0127] Color codes refer to an identifier or representation method used to specify text color or style in programming or markup languages. In code editors or text editors, color codes are used to assign specific colors to different types of code elements (such as keywords, variables, comments, etc.) so that developers can more easily identify and understand the code structure.

[0128] Specific syntax elements refer to the smallest syntax units with specific functions or meanings in a programming language or markup language. These elements are the basic components of the code, through which various programming logic and functions can be implemented. The types and definitions of specific syntax elements vary depending on the programming language, but generally include the following categories:

[0129] Keywords: Reserved words with special meanings, usually used to define program structure or control flow (for example, if, while, return).

[0130] Identifier: A name used to name a variable, function, class, etc. (e.g., myVariable, calculateSum).

[0131] Operator: A symbol used to perform arithmetic, logical, comparison, and other operations (for example, +, ==, &&).

[0132] Literal: A direct quantity that represents a fixed value (for example, the number 123, the string "hello").

[0133] Comments: Used to add explanations or notes to the code, and are not executed by the program (for example, / / single-line comment, / * multi-line comment* / ).

[0134] Delimiter: A symbol used to separate code elements (e.g., commas, semicolons, parentheses).

[0135] These specific syntax elements play different roles in the syntax of programming languages. By combining and using them, a complete program or script can be constructed. Editor features such as syntax highlighting and code completion are usually implemented based on these specific syntax elements to improve the efficiency and readability of code writing.

[0136] In step 4, the defined regular expressions can be highlighted for different programming languages ​​and syntax elements; and precise matching of specific syntax elements can reduce the probability of mismatch or omission. At the same time, users can easily adjust regular expressions and color codes to customize the syntax highlighting effect.

[0137] In this embodiment, character highlighting can be achieved during code program editing. Block-level matching, automatic indentation, and syntax highlighting are implemented through specific JSON files, making code editing more intuitive, efficient, and easy to maintain, thereby allowing developers to improve coding efficiency. In addition, when developing and implementing JSON files, context-free grammars and dynamic rule definitions can be used to accurately parse and highlight complex grammars to improve development efficiency; at the same time, modular design and flexible extension mechanisms can be introduced to make it easier to add new functions and support new programming languages ​​to the configuration file, thereby improving the scalability and adaptability of the solution.

[0138] In the following Python code example, the syntax_highlight function highlights specific syntax elements according to the regular expressions defined in the syntax_rules in the JSON configuration file. The final processed code is saved to an HTML file and is displayed using the HTML Syntax highlighting for tags and CSS styles.

[0139] The specific code example is:

[0140] def syntax_highlight(code, syntax_rules):

[0141] highlighted_code = code

[0142] for rule in syntax_rules:

[0143] regex = re.compile(rule['pattern'])

[0144] color_code = rule['color']

[0145] highlighted_code = regex.sub(f' \\g<0> ', highlighted_code)

[0146] return highlighted_code

[0147] # Read the corresponding configuration from the configuration file

[0148] regions = config.get('regions', [])

[0149] grammar_rules = config.get('grammar_rules', [])

[0150] syntax_rules = config.get('syntax_rules', [])

[0151] # Processing code

[0152] highlighted_code = highlight_blocks(code, regions)

[0153] indented_code = auto_indent(highlighted_code, grammar_rules)

[0154] final_code = syntax_highlight(highlighted_code, syntax_rules)

[0155] # Output processed code

[0156] with open('output_code.html', 'w', encoding='utf-8') as f:

[0157] f.write(final_code)

[0158] print('Code processing complete. Output saved to output_code.html')

[0159] Here is a sample code file (code_file.txt)

[0160] def hello_world():

[0161] print("Hello, world!")

[0162] end

[0163] The following is an introduction to a code character highlighting display device provided in an embodiment of the present application. The code character highlighting display device described below and the code character highlighting display method described above can be referenced to each other.

[0164] Please refer to Figure 3 , Figure 3 A schematic diagram of the structure of a code character highlighting display device provided in an embodiment of the present application includes:

[0165] The loading module 301 is used to load a preset configuration file in response to a character highlighting trigger condition;

[0166] A determination module 302 is used to determine at least one tested code region in the target code file according to the configuration file;

[0167] The display module 303 is used to highlight the target character according to the highlighting rule when the highlighting rule for the target code file in the configuration file hits the target character in the tested code area.

[0168] In one embodiment, the loading module is specifically used for:

[0169] If it is detected that the target code file is in an editing state, and / or a character highlighting instruction for the target code file is detected, a character highlighting trigger condition is generated, and a preset configuration file is loaded.

[0170] In one implementation, the determination module is specifically configured to:

[0171] Based on the regular expressions representing the start position and the end position of the region in the configuration file, the code region to be tested in the target code file is determined.

[0172] In one embodiment, the display module is specifically used for:

[0173] Get the target grammatical element category corresponding to the target character;

[0174] According to the configuration file, obtain the target coloring rule regular expression corresponding to the target syntax element category;

[0175] Use the target coloring rule regular expression to perform syntax coloring on the target characters.

[0176] In one implementation, the target syntax element category is a keyword category, an identifier category, an operator category, a literal category, or a separator category.

[0177] In one embodiment, the device further comprises:

[0178] The automatic line break and indentation module is used to determine at least one tested code area in the target code file according to the configuration file. If the automatic line break and indentation symbol defined in the configuration file is detected in the tested code area, automatic line break and indentation will be implemented after the automatic line break and indentation symbol in the tested code area.

[0179] In one embodiment, the device further comprises:

[0180] The automatic interrupt module is used to determine at least one tested code area in the target code file according to the configuration file. If a running breakpoint is detected during the running of the tested code area, the execution of the target code file is suspended and the suspension position and the running area are marked.

[0181] The computer-readable storage medium provided in the embodiment of the present application is introduced below. The computer-readable storage medium described below and the code character highlighting method described above can be referenced to each other.

[0182] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned code character highlighting method are implemented.

[0183] The computer-readable storage medium may include: a USB flash drive, a scanning hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0184] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0185] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0186] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a scannable disk, a CD-ROM, or any other form of storage medium known in the art.

[0187] Finally, it should be noted that, in this article, relationships such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms include, include or any other variations are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.

[0188] Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A code character highlighting method, characterized in that: include: In response to a character highlighting trigger condition, loading a preset configuration file; Determine at least one tested code region in the target code file according to the configuration file; If the highlighting rule for the target code file in the configuration file matches the target character in the tested code area, the target character is highlighted according to the highlighting rule.

2. The code character highlighting method according to claim 1, characterized in that: In response to the character highlighting trigger condition, a preset configuration file is loaded, including: If it is detected that the target code file is in an editing state, and / or a character highlighting instruction for the target code file is detected, the character highlighting triggering condition is generated, and the preset configuration file is loaded.

3. The code character highlighting method according to claim 1, characterized in that: Determining at least one tested code region in the target code file according to the configuration file includes: The tested code region in the target code file is determined based on the regular expression representing the region start position and the region end position in the configuration file.

4. The code character highlighting method according to claim 1, characterized in that: The highlighting of the target character according to the highlighting rule includes: Obtaining a target grammatical element category corresponding to the target character; According to the configuration file, obtaining a target coloring rule regular expression corresponding to the target syntax element category; The target characters are grammatically colored based on the target coloring rule regular expression.

5. The code character highlighting method according to claim 4, characterized in that: The target syntax element category includes a keyword category, an identifier category, an operator category, a literal category, or a separator category.

6. The code character highlighting method according to any one of claims 1 to 5, characterized in that: After determining at least one tested code region in the target code file according to the configuration file, the method further includes: If the automatic line break and indentation symbol defined in the configuration file is detected in the tested code area, automatic line break and indentation are implemented after the automatic line break and indentation symbol in the tested code area.

7. The code character highlighting method according to any one of claims 1 to 5, characterized in that: After determining at least one tested code region in the target code file according to the configuration file, the method further includes: If a running breakpoint is detected during the running of the tested code area, the execution of the target code file is suspended, and the suspension position and the running area are marked.

8. A code character highlighting display device, characterized in that: include: A loading module, used for loading a preset configuration file in response to a character highlighting trigger condition; A determination module, used to determine at least one tested code region in the target code file according to the configuration file; The display module is used for highlighting the target character according to the highlighting rule when the highlighting rule for the target code file in the configuration file hits the target character in the tested code area.

9. An electronic device, characterized in that: comprising a memory and a processor, wherein: The memory is used to store the computer program; The processor is used to execute the computer program to implement the code character highlighting method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the code character highlighting method according to any one of claims 1 to 7 is implemented.