A language code processing method and related apparatus

By parsing the CSS code and matching it with regular expressions, combined with the configuration file of the language code processor, the pixel string in the CSS code can be quickly and accurately converted into the root font size string. This solves the problems of slow conversion speed and low accuracy in existing technologies and improves the ability to adapt to layout.

CN122431672APending Publication Date: 2026-07-21TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
TENCENT TECHNOLOGY (SHENZHEN) CO LTD
Filing Date
2025-01-20
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

In existing technologies, the matching speed and accuracy of pixel strings in CSS code are slow, resulting in omissions and errors in the conversion of pixel strings to root font size.

Method used

The CSS code is parsed to generate an abstract syntax tree, the target regular expression is used to match pixel strings, and the unit is converted according to the language code processor's configuration file to generate new CSS code.

Benefits of technology

It enables fast and accurate conversion of pixel strings in CSS code to root font size strings, avoiding slow conversion speed, omissions, and incorrect conversions, and ensuring the adaptive layout capability of CSS code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122431672A_ABST
    Figure CN122431672A_ABST
Patent Text Reader

Abstract

The application discloses a language code processing method and a related device. The method comprises the following steps: parsing a first language code describing a webpage file style into a first abstract syntax tree; matching a pixel string included in a preset attribute value in the first abstract syntax tree through a target regular expression, converting the pixel string into a root font size string according to a preset root font size and a root font size unit in a configuration file of a language code processor, and obtaining a second abstract syntax tree; and generating a second language code based on the second abstract syntax tree. The target regular expression can quickly and accurately match the pixel string, so that the matching speed of the pixel string included in the preset attribute value in the first abstract syntax tree parsed by the first language code is fast and the matching precision is high. The pixel string in the first language code is quickly and accurately converted into the root font size string to obtain the second language code, and the situations of slow conversion, missed conversion and wrong conversion of the pixel string are avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing, and in particular to a language code processing method and related apparatus. Background Technology

[0002] Cascading Style Sheets (CSS) code is a language code that describes the style of a web page file. CSS code converts pixels into the root font size, making it easier to change the layout proportions of a web page by adjusting the root font size, thus adapting to different screen sizes and devices.

[0003] In related technologies, the language code processing method for converting pixel values ​​to root font size refers to: parsing CSS code into an Abstract Syntax Tree (AST), converting the pixel strings of some attribute values ​​in the AST into root font size strings, obtaining a modified AST, and generating new CSS code.

[0004] However, the above method has a slow matching speed and low matching accuracy for some attribute values ​​in the abstract syntax tree. There are problems such as slow pixel string conversion, missed conversion, and incorrect conversion, which makes it impossible to quickly and accurately convert pixels in CSS code to the root font size. Summary of the Invention

[0005] To address the aforementioned technical problems, this application provides a language code processing method and related apparatus, which quickly and accurately converts pixel strings in the first language code into root font size strings to obtain the second language code, avoiding issues such as slow pixel string conversion, missed conversions, and incorrect conversions.

[0006] The embodiments of this application disclose the following technical solutions:

[0007] On one hand, embodiments of this application provide a language code processing method, the method comprising:

[0008] The first language code is parsed to obtain the first abstract syntax tree; the first language code is the language code that describes the style of the web page file.

[0009] Based on the target regular expression, pixel matching is performed on the preset attribute values ​​in the first abstract syntax tree to obtain a pixel string; the target regular expression is used to match the pixel string.

[0010] Based on the root font size and root font size unit preset in the language code processor's configuration file, the pixel string is converted to a unit to obtain a second abstract syntax tree; the second abstract syntax tree includes the root font size string corresponding to the pixel string;

[0011] Code is generated from the second abstract syntax tree to obtain second language code.

[0012] On the other hand, embodiments of this application provide a language code processing apparatus, the apparatus comprising: a parsing unit, a matching unit, a conversion unit, and a generation unit;

[0013] The parsing unit is used to perform syntax parsing on the first language code to obtain a first abstract syntax tree; the first language code is language code describing the style of a web page file;

[0014] The matching unit is used to perform pixel matching on preset attribute values ​​in the first abstract syntax tree according to a target regular expression to obtain a pixel string; the target regular expression is used to match the pixel string.

[0015] The conversion unit is used to perform unit conversion on the pixel string according to the root font size and root font size unit preset in the configuration file of the language code processor to obtain a second abstract syntax tree; the second abstract syntax tree includes the root font size string corresponding to the pixel string;

[0016] The generation unit is used to generate code from the second abstract syntax tree to obtain second language code.

[0017] On the other hand, embodiments of this application provide a computer device, the computer device including a processor and a memory:

[0018] The memory is used to store computer programs and to transfer the computer programs to the processor;

[0019] The processor is configured to execute the method described in any of the foregoing aspects according to instructions in the computer program.

[0020] On the other hand, embodiments of this application provide a computer-readable storage medium for storing a computer program that, when run on a computer device, causes the computer device to perform the methods described in any of the foregoing aspects.

[0021] On the other hand, embodiments of this application provide a computer program product, including a computer program that, when run on a computer device, causes the computer device to perform the method described in any of the foregoing aspects.

[0022] As can be seen from the above technical solution, parsing the first language code describing the webpage file style into a first abstract syntax tree (AST) and representing the syntax structure information of the language code in a tree structure makes the syntax structure information of the first language code more intuitive and clear, facilitating subsequent fast and accurate matching of pixel strings in the first language code. The pixel strings included in the preset attribute values ​​in the first abstract syntax tree are matched using a target regular expression. Based on the preset root font size and root font size unit in the language code processor's configuration file, the pixel strings are converted into root font size strings to obtain the second abstract syntax tree. The target regular expression can quickly and accurately match pixel strings, making the matching speed and accuracy of the pixel strings included in the preset attribute values ​​in the first abstract syntax tree fast and accurate. Therefore, based on the preset root font size and root font size unit, the pixel strings included in the preset attribute values ​​in the first abstract syntax tree are quickly and accurately converted into root font size strings, ensuring that the second abstract syntax tree includes root font size strings, not pixel strings. The second language code is generated based on the second abstract syntax tree. The syntax structure information of the tree structure is converted into language code. The pixel string in the first language code is converted into the root font size string to obtain the second language code quickly and accurately, avoiding the problems of slow pixel string conversion, missed conversion, and incorrect conversion. Attached Figure Description

[0023] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0024] Figure 1 A system schematic diagram of a language code processing method provided in an embodiment of this application;

[0025] Figure 2 A flowchart illustrating a language code processing method provided in this application embodiment;

[0026] Figure 3 A schematic diagram illustrating a language code processing step provided in an embodiment of this application;

[0027] Figure 4 A schematic diagram of a language code processing flow provided for an embodiment of this application;

[0028] Figure 5 A structural diagram of a language code processing device provided in an embodiment of this application;

[0029] Figure 6A structural diagram of a server provided in an embodiment of this application;

[0030] Figure 7 This is a structural diagram of a terminal provided in an embodiment of this application. Detailed Implementation

[0031] The embodiments of this application will now be described with reference to the accompanying drawings.

[0032] Currently, pixels in CSS code need to be converted to the root font size so that adjusting the root font size makes it easier to change the layout ratio of the webpage and adapt to different screen sizes and devices. The common method for handling this pixel-to-root font size conversion in the language code is to parse the CSS code into an abstract syntax tree (Abstract Syntax Tree), convert the pixel strings of some property values ​​in the Abstract Syntax Tree into root font size strings, and then generate the new CSS code from the modified Abstract Syntax Tree. However, research has shown that matching pixel strings of some property values ​​in the Abstract Syntax Tree is slow and has low accuracy, resulting in slow pixel string conversion, missed conversions, and incorrect conversions. Therefore, it is impossible to quickly and accurately convert pixels in CSS code to the root font size.

