简体   繁体   English

在Lex中使用Regex中的Unicode Range作为规则

[英]Using Unicode Range in Regex as a rule to Lex

import re
import ply.lex as lex

#rest of the code

def t_WORD(t): #WORD is a token defined in the tokens tuple
    r'[\u0C80-\u0CFF]+'
    #rest of the actions

This snippet provides an error stating illegal character. 此摘要提供了一个错误,指出了非法字符。 All characters are in the unicode range specified in the regex rule. 所有字符都在正则表达式规则中指定的unicode范围内。

What can be the problem? 可能是什么问题? Thanks in advance. 提前致谢。

The lexer should work properly with both Unicode given as token and pattern matching rules. 该词法分析器应与作为标记和模式匹配规则给出的Unicode一起正常工作。 If you need to supply optional flags to the re.compile() function, use the reflags option to lex. 如果需要向re.compile()函数提供可选标志,请对lex使用reflags选项。

lex.lex(reflags=re.UNICODE)

As alternative, see How to validate kannada words and Python Lex-Yacc 或者,请参阅如何验证卡纳达语单词Python Lex-Yacc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM