Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Fig. 1 is a program code marking process provided in an embodiment of the present application, which specifically includes the following steps:
s101: the program code is read sequentially.
In practical applications, in order to improve the efficiency of editing program codes, some program codes in the program codes are usually marked, so that a programmer can accurately locate a desired program code.
Therefore, in the whole process of marking the program codes, the program codes are firstly read in a forward and backward sequence, and the sequence reading program codes can be executed by a code editing device and other code reading devices.
For example, assuming that the program code a is written in perl language, C language, and SQL language, the code editing apparatus reads the program code a sequentially.
S102: when a switching identifier contained in a program code is read, a marking rule corresponding to the switching identifier is determined.
Different programming languages have different syntactic structures, so that different programming languages correspond to different program codes to be marked, that is, different programming languages correspond to different marking rules, and the marking rules describe in detail the program codes to be marked when the program codes are written by using a certain programming language.
Further, since the program code may be written by more than two programming languages in practical applications, in the present application, if the program code is written by more than two programming languages, when the program code is marked, the program code written by different programming languages needs to be marked by different marking rules.
Furthermore, in order to mark program codes written in different programming languages by using different marking rules, in the present application, it is necessary to identify which programming language the program code is written in, and the present application specifically identifies by using a switching identifier, where each switching identifier corresponds to one programming language, that is, the switching identifier can accurately identify, which programming language the program code is written in next, and then determines the marking rule corresponding to the switching identifier.
It should be noted that, in the present application, in order to consider that the written program code can be recognized and executed by the execution device, when the switching identifier is preset, the program code existing in the programming language may be used as the switching identifier, for example, the program code "" symbol "in the perl language may be used as the switching identifier, but if the program code existing in the programming language is used as the switching identifier, there may be other meanings of the switching identifier, for example, if the program code" "is selected as the switching identifier, the program code" "may also represent escape, that is, the program code in the middle of the program code" "symbol" and the program codes on both sides are the same programming language, so that when the code editing device reads the switching identifier, the switching marking rule is continued according to the switching identifier, it is likely that an error in the mark is directly caused, and therefore, if a program code is used as the switching identifier, which has other meanings than the meaning of the switching identifier, the programming language may be modified such that the meaning of the program code used as the switching identifier is represented by a new program code, and thus the program code may be used as the switching identifier, for example, the program code "" representing an escape may be modified into the program code "" so that the program code "" may be used as the switching identifier.
In addition, since the comment can be customized in general and the execution device can normally recognize and execute the program code even if the comment is customized, in the present application, it is also possible to use the comment (which programming language the next program code is written in is explained in the comment) as the switching identifier and freely set the switching identifier.
Continuing the above example, it is assumed that a comment is used as the switching identifier, and the preset switching identifier is "// perl language" (indicating that the next program code is written in perl language), "// C language" (indicating that the next program code is written in C language), "// SQL language" (indicating that the next program code is written in SQL language), and "// perl language" corresponding to the perl markup rules, "// C language" corresponding to the C markup rules, and "// SQL language" corresponding to the SQL markup rules are set in advance.
Assume that the switching identifier appearing first in the program code a is in the "// perl language", and therefore, the code editing apparatus reads the program code a sequentially, and when the "// perl language" included in the program code is read, determines the perl markup rule corresponding to the "// perl language".
In practical applications, there may be a case where the top program code of the entire program code is not the switch identifier, but since the programming language used at the beginning of the entire program code corresponds to the file type in a normal case, that is, the file type may determine the programming language used at the beginning of the program code, for this case, in the present application, when marking the entire program code, specifically, before the switch identifier is read for the first time, a marking rule corresponding to the file type may be determined according to the file type of the file in which the program code is located, and according to the marking rule corresponding to the file type, the program code read subsequently may be marked until the switch identifier is read. For example, assuming that the program code located at the forefront in the program codes being written is not the switching identifier, assuming that the file where the program code is located is an SQL-type file, before the code editing device reads the switching identifier for the first time, according to the SQL file type, a marking rule corresponding to the file type is determined, assuming that the marking rule is an SQL marking rule, and according to the SQL marking rule, marking the program code read subsequently until the switching identifier is read.
S103: and marking the subsequently read program codes by adopting the marking rule until the next switching identifier contained in the program codes is read again, determining another marking rule corresponding to the next switching identifier again, and continuously marking the read program codes by adopting the other marking rule until all the program codes are marked.
In consideration of the fact that in practical application, when the adopted switching identifier is an existing program code in a programming language, there may be a case where a preset switching identifier appears in a comment, and the program code before the comment and the program code after the comment are both in the same programming language, therefore, in the present application, before a marking rule is adopted to mark a subsequently read program code, it is determined that the position of the switching identifier in the program code is not a preset specified position, and if the determined position of the switching identifier in the program code is a preset specified position, it is described that the program code before the switching identifier and the program code after the switching identifier are both in the same programming language, and therefore, the switching identifier can be directly ignored, i.e., no processing is performed.
For example, assuming that the program code "is used as the switching identifier, and the switching identifier cannot appear in the annotation, the code editing apparatus reads the switching identifier included in the annotation during the process of reading the program code E, and determines that the position of the switching identifier" in the program code is in the annotation, that is, the switching identifier "is at a preset specified position, then the code editing apparatus directly ignores the switching identifier", does not adopt the marking rule corresponding to the switching identifier "to mark the subsequently read program code, and still adopts the current marking rule to mark the subsequently read program code.
Further, after determining that the position of the switching identifier in the program code is not the preset designated position, the code editing device may directly mark the program code read subsequently according to the marking rule until the next switching identifier included in the program code is read again, determine another marking rule corresponding to the next switching identifier again, and continue to mark the read program code by using the other marking rule until all the program codes are marked.
In the process of marking the program code, in the present application, the program code may be marked in a highlighting manner, that is, the program code to be marked that is read subsequently is highlighted, and of course, different ground colors may be added to the program code to be marked according to different types.
Continuing with the above example, the code editing device determines the perl mark rule corresponding to the// perl language, and it is assumed that the code editing device determines that the position of the// perl language in the program code a is not the preset designated position, therefore, the code editing device uses the perl mark rule to highlight (i.e. mark) the subsequently read program code to be marked until the next switch identifier included in the program code is read again, and it is assumed that the next switch identifier is the// C language, determines the C mark rule corresponding to the// C language, and uses the C mark rule to highlight the subsequently read program code to be marked, and it is assumed that the next switch identifier is the// SQL language, determines the SQL mark rule corresponding to the// SQL language, and uses the SQL mark rule to highlight the subsequently read program code to be marked, until all of the program code a is marked.
By the method, even if the program codes are written by more than two programming languages, which marking rule needs to be used can be determined according to the switching identifier, and the program codes read subsequently can be accurately marked.
In the above method for marking program codes provided by the present application, in the whole process of marking program codes, the switching identifier uniquely corresponds to the marking rule of one programming language, that is, the marking rule corresponding to one programming language can be uniquely identified and determined by the switching identifier, however, in practical applications, for program codes written only by two programming languages, when the switching identifier is preset, the set switching identifier does not need to correspond to the marking rule of any one programming language, and as long as the code editing device reads the switching identifier, another marking rule different from the currently used marking rule in the two marking rules may be adopted, as specifically shown in fig. 2.
Fig. 2 is a program code marking process provided in an embodiment of the present application, which specifically includes the following steps:
s201: the program code is read sequentially.
For example, suppose that the program code B is written by perl language and SQL language, and the perl markup rules corresponding to the perl language are stored in advance, and the SQL markup rules corresponding to the SQL language are as follows:
the code editing apparatus reads the program codes B sequentially.
S202: and marking the subsequently read program codes by adopting a default marking rule in the two marking rules.
S203: and when the switching identifier contained in the program code is read, adopting the other marking rule different from the currently used marking rule in the two marking rules to continuously mark the subsequently read program code until all the program codes are marked.
Since only two programming languages are written in the application, in order to improve the efficiency of writing the program codes, only one switching identifier can be set in the application, and when the code editing device reads the switching identifier, another marking rule different from the currently used marking rule in the two marking rules is adopted to continuously mark the subsequently read program codes until all the program codes are marked.
Further, since only one switch identifier is set in the present application, in the entire program code, the program code located at the frontmost end is not the switch identifier, that is, the program code between the program code located at the frontmost end and the switch identifier that occurs for the first time needs to select one marking rule from two marking rules (in the present application, the marking rule may be used as a default marking rule) to mark the program code between the program code located at the frontmost end and the switch identifier that occurs for the first time.
The application provides a selection method for selecting which marking rule from two marking rules, which is specifically as follows: and determining a marking rule corresponding to the file type in the two marking rules according to the file type of the file where the program code is located, taking the marking rule as a default marking rule, and marking the subsequently read program code by adopting the default marking rule.
Continuing with the above example, assume that the preset switch identifier is a # switch identifier (the marking rule indicating the next program code is a perl marking rule and another marking rule different from the currently used marking rule in the SQL marking rule).
Assuming that the file type of the file where the program code B is located is perl, the code editing device determines a perl marking rule corresponding to the file type according to the file type perl of the file where the program code B is located, and takes the perl marking rule as a default marking rule, and the code editing device highlights the subsequently read program code by adopting the perl marking rule, namely highlights substr, "10", "1001", "y-% m-% d% m:% s", # bizdate ═ yesterday, and $.
Until the # switching identifier contained in the program code B is read, adopting another marking rule different from the currently used perl marking rule, namely, the SQL marking rule, to continue to highlight the program code B which is read subsequently, namely, to highlight ═ temp _ bizdate ', -statistical month, — payment account and bank account balance/bank, count, sum, ' yyyyyyyy-mm-dd hh: mi: ss ', ' yyymm ', until the program code B is completely marked.
Based on the same idea, the two methods for marking program codes provided by the embodiments of the present application further provide a first program code marking device, as shown in fig. 3, and a second program code marking device, as shown in fig. 4. .
Fig. 3 is a schematic structural diagram of a first program code marking apparatus provided in an embodiment of the present application, including:
a reading module 301, configured to read program codes sequentially;
a first determining module 302, configured to determine, when a handover identifier included in a program code is read, a marking rule corresponding to the handover identifier;
the marking module 303 is configured to mark the subsequently read program code by using the marking rule, determine another marking rule corresponding to a next switching identifier again when the next switching identifier included in the program code is read again, and continue to mark the read program code by using the other marking rule until all the program codes are marked.
The device further comprises:
an initial marking module 304, configured to determine, before the switching identifier is read for the first time, a marking rule corresponding to the file type according to the file type of the file where the program code is located, and mark, according to the marking rule corresponding to the file type, the program code that is read subsequently until the switching identifier is read.
The device further comprises:
a second determining module 305, configured to determine, by the marking module 303, that a position of the handover identifier in the program code is not a preset specified position before marking a subsequently read program code by using the marking rule.
The marking module 303 is specifically configured to highlight the program code that needs to be marked and is subsequently read.
Fig. 4 is a schematic structural diagram of a second program code marking apparatus provided in an embodiment of the present application, where the program code is written in two programming languages, and two marking rules respectively corresponding to the two programming languages are pre-stored, where the method includes:
a reading module 401, configured to read the program codes sequentially;
a default marking module 402, configured to mark a subsequently read program code by using a default marking rule of the two marking rules;
a marking module 403, configured to, each time a switching identifier included in a program code is read, adopt another marking rule different from the currently used marking rule in the two marking rules, and continue to mark a subsequently read program code until all program codes are marked.
The default marking module 402 is specifically configured to determine, according to the file type of the file where the program code is located, a marking rule corresponding to the file type in the two marking rules, as a default marking rule, and mark the subsequently read program code by using the default marking rule.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.