Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ply.lex中的t_ignore、pass和t.lexer.skip()之间有什么区别?_Python_Lex_Lexer_Ply - Fatal编程技术网

Python ply.lex中的t_ignore、pass和t.lexer.skip()之间有什么区别?

Python ply.lex中的t_ignore、pass和t.lexer.skip()之间有什么区别?,python,lex,lexer,ply,Python,Lex,Lexer,Ply,这三种方法都可用于跳过、忽略或传递字符。例如: def t_error(t): pass def t_error(t): t.lexer.skip() def t_default(t): # put at the extreme end and assuming there are no string definitions r'.' pass or skip() 因此,在这种情况下,三者似乎都有相同的作用。我承认有些方法比其他方法更优雅 pass、tu ignore和t.

这三种方法都可用于跳过、忽略或传递字符。例如:

def t_error(t):
  pass

def t_error(t):
  t.lexer.skip()

def t_default(t): # put at the extreme end and assuming there are no string definitions
  r'.'
  pass or skip()
因此,在这种情况下,三者似乎都有相同的作用。我承认有些方法比其他方法更优雅


pass
tu ignore
t.lexer.skip()
之间的真正区别是什么?

中介绍了所有这些函数

t.lexer.skip()
主要用于错误情况下,在不处理字符的情况下提前输入固定数量的字符

t_ignore
pass
可以以类似的方式使用
t_ignore
是一条特殊规则,用于忽略在识别过程中不起作用的字符。它主要用于忽略空白和类似类型的字符。例如,它可以用来忽略注释,但手册给出了警告,如果这样做会导致其他识别功能出现问题,则不要这样做。例如,注释可以被以下人员忽略:

t_ignore_COMMENT = r'\#.*'
pass
用于在识别词素后丢弃词素而不生成标记。手册中给出了类似的注释示例:

def t_COMMENT(t):
    r'\#.*'
    pass
    # No return value. Token discarded