mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-22 10:16:30 +00:00
state-machine solve parsing of // in string
This commit is contained in:
parent
b43c62f726
commit
6bef67b1a4
@ -23,6 +23,31 @@ import unishox
|
||||
from os import listdir
|
||||
from os import path
|
||||
from datetime import datetime
|
||||
import re
|
||||
|
||||
def extract_c_string(s: str) -> str:
|
||||
state = 0
|
||||
escape = False
|
||||
out = ""
|
||||
for c in s:
|
||||
if state == 0: # before string
|
||||
if c == '"': # entering string
|
||||
out = '"'
|
||||
state = 1
|
||||
elif c == '/': # start of comment before entering string
|
||||
state = 99 # we're done
|
||||
elif state == 1: # in string
|
||||
if escape: # escaped char
|
||||
out += '\\' + c
|
||||
escape = False
|
||||
elif c == '\\': # escaped char
|
||||
escape = True
|
||||
elif c == '"': # end of string
|
||||
out += '"'
|
||||
state = 99 # we're done
|
||||
else:
|
||||
out += c
|
||||
return out
|
||||
|
||||
path_compressed = path.join('..','..','tasmota','html_compressed')
|
||||
path_uncompressed = path.join('..','..','tasmota','html_uncompressed')
|
||||
@ -56,10 +81,9 @@ for file in files:
|
||||
const_name = el[:-2] #extract the "const char" variable name
|
||||
line_list.pop(line_number)
|
||||
else: # remove line comments
|
||||
line_el = line.rsplit("//")
|
||||
# print('Splitted line list by //' % line_el)
|
||||
# print(line_el[0])
|
||||
text = text + line_el[0]
|
||||
line_el = extract_c_string(line)
|
||||
# print(line_el)
|
||||
text = text + line_el
|
||||
line_number = line_number +1
|
||||
|
||||
# print const_name
|
||||
|
Loading…
x
Reference in New Issue
Block a user