[0033] This application provides a language code processing method that parses first language code describing the style of a webpage file into a first abstract syntax tree (AST). This tree structure represents the syntactic structure information of the language code, making the syntactic structure information of the first language code more intuitive and clear, facilitating subsequent fast and accurate matching of pixel strings within the first language code. The method uses a target regular expression to match pixel strings included in preset attribute values ​​within the first AST. Based on the preset root font size and root font size unit in the language code processor's configuration file, the pixel strings are converted into root font size strings to obtain a second AST. The target regular expression can quickly and accurately match pixel strings, resulting in fast and accurate matching of pixel strings included in the preset attribute values ​​of the first AST. Therefore, based on the preset root font size and root font size unit, the method quickly and accurately converts pixel strings included in the preset attribute values ​​of the first AST into root font size strings, ensuring that the second AST includes root font size strings, not pixel strings. The second language code is generated based on the second abstract syntax tree. The syntax structure information of the tree structure is converted into language code. The pixel string in the first language code is converted into the root font size string to obtain the second language code quickly and accurately, avoiding the problems of slow pixel string conversion, missed conversion, and incorrect conversion.

[0034] Next, the system architecture of the language code processing method will be introduced. See [link / reference] Figure 1 ,Should Figure 1This is a schematic diagram of a language code processing method provided in an embodiment of this application. The system includes a computer device 100, which is used to execute the language code processing method.

[0035] Computer device 100 performs syntax parsing on the first language code to obtain the first abstract syntax tree; the first language code is the language code that describes the style of the web page file.

[0036] As an example, if the first language code is the first CSS code, then the computer device 100 will parse the first CSS code describing the style of the web page file into the first abstract syntax tree, i.e., the first AST.

[0037] Computer device 100 performs pixel matching on preset attribute values ​​in the first abstract syntax tree according to the target regular expression to obtain pixel strings; the target regular expression is used to match pixel strings.

[0038] As an example, based on the above example, the target regular expression is / (\d*\.?\d+)px / g, and the pixel string is the px string; then computer device 100 matches the px string included in the preset attribute value in the first AST by / (\d*\.?\d+)px / g.

[0039] Computer device 100 performs unit conversion on pixel strings according to the root font size and root font size unit preset in the configuration file of the language code processor to obtain a second abstract syntax tree; the second abstract syntax tree includes the root font size string corresponding to the pixel string.

[0040] As an example, based on the above example, the language code processor is the CSS code converter PostCSS, the configuration file is postcss.config.js, the preset root font size is preset rootFontSize, the root font size unit is rem unit, and the root font size string is rem string; then computer device 100, according to the preset rootFontSize and rem unit in postcss.config.js of PostCSS, converts the px string to a rem string to obtain the second abstract syntax tree, i.e., the second AST.

[0041] Computer device 100 generates code from the second abstract syntax tree to obtain second language code.

[0042] As an example, based on the above example, computer device 100 generates second language code, which is second CSS code, based on the second AST.

[0043] In other words, the first language code describing the style of a webpage file is parsed into a first abstract syntax tree (AST). This tree structure represents the syntax information of the language code, making it more intuitive and clear, facilitating subsequent fast and accurate matching of pixel strings within the first language code. The first AST uses a target regular expression to match pixel strings included in preset attribute values. Based on the preset root font size and unit in the language code processor's configuration file, the pixel strings are converted into root font size strings to obtain a second abstract syntax tree. The target regular expression's ability to quickly and accurately match pixel strings ensures fast and accurate matching of pixel strings included in the preset attribute values ​​of the first AST. Therefore, based on the preset root font size and unit, the second AST quickly and accurately converts pixel strings included in the preset attribute values ​​of the first AST into root font size strings, ensuring that the second AST includes root font size strings, not pixel strings. The second language code is generated based on the second abstract syntax tree. The syntax structure information of the tree structure is converted into language code. The pixel string in the first language code is converted into the root font size string to obtain the second language code quickly and accurately, avoiding the problems of slow pixel string conversion, missed conversion, and incorrect conversion.

[0044] It should be noted that, in the embodiments of this application, the computer device can be a server or a terminal. The method provided in the embodiments of this application can be executed by the terminal or the server alone, or it can be executed by the terminal and the server in cooperation. Specifically, when the method provided in the embodiments of this application is executed by the terminal or the server alone, its execution method is similar to... Figure 1 The corresponding embodiments are similar, mainly replacing the computer device with a terminal or server. Furthermore, when the method provided in this application is executed by a terminal and a server, steps that need to be displayed on the front-end interface can be executed by the terminal, while steps that require background calculations and do not need to be displayed on the front-end interface can be executed by the server.

[0045] The terminal can be a smartphone, tablet, laptop, desktop computer, intelligent voice interaction device, vehicle terminal, extended reality device, or aircraft, but is not limited to these. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services, but is not limited to these. The terminal and server can be connected directly or indirectly through wired or wireless communication, and this application does not impose any restrictions. For example, the terminal and server can be connected through a network, which can be wired or wireless.

[0046] Next, the language code processing method provided in the embodiments of this application will be described in detail using a computer device executing the method provided in the embodiments of this application as an example, in conjunction with the accompanying drawings.

[0047] See Figure 2 ,Should Figure 2 A flowchart of a language code processing method provided in this application embodiment, the method including:

[0048] S201: Perform syntax parsing on the first language code to obtain the first abstract syntax tree; the first language code is the language code that describes the style of the web page file.

[0049] In this embodiment of the application, for the first language code describing the style of a web page file, in order to convert the pixel string in the first language code into the root font size string and adapt to the adaptive layout under different screen sizes and different devices, considering that the pixel string in the first language code belongs to the attribute value of the attribute under the selector in the first language code, it is first necessary to clarify the syntactic structure information of the first language code. Therefore, the first language code can be parsed into a first abstract syntax tree with more intuitive and clear syntactic structure information.

[0050] Here, the first language code is the first CSS code, and the first abstract syntax tree (AST) is a data representation of the syntax structure information of the first CSS code in a tree structure. Based on this, parsing the first language code to obtain the first AST can be done by parsing the syntax structure information of the first CSS code and representing the syntax structure information of the first CSS code in a tree structure.

[0051] The above-mentioned S201 parses the first language code describing the style of the web page file into a first abstract syntax tree, and represents the syntax structure information of the language code in a tree structure, making the syntax structure information of the first language code more intuitive and clear, and facilitating subsequent fast and accurate matching of pixel strings in the first language code.

[0052] As an example of S201, the first language code is the first CSS code; the computer device parses the first CSS code, which describes the style of the web page file, into the first abstract syntax tree, i.e., the first AST.

[0053] S202: Based on the target regular expression, perform pixel matching on the preset attribute values ​​in the first abstract syntax tree to obtain the pixel string; the target regular expression is used to match the pixel string.

[0054] S203: Based on the root font size and root font size unit preset in the language code processor's configuration file, perform unit conversion on the pixel string to obtain the second abstract syntax tree; the second abstract syntax tree includes the root font size string corresponding to the pixel string.

[0055] In related technologies, after parsing the first language code into a first abstract syntax tree, the matching speed and accuracy of pixel strings for some attribute values ​​in the first abstract syntax tree are slow. There are problems such as slow pixel string conversion, missed conversion, and incorrect conversion, which makes it impossible to quickly and accurately convert pixel strings in the first language code into root font size strings.

[0056] Therefore, in this embodiment of the application, in order to solve the above problems, it is necessary to quickly and accurately match pixel strings of some attribute values ​​in the first abstract syntax tree. Considering that the target regular expression used to match pixel strings can quickly and accurately match pixel strings, after executing the above S201 to parse the first language code into the first abstract syntax tree, the pixel strings included in the preset attribute values ​​in the first abstract syntax tree are matched by the target regular expression. On this basis, according to the root font size and root font size unit preset in the configuration file of the language code processor, the pixel strings are quickly and accurately converted into root font size strings, resulting in a second abstract syntax tree that includes root font size strings that are not pixel strings.

