This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
TP-CMPL/ply/example2.py
2022-03-05 21:56:48 +01:00

51 lines
798 B
Python

import ply.lex as lex
tokens = (
'COMMENTBEGIN',
'COMMENTEND',
'CODE',
)
states = (
('inComment', 'inclusive'),
)
def t_inComment_COMMENTEND(t):
r'\*/'
t.lexer.begin('INITIAL')
return t
def t_inComment_CODE(t):
r'.'
t.value = ''
return t
def t_COMMENTBEGIN(t):
r'/\*'
t.lexer.begin('inComment')
return t
t_CODE = r'.'
def t_inComment_newline(t):
r'\n+'
def t_newline(t) :
r'\n+'
t.lexer.lineno += len(t.value)
if __name__ == "__main__" :
import sys
lexer = lex.lex()
lexer.input(sys.stdin.read())
ret = ""
lineno = 1
for token in lexer:
if token.lineno > lineno :
lineno += 1
ret += '\n'
if token.type == 'CODE' :
ret += token.value
print(ret)