首页 > 其他分享 >翻译

翻译

时间:2024-05-21 14:52:32浏览次数:7  
标签:digits 翻译 LPeg pattern d% patterns match

Mastering LPeg
by Roberto Ierusalimschy
(Version 1.0)
LPeg is a pattern-matching library for Lua, based on Parsing Expression Grammars. LPeg performs all tasks of a typical regex system, but it goes well beyond
that. Among other tasks, we can write entire parsers with LPeg, with scanners
included.
For us, pattern matching is a system for finding and extracting pieces of information from a text. For instance, we may want to find a line starting with
“From:” in an email message and extract the rest of the line; we may have an
XML document and want to extract all emphasized text, that is, text written
between <em> and </em>; we may have a list of license plates and want to find
all plates that are palindromes or that start with a given prefix. We may want
to determine whether a sequence of characters is a valid identifier in C, that is,
a letter or underscore followed by zero or more letters or underscores or digits;
moreover, the sequence cannot be equal to a reserved word.
Most pattern-matching systems are based on regexes, also called regular expressions. (Most regex systems are extensions of the original regular-expression
definition that break the nice properties of the original. For that reason, I prefer
to save the name “regular expression” for the original definition and use the
term “regex” for those extensions.) A regex is a string that specifies a pattern
and occasionally what to extract from a match—an occurrence of that pattern
in a text. As a simple example, consider the following Lua code:
subject = "birth date: 12/03/1980"
pattern = "(%d%d)/(%d%d)/(%d%d%d%d)"
d, m, y = string.match(subject, pattern)
print(d, m, y) --> 12 03 1980
(Remember that, in Lua, a function can return multiple values.) In the pattern,
"%d" represents any digit, "/" represents itself, and the parentheses delimit
the captures, which is what to extract from the match. So, in this example,
pattern means any two digits followed by a slash followed by two digits followed
by another slash followed by four digits, capturing the three groups of digits.
The function string.match searches for that pattern in the subject; if if finds
a match, it returns the captured values, that is, the parts of the subject that
matched the parenthesized parts of the pattern.
Unlike most other pattern-matching systems, LPeg is not based on regexes.
Following the Snobol tradition, LPeg defines patterns as first-class objects. This
means that patterns are handled like regular Lua values. The LPeg library offers
several functions to create and compose patterns; with the use of metamethods,
several of these functions are provided as infix or prefix operators. On the
one hand, the result is usually much more verbose than the typical encoding
of patterns using regexes. On the other hand, first-class patterns allow us to
create patterns piecemeal; it is easy to test each piece independently, to properly
document them with good names and comments, to reuse those pieces, and to
compose them to create more complex patterns. In other words, we can create

 

标签:digits,翻译,LPeg,pattern,d%,patterns,match
From: https://www.cnblogs.com/kehuadong/p/18204043

相关文章

  • ComfyUI安装ComfyUI-Manager管理器和翻译插件
    进到ComfyUI\custom_nodes目录克隆https://github.com/ltdrdata/ComfyUI-Manager源码到ComfyUI\custom_nodes下然后进入到ComfyUI-Manager,执行pipinstall-rrequirements.txt启动\重启ComfyUI安装翻译插件点击Manager按钮搜索AIGODLIKE-COMFYUI-TRANSLATION安装......
  • Stable Diffusion webui.sh(Version: v1.9.3)选项翻译
    补充解释:Linux/iOS的目录==Windows文件夹options选项:-h,--help显示帮助信息并退出程序 showthishelpmessageandexit--update-all-extensions在启动时更新所有扩展插件 (此为launch.py脚本的参数,下同)launch.pyargument:downloadupdatesforallextensi......
  • 【翻译】《血母蔭身》 - 珂拉琪 Collage
    闽南语有独特的节奏美感,翻译尽量忠于歌词划分,参考YouTube字幕翻译。「前陰已謝,後陰未至,中陰現前。」注:语出《地藏菩萨本愿经》,意指人从去世后意识出窍到转世投胎的过程。前阴已谢,指人此期寿命已尽。后阴未至,指人的灵魂还未转世投胎。中阴现前,指人处于去世后意识出窍,且......
  • aardio爬虫) 实战篇:逆向有道翻译web接口
    前言之前的文章把js引擎(aardio封装库)微软开源的js引擎(ChakraCore))写好了,这篇文章整点js代码来测一下bug。测试网站:https://fanyi.youdao.com/index.html#/逆向思路逆向思路可以看有道翻译js逆向(MD5加密,AES加密)附完整源码,逆向我就不赘述了。这篇文章说一下怎么将文章中给的......
  • 一个服务提供翻译功能,一个服务提供商品名字查询功能,客户端有多语言需求,语言占比不一样
    针对这两个服务的多语言需求和商品信息查询功能,可以设计以下测试用例:基本功能测试:1.1翻译服务:-测试用例1:输入包含英文商品信息的请求,验证翻译服务是否能够正确将英文翻译成其他语言。-测试用例2:输入包含中文商品信息的请求,验证翻译服务是否能够正确将中文翻译成其他语......
  • 【翻译】RISC-V裸机编程指南(Bare metal programming with RISC-V guide)
    RISC-V裸机编程指南(BaremetalprogrammingwithRISC-Vguide)作者:Follow@popovicu94原文链接:https://popovicu.com/posts/bare-metal-programming-risc-v/今天,我们将探讨如何为RISC-V架构的机器编写一个裸机程序。为了确保可复现,目标平台选择为QEMUriscv64virt虚拟机......
  • Visual Studio Code 检测到#include 错误,请更新includepath。已为此翻译单元 禁用波
    以上问题的出现是因为visualstudiocode的环境没有配置好在界面中按ctrl+shft+p输入Cconfiguration选择上图蓝色框 在上面红色框填上正确的路径(如果没有这个路径要在https://sourceforge.net/projects/mingw-w64/下载MinGW,具体操作b站有可以去看看照着下载)因为用的是c......
  • 使用pyppeteer 下载chromium 报错 python pyppeteer 调用谷歌翻译api
    https://registry.npmmirror.com/binary.html?path=chromium-browser-snapshots/Win_x64/手动下载安装包 修改文件C:\Users\luyan\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyppeteer\chromium_downloader.py #修改这段代码defdownload_chromium()-......
  • puppeteer 调用谷歌翻译api
    npmi puppeteerindex.jsconstpuppeteer=require('puppeteer');asyncfunctiontranslateText(text,sl,tl){ constbrowser=awaitpuppeteer.launch(); constpage=awaitbrowser.newPage(); awaitpage.goto(  `http://translate.google.co......
  • 1.某道翻译js逆向sign值
    首先找到这个请求接口这个接口就是我们请求翻译的接口发现有个sign值,这就是我们需要逆向的值再看看这个接口的响应可以发现这个响应是被加密的,我们还需要去逆向解密这个被加密的响应,这篇就单纯讲一下逆向这个sign值把查看调用堆栈下断点,一步步跟栈发现......