[0057] Among them, the target regular expression is a regular expression that matches pixel strings; the preset attribute values ​​in the first abstract syntax tree are the attribute values ​​of preset attributes under the preset selectors in the first abstract syntax tree; the pixel string is a string that starts with a number and ends with px (pixel); the language code processor is a processor of language code that describes the style of the web page file, i.e., the CSS code converter PostCSS; the configuration file is a processing configuration file for the language code that describes the style of the web page file, i.e., the CSS code processing configuration file; the preset root font size is a pre-configured root font size, and the root font size unit is rem (root em); the second abstract syntax tree is the data representation of the pixel strings included in the preset attribute values ​​of the first abstract syntax tree converted into the root font size string, i.e., the second AST; the root font size string is a string that starts with a number and ends with rem (rem string).

[0058] Based on this, pixel matching is performed on the preset attribute values ​​in the first abstract syntax tree (AST) according to the target regular expression to obtain pixel strings. The target regular expression used to match pixel strings can be: matching the px string of the attribute value of the preset attribute under the preset selector in the first AST using a regular expression that matches pixel strings. According to the preset root font size and root font size unit in the language code processor's configuration file, the pixel strings are converted to obtain the second abstract syntax tree. This can be done by converting the px string to a rem string according to the root font size and rem unit pre-configured in the PostCSS CSS code processing configuration file to obtain the second AST.

[0059] The above steps S202-S203 use a target regular expression to match pixel strings included in the preset attribute values ​​of the first abstract syntax tree, and convert the pixel strings into root font size strings according to the preset root font size and root font size unit in the language code processor's configuration file to obtain the second abstract syntax tree. The target regular expression can quickly and accurately match pixel strings, making the matching speed of pixel strings included in the preset attribute values ​​of the first abstract syntax tree fast and accurate. Thus, based on the preset root font size and root font size unit, it quickly and accurately converts the pixel strings included in the preset attribute values ​​of the first abstract syntax tree into root font size strings, so that the second abstract syntax tree includes root font size strings but not pixel strings, which facilitates the subsequent quick and accurate generation of second language code in the first language code that converts pixel strings in the first language code into root font size strings.

[0060] As an example of S202-S203, based on the example of S201 above, the target regular expression is / (\d*\.?\d+)px / g, the pixel string is the px string, the language code processor is the CSS code converter PostCSS, the configuration file is postcss.config.js, the preset root font size is the preset rootFontSize, the root font size unit is the rem unit, and the root font size string is the rem string; the computer device matches the px string included in the preset attribute value in the first AST using / (\d*\.?\d+)px / g, and converts the px string to the rem string according to the preset rootFontSize and rem unit in postCSS's postcss.config.js to obtain the second abstract syntax tree, i.e., the second AST.

[0061] In the expression / (\d*\.?\d+)px / g, / indicates the beginning of the target regular expression, () indicates the beginning and end of the match, \d* indicates matching zero or more digit characters, \.? indicates matching zero or more decimal point characters, px indicates pixels, and / g indicates global matching.

[0062] S204: Generate code from the second abstract syntax tree to obtain second language code.

[0063] In this embodiment of the application, after executing the above S202-S203 steps of matching the pixel string included in the preset attribute value in the first abstract syntax tree by the target regular expression, and converting the pixel string into the root font size string according to the preset root font size and root font size unit in the configuration file of the language code processor to obtain the second abstract syntax tree, since the second abstract syntax tree includes the root font size string corresponding to the pixel string, a second language code that includes the root font size string but is not a pixel string can be generated based on the second abstract syntax tree, so as to realize the conversion of the pixel string in the first language code into the root font size string.

[0064] The second language code is the CSS code that converts the pixel string in the first CSS code into a second font size string. Based on this, code generation is performed on the second abstract syntax tree to obtain the second language code, which can be: generating the second CSS code that converts the pixel string in the first CSS code into a second font size string based on the second AST.

[0065] The above-mentioned S204 generates second language code based on the second abstract syntax tree, converting the syntactic structure information of the tree structure into language code, quickly and accurately converting the pixel string in the first language code into the root font size string to obtain the second language code, avoiding situations such as slow pixel string conversion, missed conversion, and incorrect conversion.

[0066] As an example of S204, based on the examples of S202-S203 above, the computer device generates second language code based on the second AST, which is the second CSS code.

[0067] See Figure 3 ,Should Figure 3This illustration shows a language code processing step provided in an embodiment of this application. The steps include: syntax parsing, pixel matching, unit conversion, and code generation. Specifically, syntax parsing refers to parsing the first language code describing the style of a webpage file into a first abstract syntax tree; pixel matching refers to matching pixel strings containing preset attribute values ​​in the first abstract syntax tree using a target regular expression; unit conversion refers to converting the pixel strings into a root font size string according to the root font size and root font size unit preset in the language code processor's configuration file to obtain a second abstract syntax tree; and code generation refers to generating second language code based on the second abstract syntax tree.

[0068] As can be seen from the above technical solution, parsing the first language code describing the webpage file style into a first abstract syntax tree (AST) and representing the syntax structure information of the language code in a tree structure makes the syntax structure information of the first language code more intuitive and clear, facilitating subsequent fast and accurate matching of pixel strings in the first language code. The pixel strings included in the preset attribute values ​​in the first abstract syntax tree are matched using a target regular expression. Based on the preset root font size and root font size unit in the language code processor's configuration file, the pixel strings are converted into root font size strings to obtain the second abstract syntax tree. The target regular expression can quickly and accurately match pixel strings, making the matching speed and accuracy of the pixel strings included in the preset attribute values ​​in the first abstract syntax tree fast and accurate. Therefore, based on the preset root font size and root font size unit, the pixel strings included in the preset attribute values ​​in the first abstract syntax tree are quickly and accurately converted into root font size strings, ensuring that the second abstract syntax tree includes root font size strings, not pixel strings. The second language code is generated based on the second abstract syntax tree. The syntax structure information of the tree structure is converted into language code. The pixel string in the first language code is converted into the root font size string to obtain the second language code quickly and accurately, avoiding the problems of slow pixel string conversion, missed conversion, and incorrect conversion.

[0069] In this embodiment, when implementing the above-mentioned S203, which converts the pixel string into a root font size string to obtain the second abstract syntax tree according to the root font size and root font size unit preset in the configuration file of the language code processor, considering that the pixel string includes pixel values ​​and pixel units, it is necessary to first convert the pixel values ​​into root font size values ​​by using the preset root font size, and then replace the pixel units with the root font size units to convert the pixel string into a root font size string to obtain the second abstract syntax tree. Therefore, firstly, the root font size value corresponding to the pixel values ​​in the pixel string is determined by using the pixel values ​​in the pixel string and the preset root font size. Then, the pixel values ​​in the pixel string are replaced with the root font size values ​​corresponding to the pixel values ​​in the pixel string, and the pixel units in the pixel string are replaced with the root font size units to obtain the second abstract syntax tree. Based on this, this application provides a possible implementation method where the pixel string includes pixel values ​​and pixel units. The above-mentioned S203 may include, for example, the following S203a-S203b (not shown in the figure).

[0070] S203a: Determine the root font size value corresponding to the pixel value in the pixel string based on the pixel value in the pixel string and the preset root font size.

[0071] S203b: Based on the root font size value and root font size unit corresponding to the pixel value in the pixel string, perform unit replacement on the pixel value and pixel unit in the pixel string to obtain the second abstract syntax tree.

[0072] In the pixel string, the pixel value is the value before px in the string that starts with a number and ends with px. The root font size value corresponding to the pixel value is the pixel value divided by the preset root font size. The pixel unit is px.

[0073] The above steps S203a-S203b first calculate the root font size corresponding to the pixel values ​​in the pixel string based on the preset root font size, thus accurately determining the root font size value that the pixel values ​​need to be converted to when the pixel string is converted to the root font size string. Then, based on the root font size value and root font size unit corresponding to the pixel values ​​in the pixel string, the pixel values ​​and pixel units in the pixel string are replaced respectively, completing both the value replacement and the unit replacement. This accurately converts the pixel string to the root font size string, ensuring that the second abstract syntax tree includes the accurate root font size string corresponding to the pixel string.

[0074] As an example, based on the examples in S202-S203 above, the pixel value is a px value and the pixel unit is a px unit; the computer device determines that the root font size value corresponding to the px value in the px string is a rem value by using the px value in the px string and the preset rootFontSize; the px value in the px string is replaced with the rem value corresponding to the px value in the px string, and the px unit in the px string is replaced with the rem unit to obtain the second AST.

[0075] Furthermore, in this embodiment, after executing S201 to parse the first language code into a first abstract syntax tree, considering that the pixel string in the attribute value under a specific selector in the first language code does not need to be converted into a root font size string, a selector exclusion set formed by the target selector can be configured in the configuration file of the language code processor; when the preset selector in the first abstract syntax tree parsed from the first language code matches the target selector in the selector exclusion set, it is not necessary to match the pixel string through the target regular expression; when the preset selector in the first abstract syntax tree does not match the target selector in the selector exclusion set, it is necessary to match the pixel string through the target regular expression, thereby preventing the pixel string in the attribute value under the target selector in the first language code from being converted into a root font size string.

[0076] Therefore, for each preset selector in the first abstract syntax tree, it is determined whether the preset selector matches the target selector in the selector exclusion set. If so, the preset selector is determined as an exclusion selector. In the specific implementation of S202, which matches the pixel strings included in the preset attribute values ​​in the first abstract syntax tree using the target regular expression, it is not necessary to match the pixel strings included in the preset attribute values ​​under the exclusion selectors in the first abstract syntax tree. That is, the preset attribute values ​​under the exclusion selectors in the first abstract syntax tree are skipped. Instead, the pixel strings included in the preset attribute values ​​under the non-exclusion selectors in the first abstract syntax tree are matched using the target regular expression. Based on this, this application provides a possible implementation. The configuration file also includes a selector exclusion set formed by the target selector. The method may also include S1 (not shown in the figure): for each preset selector in the first abstract syntax tree, if the preset selector matches the target selector in the selector exclusion set, the preset selector is determined as an exclusion selector. Correspondingly, S202 may include S202a (not shown in the figure): according to the target regular expression, pixel matching is performed on the preset attribute values ​​under the non-exclusion selectors in the first abstract syntax tree to obtain pixel strings.

[0077] In this context, each preset selector in the first abstract syntax tree is a selector in the first language code; the target selector in the selector exclusion set is a pre-configured selector that does not need to implement the conversion of pixel strings to root font size strings; the exclusion selector is a selector that needs to be excluded from implementing the conversion of pixel strings to root font size strings; and the non-exclusion selector is a selector that implements the conversion of pixel strings to root font size strings.

[0078] When the configuration file also includes a selector exclusion set formed by the target selector, S1 and S202a above do not need to match the pixel strings in the preset selectors that match the target selector in the first abstract syntax tree parsed from the first language code by matching the target regular expression. Instead, they match the pixel strings in the preset selectors that do not match the target selector in the first abstract syntax tree. This avoids converting the pixel strings in the attribute values ​​under the target selector in the first language code into the root font size string. It achieves the exclusion of the pixel strings in the attribute values ​​under the target selector from being converted into the root font size string for the first language code. This allows for flexible exclusion of the pixel strings under a specific selector in the first language code from being converted into the root font size string.

[0079] As an example of S1 and S202a, based on the examples of S202-S203 above, the target selector is excludeSelector, and the selector exclusion set is excludeSelectors; postcss.config.js also includes excludeSelectors formed by excludeSelector. For each preset selector in the first AST, it is determined whether the preset selector matches excludeSelector in excludeSelectors. If so, the preset selector is determined as an exclusion selector, and the px string included in the preset attribute value under the non-exclusion selector in the first AST is matched by / (\d*\.?\d+)px / g.

[0080] In this embodiment of the application, the target selector in the selector exclusion set included in the above configuration file can be represented by a regular expression or a string; based on this, this application provides a possible implementation method in which the target selector is a selector regular expression or a selector string.

[0081] Here, the selector regular expression is the regular expression that matches the target selector, and the selector string is the string that represents the target selector.

[0082] When the target selector is a selector regular expression, the selector regular expression can quickly and accurately match the target selector, making the matching speed of the target selector in the first abstract syntax tree fast and the matching accuracy high, thereby improving the determination efficiency and accuracy of the exclusion selector in the first abstract syntax tree; when the target selector is a selector string, the selector string can intuitively and clearly represent the target selector, making the matching accuracy of the target selector in the first abstract syntax tree high, thereby improving the determination accuracy of the exclusion selector in the first abstract syntax tree.

[0083] As an example, based on the examples in S1 and S202a above, the excludeSelector in excludeSelectors can be / ^\.no-rem / . In / ^\.no-rem / , / / represents the beginning and end of the target regular expression, ^ represents the beginning of the string, and \.no-rem means matching .no-rem. Therefore, the default selector starting with .no-rem is an exclusion selector. All default property values ​​under the default selector starting with .no-rem, including the px string, will not be converted to the rem string.

[0084] Furthermore, in this embodiment, after executing S201 to parse the first language code into a first abstract syntax tree, considering that pixel strings in attribute values ​​under specific attributes in the first language code do not need to be converted into root font size strings, an attribute exclusion set formed by the target attribute can be configured in the configuration file of the language code processor. When the preset attribute in the first abstract syntax tree parsed from the first language code matches the target attribute in the attribute exclusion set, it is not necessary to match the pixel string using the target regular expression. When the preset attribute in the first abstract syntax tree does not match the target attribute in the attribute exclusion set, it is necessary to match the pixel string using the target regular expression, thereby preventing the pixel strings in attribute values ​​under the target attribute in the first language code from being converted into root font size strings.

[0085] Therefore, for each preset attribute in the first abstract syntax tree, it is determined whether the preset attribute matches the target attribute in the attribute exclusion set. If so, the preset attribute is determined as an excluded attribute. In the specific implementation of S202, which matches the pixel strings included in the preset attribute values ​​in the first abstract syntax tree using the target regular expression, it is not necessary to match the pixel strings included in the preset attribute values ​​under the excluded attributes in the first abstract syntax tree. That is, the preset attribute values ​​under the excluded attributes in the first abstract syntax tree are skipped. Instead, the pixel strings included in the preset attribute values ​​under the non-excluded attributes in the first abstract syntax tree are matched using the target regular expression. Based on this, this application provides a possible implementation. The configuration file also includes an attribute exclusion set formed by the target attribute. The method may also include S2 (not shown in the figure): for each preset attribute in the first abstract syntax tree, if the preset attribute matches the target attribute in the attribute exclusion set, the preset attribute is determined as an excluded attribute. Correspondingly, S202 may include S202b (not shown in the figure): according to the target regular expression, pixel matching is performed on the preset attribute values ​​under the non-excluded attributes in the first abstract syntax tree to obtain pixel strings.

[0086] In this context, each preset attribute in the first abstract syntax tree is a property in the first language code; the target attribute in the attribute exclusion set is a pre-configured attribute that does not need to be converted from a pixel string to a root font size string; the excluded attribute is an attribute to be excluded from converting a pixel string to a root font size string, and the non-excluded attribute is an attribute that converts a pixel string to a root font size string.

[0087] When the configuration file also includes an attribute exclusion set formed by the target attribute, S2 and S202b do not need to match the pixel strings in the preset attributes that match the target attribute in the first abstract syntax tree parsed from the first language code using the target regular expression. Instead, they match the pixel strings in the preset attributes that do not match the target attribute in the first abstract syntax tree. This avoids converting the pixel strings in the attribute values ​​under the target attribute in the first language code into the root font size string. This achieves the exclusion of the pixel strings in the attribute values ​​under the target attribute from being converted into the root font size string for the first language code, allowing for flexible exclusion of pixel strings under specific attributes in the first language code from being converted into the root font size string.

[0088] As an example of S2 and S202b, based on the examples of S202-S203 above, the target property is excludeProperty, and the property exclusion set is excludeProperties. postcss.config.js also includes excludeProperties formed by excludeProperty. For each preset property in the first AST, it is determined whether the preset property matches excludeProperty in excludeProperties. If so, the preset property is determined as an excluded property, and the px string included in the preset property value under the non-excluded property in the first AST is matched by / (\d*\.?\d+)px / g.

[0089] Furthermore, in this embodiment, after determining that each preset selector in the first abstract syntax tree matches the target selector in the selector exclusion set and identifying the preset selector as the exclusion selector in S1, considering that pixel strings in attribute values ​​under specific attributes in the first language code do not need to be converted into root font size strings, the attribute exclusion set formed by the target attribute can be configured in the configuration file of the language code processor. When the preset attribute in the first abstract syntax tree parsed by the first language code matches the target attribute in the attribute exclusion set, it is not necessary to match the pixel string through the target regular expression. When the preset attribute in the first abstract syntax tree does not match the target attribute in the attribute exclusion set, it is necessary to match the pixel string through the target regular expression, thereby preventing the pixel string in the attribute value under the target attribute in the first language code from being converted into the root font size string.

[0090] Therefore, for each preset attribute in the first abstract syntax tree, it is determined whether the preset attribute matches the target attribute in the attribute exclusion set. If so, the preset attribute is determined as an excluded attribute. In the specific implementation of S202a above, when matching the pixel string included in the preset attribute value under the non-excluded selector in the first abstract syntax tree using the target regular expression, it is not necessary to match the pixel string included in the preset attribute value of the excluded attribute under the non-excluded selector in the first abstract syntax tree. That is, skip the preset attribute value of the excluded attribute under the non-excluded selector in the first abstract syntax tree, and instead match the pixel string included in the preset attribute value of the non-excluded attribute under the non-excluded selector in the first abstract syntax tree using the target regular expression. Based on this, this application provides a possible implementation method. The configuration file also includes an attribute exclusion set formed by the target attribute. The method may also include, for example, S3 (not shown in the figure): for each preset attribute in the first abstract syntax tree, if the preset attribute matches the target attribute in the attribute exclusion set, the preset attribute is determined to be an excluded attribute. Correspondingly, the above S202a may include, for example, S202aa (not shown in the figure): according to the target regular expression, perform pixel matching on the preset attribute values ​​of the non-excluded attributes under the non-excluded selector in the first abstract syntax tree to obtain a pixel string.

[0091] In this context, each preset attribute in the first abstract syntax tree is a property in the first language code; the target attribute in the attribute exclusion set is a pre-configured attribute that does not need to be converted from a pixel string to a root font size string; the excluded attribute is an attribute to be excluded from converting a pixel string to a root font size string, and the non-excluded attribute is an attribute that converts a pixel string to a root font size string.

[0092] When the configuration file also includes an attribute exclusion set formed by the target attribute, S3 and S202 aa above do not need to match the pixel string of the preset attribute that matches the target attribute under the non-exclusion selector in the first abstract syntax tree parsed from the first language code through the target regular expression. Instead, they match the pixel string of the preset attribute that does not match the target attribute under the non-exclusion selector in the first abstract syntax tree. This avoids converting the pixel string of the attribute value under the target attribute under the non-exclusion selector in the first language code into the root font size string. This achieves the conversion of the pixel string of the attribute value under the target attribute into the root font size string for the non-exclusion selector in the first language code, so that the pixel string under the specific attribute of the non-exclusion selector in the first language code can be flexibly excluded.

[0093] As an example of S3 and S202 aa, based on the examples of S1 and S202a above, the target property is excludeProperty, and the property exclusion set is excludeProperties; postcss.config.js also includes excludeProperties formed by excludeProperty. For each preset property in the first AST, it is determined whether the preset property matches excludeProperty in excludeProperties. If so, the preset property is determined as an excluded property, and the px string included in the preset property value of the non-excluded property under the non-excluded selector in the first AST is matched by / (\d*\.?\d+)px / g.

[0094] In this embodiment, the target attribute in the attribute exclusion set included in the configuration file can be represented by a string. Based on this, this application provides a possible implementation where the target attribute is an attribute string.

[0095] Among them, the attribute string is a string that represents the target attribute.

[0096] In this approach, the target attribute is an attribute string that can intuitively and clearly represent the target attribute, which makes the matching accuracy of the target attribute in the first abstract syntax tree high, thereby improving the determination accuracy of the excluded attribute in the first abstract syntax tree.

[0097] As an example, based on the examples S2, S202b, S3 and S202c above, excludeProperty in excludeProperties can be 'border'. In this 'border', "" indicates the beginning and end of the property string. Therefore, border is an excluded property. In the first AST, the px string included in the border property value will not be converted to the rem string.

[0098] Furthermore, in this embodiment, before executing S203 to convert the pixel string into a root font size string to obtain the second abstract syntax tree according to the root font size and root font size unit preset in the language code processor's configuration file, it is necessary to determine the preset root font size required to convert the pixel string into a root font size string. Considering that a specific root font size is used to change the layout ratio of the webpage under specific media query conditions to adapt to adaptive layouts under different screen sizes and devices, the target root font size corresponding to the target media query condition can be configured in the language code processor's configuration file. When the language rule to which the pixel string belongs is a non-media query rule, the default root font size in the configuration file is determined as the preset root font size. When the language rule to which the pixel string belongs is a media query rule, the preset root font size is determined from the target root font size corresponding to the target media query condition and the default root font size based on the matching result between the preset media query condition corresponding to the pixel string and the target media query condition. Based on this, this application provides a possible implementation method, in which the configuration file also includes the target root font size corresponding to the target media query condition; the step of determining the preset root font size may include, for example, the following S4-S5 (not shown in the figure).

[0099] S4: If the language rule to which the pixel string belongs is a non-media query rule, determine the preset root font size based on the default root font size in the configuration file.

[0100] S5: If the language rule to which the pixel string belongs is a media query rule, determine the preset root font size from the target root font size and the default root font size corresponding to the target root font size, based on the matching result between the preset media query condition corresponding to the pixel string and the target media query condition.

[0101] Among them, the target root font size corresponding to the target media query condition is the root font size under the pre-configured specific media query condition, the language rule to which the pixel string belongs is the language rule corresponding to the preset attribute value, preset attribute and preset selector of the pixel string, the non-media query rule is the language rule that does not include the media query condition, the default root font size is the pre-configured baseline root font size, the media query rule is the language rule that includes the media query condition, and the matching result indicates whether the preset media query condition corresponding to the pixel string matches the target media query condition.

[0102] Based on the target root font size corresponding to the target media query conditions in the configuration file, S4-S5 above, when the language rule to which the pixel string belongs is a non-media query rule, the preset root font size is the default root font size, so that the pixel string can be converted into the root font size string according to the default root font size for non-media queries. When the language rule to which the pixel string belongs is a media query rule, the preset root font size needs to be determined from the target root font size or the default root font size based on the matching result between the preset media query conditions and the target media query conditions, so that the pixel string can be flexibly converted into the root font size string according to the target root font size or the default root font size for media queries. This allows for flexible customization of the conversion of pixel strings into root font size strings under media queries, laying the foundation for more accurate conversion of pixel strings included in the preset attribute values ​​in the first abstract syntax tree into root font size strings.

[0103] As an example of S4-S5, based on the examples of S202-S203 above, the default root font size is the default rootFontSize: 16; postcss.config.js also includes the target root font size corresponding to the target media query condition. When the language rule to which the px string belongs is a non-media query rule, the computer device will determine the default rootFontSize: 16 in postcss.config.js as the preset rootFontSize; when the language rule to which the px string belongs is a media query rule, the computer device will determine the preset rootFontSize based on the matching result between the preset media query condition corresponding to the px string and the target media query condition, from the target root font size corresponding to the target media query condition and the default rootFontSize: 16.

[0104] The target root font size corresponding to the target media query condition can be as follows:

[0105] mediaQueries:{

[0106] '(min-width:768px)':18,

[0107] '(min-width:1024px)':20,

[0108] }

[0109] That is, the target root font size corresponding to the target media query condition min-width:768px is 18, and the target root font size corresponding to the target media query condition min-width:1024px is 20.

[0110] See Figure 4 ,Should Figure 4 This is a schematic diagram of a language code processing flow provided in an embodiment of this application. The flow includes: reading first language code, reading the configuration file of a language code processor, parsing the first language code, matching pixel strings and converting them into root font size strings, and generating second language code. Specifically, parsing the first language code refers to parsing the first language code describing the style of a webpage file into a first abstract syntax tree; matching pixel strings and converting them into root font size strings refers to matching pixel strings containing preset attribute values ​​in the first abstract syntax tree using a target regular expression, and converting the pixel strings into root font size strings according to the preset root font size and root font size unit in the language code processor's configuration file to obtain a second abstract syntax tree. This conversion of matching pixel strings into root font size strings distinguishes between non-media query cases and media query cases; generating second language code refers to generating second language code based on the second abstract syntax tree.

[0111] In this embodiment, when determining the preset root font size from the target root font size and the default root font size based on the matching result of the preset media query condition and the target media query condition corresponding to the pixel string in S5, the matching result may indicate that the preset media query condition corresponding to the pixel string matches the target media query condition, meaning that the pixel string needs to be converted into a root font size string according to the target root font size corresponding to the target media query condition. In this case, the target root font size corresponding to the target media query condition is determined as the preset root font size. Based on this, this application provides a possible implementation: the step of determining the preset root font size from the target root font size and the default root font size corresponding to the target media query condition based on the matching result of the preset media query condition and the target media query condition in S5 may include, for example, S5a (not shown in the figure): if the matching result is that the preset media query condition matches the target media query condition, the target root font size corresponding to the target media query condition is determined as the preset root font size.

[0112] When the preset media query condition corresponding to the pixel string in the matching result S5a matches the target media query condition, the target root font size corresponding to the target media query condition is determined as the preset root font size, so that the pixel string can be converted into the root font size string according to the target root font size corresponding to the target media query condition, making the conversion of the pixel string into the root font size string under the preset media query condition that matches the target media query condition more accurate.

[0113] As an example of S5a, based on the examples of S4-S5 above, the matching result indicates that the preset media query condition corresponding to the px string matches the target media query condition, and the target root font size corresponding to the target media query condition is determined as the preset rootFontSize.

[0114] In this embodiment, when determining the specific implementation of the preset root font size from the target root font size and the default root font size based on the matching result of the preset media query condition corresponding to the pixel string and the target media query condition in S5, the matching result may indicate that the preset media query condition corresponding to the pixel string does not match the target media query condition, meaning that it is not necessary to convert the pixel string into a root font size string according to the target root font size corresponding to the target media query condition. In this case, the default root font size is determined as the preset root font size. Based on this, this application provides a possible implementation method. The step of determining the preset root font size from the target root font size and the default root font size based on the matching result of the preset media query condition corresponding to the pixel string and the target media query condition in S5 may include, for example, S5b (not shown in the figure): if the matching result is that the preset media query condition does not match the target media query condition, the default root font size is determined as the preset root font size.

[0115] When the preset media query condition corresponding to the pixel string in the matching result does not match the target media query condition, the default root font size is determined to be the preset root font size in S5b above. This is so that the pixel string can be converted into the root font size string according to the default root font size in the subsequent process. This ensures that the pixel string under the preset media query condition that does not match the target media query condition can also be accurately converted into the root font size string.

[0116] As an example of S5b, based on the examples of S4-S5 above, the matching result indicates that the preset media query condition corresponding to the px string matches the target media query condition, and the default rootFontSize: 16 is determined as the preset rootFontSize.

[0117] Based on the examples S4-S5, S5a, and S5b above, when the language rule to which the pixel string belongs is .container{font-size:32px;}, this .container{font-size:32px;} is a non-media query rule. The default rootFontSize in postcss.config.js is set to 16 as the preset rootFontSize. Using 16 and the rem unit, the px string: 32px is converted to the rem string: 2rem. Therefore, .container{font-size:32px;} is converted to .container{font-size:2rem;}.

[0118] When the language rule of the pixel string is `@media(min-width:768px){.container{font-size:48px;}}`, this `@media(min-width:768px){.container{font-size:48px;}}` is a media query rule. The preset media query condition is: `(min-width:768px)`. The target media query condition is: `(min-width:768px)`. The target root font size corresponding to `(min-width:768px)`, 18, is determined as the preset `rootFontSize`. According to 18 and the rem unit, the px string: 48px is converted to the rem string: 2.67rem. Therefore, `@media(min-width:768px){.container{font-size:48px;}}` is converted to `@media(min-width:768px){.container{font-size:2.67rem;}}`.

[0119] When the language rule of the pixel string is `@media(min-width:1024px){.container{font-size:64px;}}`, this `@media(min-width:1024px){.container{font-size:64px;}}` is a media query rule. The preset media query condition is `(min-width:1024px)`, which matches the target media query condition `(min-width:1024px)`. The target root font size corresponding to `(min-width:1024px)`, 20, is determined as the preset `rootFontSize`. Based on 20 and the rem unit, the px string `64px` is converted to the rem string `3.2rem`. Therefore, `@media(min-width:1024px){.container{font-size:64px;}}` is converted to `@media(min-width:1024px){.container{font-size:3.2rem;}}`.

[0120] When the language rule for the pixel string is `@media(min-width:375px){.container{font-size:64px;}}`, this `@media(min-width:375px){.container{font-size:64px;}}` is a media query rule. The default media query condition is: `(min-width:375px)` does not match the target media query condition. The default rootFontSize in `postcss.config.js` is set to 16. Based on 16 and the rem unit, the px string `64px` is converted to the rem string `4rem`. Therefore, `@media(min-width:375px){.container{font-size:64px;}}` is transformed into `@media(min-width:375px){.container{font-size:4rem;}}`.

[0121] In this embodiment, when specifically implementing the generation of second language code based on the second abstract syntax tree in S204, considering that the preset selectors, preset attributes, and preset attribute values ​​in the second abstract syntax tree are closely related to the language rules of the language code, and that the comment information and formatting information in the second abstract syntax tree are closely related to the readability of the language code, the second language code is generated based on the preset selectors, preset attributes, preset attribute values, comment information, and formatting information in the second abstract syntax tree. Based on this, this application provides a possible implementation, where S204 may include, for example, S204a (not shown in the figure): generating code from the second abstract syntax tree according to the preset selectors, preset attributes, preset attribute values, comment information, and formatting information in the second abstract syntax tree to obtain the second language code.

[0122] The annotation information in the second abstract syntax tree is the same as the annotation information in the first abstract syntax tree, that is, the textual information in the first language code that explains or describes the language code. The formatting information in the second abstract syntax tree is the same as the formatting information in the first abstract syntax tree, that is, the formatting information of the language code in the first language code.

[0123] When generating second language code based on the second abstract syntax tree, S204a not only focuses on the preset selectors, preset attributes, and preset attribute values ​​in the second abstract syntax tree to make the second language code conform to the language rules in the second abstract syntax tree, but also focuses on the comment information and formatting information in the second abstract syntax tree, that is, it focuses on the comment information and formatting information in the first abstract syntax tree parsed from the first language code, so that the second language code retains the comment information and formatting information in the first language code, thereby ensuring the readability of the second language code.

[0124] As an example of S204a, based on the example of S204 above, the computer device generates second CSS code based on the preset selectors, preset attributes, preset attribute values, comment information, and formatting information in the second AST.

[0125] Furthermore, the language code processing method provided in this application embodiment can further enhance user experience and developer friendliness by providing real-time preview and debugging functions, as well as a visual configuration interface; and improve the conversion speed and build efficiency of large-scale language code through incremental processing, caching mechanisms, and parallel processing technology. In addition, the language code processor implementing the language code processing method provided in this application embodiment has good cross-version compatibility and modular design, provides open application programming interfaces, and supports functional expansion and customization.

[0126] In summary, in daily front-end project development, facing the challenge of multi-device adaptation, the language code processing method provided in this application automatically converts pixel strings to root font size strings. This quickly and accurately converts pixel strings in the first language code into root font size strings to obtain the second language code, avoiding issues such as slow pixel string conversion, missed conversions, and incorrect conversions. By adjusting the root font size, it is easier to change the layout ratio of the webpage to adapt to different screen sizes and devices, improving design flexibility and responsiveness, increasing development efficiency, and making the design easier to maintain, thereby ensuring a consistent user experience across devices.

[0127] Furthermore, the language code processor that implements the language code processing method provided in this application embodiment is seamlessly integrated into the build process of frameworks such as React and Vue.js, automatically converting pixel strings to root font size strings, avoiding slow pixel string conversion, missed conversion, and incorrect conversion. This not only significantly improves code consistency and maintainability, but also effectively speeds up the build process, allowing developers to focus more on the implementation of business logic and innovative functions, thereby comprehensively improving the overall development efficiency and user experience quality of the project.

[0128] It should be noted that, based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods.

[0129] based on Figure 2 In accordance with the language code processing method provided in the corresponding embodiments, this application also provides a language code processing apparatus, see below. Figure 5 ,Should Figure 5 The present application provides a structural diagram of a language code processing device 500, which includes: a parsing unit 501, a matching unit 502, a conversion unit 503, and a generation unit 504.

[0130] Parsing unit 501 is used to perform syntax parsing on the first language code to obtain the first abstract syntax tree; the first language code is the language code that describes the style of the web page file.

[0131] Matching unit 502 is used to perform pixel matching on preset attribute values ​​in the first abstract syntax tree according to the target regular expression to obtain pixel strings; the target regular expression is used to match pixel strings;

[0132] The conversion unit 503 is used to convert the pixel string to a second abstract syntax tree based on the root font size and root font size unit preset in the configuration file of the language code processor; the second abstract syntax tree includes the root font size string corresponding to the pixel string;

[0133] Generation unit 504 is used to generate code from the second abstract syntax tree to obtain second language code.

[0134] In one possible implementation, the pixel string includes pixel values ​​and pixel units, and the conversion unit 503 is used for:

[0135] Determine the root font size value corresponding to the pixel value in the pixel string based on the pixel value in the pixel string and the preset root font size;

[0136] Based on the root font size value and root font size unit corresponding to the pixel value in the pixel string, the unit of the pixel value and pixel unit in the pixel string is replaced to obtain the second abstract syntax tree.

[0137] In one possible implementation, the configuration file also includes a selector exclusion set formed by the target selector, and the language code processing device 500 further includes: a first determining unit;

[0138] The first determining unit is used to determine the preset selector as the exclusion selector if, for each preset selector in the first abstract syntax tree, the preset selector matches the target selector in the selector exclusion set.

[0139] Matching unit 502 is used for:

[0140] Based on the target regular expression, perform pixel matching on the preset attribute values ​​under the non-exclusion selector in the first abstract syntax tree to obtain the pixel string.

[0141] In one possible implementation, the target selector is a selector regular expression or a selector string.

[0142] In one possible implementation, the configuration file also includes an attribute exclusion set formed by the target attributes, and the language code processing device 500 further includes: a second determining unit;

[0143] The second determining unit is used to determine the preset attribute as an exclusion attribute if the preset attribute matches the target attribute in the attribute exclusion set for each preset attribute in the first abstract syntax tree.

[0144] Matching unit 502 is used for:

[0145] Based on the target regular expression, perform pixel matching on the preset attribute values ​​under the non-excluded attributes in the first abstract syntax tree to obtain the pixel string.

[0146] In one possible implementation, the configuration file also includes an attribute exclusion set formed by the target attributes, and the first determining unit is further used for:

[0147] For each preset attribute in the first abstract syntax tree, if the preset attribute matches the target attribute in the attribute exclusion set, the preset attribute is determined to be an exclusion attribute.

[0148] Matching unit 502 is used for:

[0149] Based on the target regular expression, pixel matching is performed on the preset attribute values ​​of non-excluded attributes under the non-excluded selector in the first abstract syntax tree to obtain pixel strings.

[0150] In one possible implementation, the target attribute is an attribute string.

[0151] In one possible implementation, the configuration file also includes the target root font size corresponding to the target media query conditions; the language code processing device 500 also includes: a third determining unit and a fourth determining unit;

[0152] The third determining unit is used to determine the preset root font size based on the default root font size in the configuration file if the language rule to which the pixel string belongs is a non-media query rule.

[0153] The fourth determining unit is used to determine the preset root font size from the target root font size and the default root font size, based on the matching result between the preset media query condition corresponding to the pixel string and the target media query condition, if the language rule to which the pixel string belongs is a media query rule.

[0154] In one possible implementation, the fourth determining unit is used for:

[0155] If the matching result is that the preset media query condition matches the target media query condition, the target root font size corresponding to the target media query condition is determined to be the preset root font size.

[0156] In one possible implementation, the fourth determining unit is used for:

[0157] If the matching result is that the preset media query conditions do not match the target media query conditions, the default root font size is determined to be the preset root font size.

[0158] In one possible implementation, the generation unit 504 is used for:

[0159] Based on the preset selectors, preset attributes, preset attribute values, comment information, and formatting information in the second abstract syntax tree, code is generated from the second abstract syntax tree to obtain second language code.

[0160] As can be seen from the above technical solution, parsing the first language code describing the webpage file style into a first abstract syntax tree (AST) and representing the syntax structure information of the language code in a tree structure makes the syntax structure information of the first language code more intuitive and clear, facilitating subsequent fast and accurate matching of pixel strings in the first language code. The pixel strings included in the preset attribute values ​​in the first abstract syntax tree are matched using a target regular expression. Based on the preset root font size and root font size unit in the language code processor's configuration file, the pixel strings are converted into root font size strings to obtain the second abstract syntax tree. The target regular expression can quickly and accurately match pixel strings, making the matching speed and accuracy of the pixel strings included in the preset attribute values ​​in the first abstract syntax tree fast and accurate. Therefore, based on the preset root font size and root font size unit, the pixel strings included in the preset attribute values ​​in the first abstract syntax tree are quickly and accurately converted into root font size strings, ensuring that the second abstract syntax tree includes root font size strings, not pixel strings. The second language code is generated based on the second abstract syntax tree. The syntax structure information of the tree structure is converted into language code. The pixel string in the first language code is converted into the root font size string to obtain the second language code quickly and accurately, avoiding the problems of slow pixel string conversion, missed conversion, and incorrect conversion.

[0161] This application also provides a computer device, which may be a server, see [link to previous document]. Figure 6 ,Should Figure 6 This application provides a structural diagram of a server 600. The server 600 can vary significantly due to different configurations or performance characteristics. It may include one or more processors, such as a central processing unit (CPU) 622, and a memory 632, as well as one or more storage media 630 (e.g., one or more mass storage devices) for storing application programs 642 or data 644. The memory 632 and storage media 630 can be temporary or persistent storage. The program stored in the storage media 630 may include one or more modules (not shown in the diagram), each module including a series of instruction operations on the server. Furthermore, the CPU 622 may be configured to communicate with the storage media 630 and execute the series of instruction operations stored in the storage media 630 on the server 600.

[0162] Server 600 may also include one or more power supplies 626, one or more wired or wireless network interfaces 650, one or more input / output interfaces 658, and / or one or more operating systems 641, such as Windows Server. TM Mac OS X TM Unix TM LinuxTM FreeBSD TM etc.

[0163] In this embodiment, the central processing unit 622 in the server 600 can execute the methods provided in the various optional implementations of the above embodiments.

[0164] The computer device provided in this application embodiment can also be a terminal, see [link to relevant documentation]. Figure 7 ,Should Figure 7 This is a structural diagram of a terminal provided in an embodiment of this application. Taking a smartphone as an example, the smartphone includes components such as a radio frequency (RF) circuit 710, a memory 720, an input unit 730, a display unit 740, a sensor 750, an audio circuit 760, a wireless Fidelity (WiFi) module 770, a processor 780, and a power supply 790. The input unit 730 may include a touch panel 731 and other input devices 732, the display unit 740 may include a display panel 741, and the audio circuit 760 may include a speaker 761 and a microphone 762. Those skilled in the art will understand that... Figure 7 The smartphone structure shown does not constitute a limitation on smartphones and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0165] The memory 720 can be used to store software programs and modules. The processor 780 executes various functions and data processing of the smartphone by running the software programs and modules stored in the memory 720. The memory 720 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created based on the use of the smartphone (such as audio data, phonebook, etc.). In addition, the memory 720 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0166] The processor 780 is the control center of the smartphone, connecting various parts of the smartphone via various interfaces and lines. It performs various functions and processes data by running or executing software programs and / or modules stored in the memory 720, and by accessing data stored in the memory 720. Optionally, the processor 780 may include one or more processing units; preferably, the processor 780 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 780.

[0167] In this embodiment, the processor 780 in the smartphone can execute the methods provided in the various optional implementations of the above embodiments.

[0168] According to one aspect of this application, a computer-readable storage medium is provided for storing a computer program that, when run on a computer device, causes the computer device to perform the methods provided in various optional implementations of the above embodiments.

[0169] According to one aspect of this application, a computer program product is provided, comprising a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium and executes the computer program, causing the computer device to perform the methods provided in various optional implementations of the above embodiments.

[0170] The descriptions of the processes or structures corresponding to the above figures each have their own emphasis. For parts of a process or structure that are not described in detail, please refer to the relevant descriptions of other processes or structures.

[0171] The terms "first," "second," etc., used in this application's specification and the foregoing drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented, for example, in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0172] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.

[0173] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0174] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0175] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing computer programs, such as USB flash drives, portable hard drives, read-only memory (ROM), RAM, magnetic disks, or optical disks.

[0176] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.

[0177] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A language code processing method, characterized in that, The method includes: The first language code is parsed to obtain the first abstract syntax tree; the first language code is the language code that describes the style of the web page file. Based on the target regular expression, pixel matching is performed on the preset attribute values ​​in the first abstract syntax tree to obtain a pixel string; the target regular expression is used to match the pixel string. Based on the root font size and root font size unit preset in the language code processor's configuration file, the pixel string is converted to a unit to obtain a second abstract syntax tree; the second abstract syntax tree includes the root font size string corresponding to the pixel string; Code is generated from the second abstract syntax tree to obtain second language code.

2. The method according to claim 1, characterized in that, The pixel string includes pixel values ​​and pixel units. The step of converting the pixel string to a unit based on the root font size and root font size unit preset in the language code processor's configuration file to obtain the second abstract syntax tree includes: Based on the pixel values ​​in the pixel string and the preset root font size, determine the root font size value corresponding to the pixel values ​​in the pixel string; Based on the root font size value corresponding to the pixel value in the pixel string and the root font size unit, the pixel value and pixel unit in the pixel string are replaced with units to obtain the second abstract syntax tree.

3. The method according to claim 2, characterized in that, The configuration file also includes a selector exclusion set formed by the target selector, and the method further includes: For each preset selector in the first abstract syntax tree, if the preset selector matches the target selector in the selector exclusion set, the preset selector is determined to be an exclusion selector; The step of performing pixel matching on preset attribute values ​​in the first abstract syntax tree according to the target regular expression to obtain a pixel string includes: Based on the target regular expression, pixel matching is performed on the preset attribute values ​​under the non-exclusion selector in the first abstract syntax tree to obtain the pixel string.

4. The method according to claim 3, characterized in that, The target selector is a selector regular expression or a selector string.

5. The method according to claim 1, characterized in that, The configuration file also includes an attribute exclusion set formed by the target attributes, and the method further includes: For each preset attribute in the first abstract syntax tree, if the preset attribute matches the target attribute in the attribute exclusion set, the preset attribute is determined to be an exclusion attribute. The step of performing pixel matching on preset attribute values ​​in the first abstract syntax tree according to the target regular expression to obtain a pixel string includes: Based on the target regular expression, pixel matching is performed on the preset attribute values ​​under the non-excluded attributes in the first abstract syntax tree to obtain the pixel string.

6. The method according to claim 3, characterized in that, The configuration file also includes an attribute exclusion set formed by the target attributes, and the method further includes: For each preset attribute in the first abstract syntax tree, if the preset attribute matches the target attribute in the attribute exclusion set, the preset attribute is determined to be an exclusion attribute. The step of performing pixel matching on preset attribute values ​​in the first abstract syntax tree according to the target regular expression to obtain a pixel string includes: Based on the target regular expression, pixel matching is performed on the preset attribute values ​​of non-excluded attributes under the non-excluded selector in the first abstract syntax tree to obtain the pixel string.

7. The method according to claim 5 or 6, characterized in that, The target attribute is an attribute string.

8. The method according to claim 1, characterized in that, The configuration file also includes the target root font size corresponding to the target media query conditions; the steps for determining the preset root font size include: If the language rule to which the pixel string belongs is a non-media query rule, the preset root font size is determined according to the default root font size in the configuration file; If the language rule to which the pixel string belongs is a media query rule, the preset root font size is determined from the target root font size corresponding to the target media query condition and the default root font size, based on the matching result between the preset media query condition corresponding to the pixel string and the target media query condition.

9. The method according to claim 8, characterized in that, The step of determining the preset root font size from the target root font size corresponding to the target media query condition and the default root font size based on the matching result between the preset media query condition corresponding to the pixel string and the target media query condition includes: If the matching result is that the preset media query condition matches the target media query condition, the target root font size corresponding to the target media query condition is determined to be the preset root font size.

10. The method according to claim 8, characterized in that, The step of determining the preset root font size from the target root font size corresponding to the target media query condition and the default root font size based on the matching result between the preset media query condition corresponding to the pixel string and the target media query condition includes: If the matching result is that the preset media query condition does not match the target media query condition, the default root font size is determined to be the preset root font size.

11. The method according to claim 1, characterized in that, The step of generating code from the second abstract syntax tree to obtain second language code includes: Based on the preset selectors, preset attributes, preset attribute values, comment information, and formatting information in the second abstract syntax tree, code is generated from the second abstract syntax tree to obtain the second language code.

12. A language code processing device, characterized in that, The device includes: a parsing unit, a matching unit, a conversion unit, and a generation unit; The parsing unit is used to perform syntax parsing on the first language code to obtain a first abstract syntax tree; the first language code is language code describing the style of a web page file; The matching unit is used to perform pixel matching on preset attribute values ​​in the first abstract syntax tree according to a target regular expression to obtain a pixel string; the target regular expression is used to match the pixel string. The conversion unit is used to perform unit conversion on the pixel string according to the root font size and root font size unit preset in the configuration file of the language code processor to obtain a second abstract syntax tree; the second abstract syntax tree includes the root font size string corresponding to the pixel string; The generation unit is used to generate code from the second abstract syntax tree to obtain second language code.

13. A computer device, characterized in that, The computer device includes a processor and memory: The memory is used to store computer programs and to transfer the computer programs to the processor; The processor is configured to execute the method according to any one of claims 1-11 according to instructions in the computer program.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program that, when run on a computer device, causes the computer device to perform the method according to any one of claims 1-11.

15. A computer program product, comprising a computer program, characterized in that, When the computer program is run on a computer device, it causes the computer device to perform the method according to any one of claims 1-11.