Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
24d6007d
Commit
24d6007d
authored
Nov 27, 2018
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a real tokenizer (only little use yet)
Make reporting syntax errors easier.
parent
b2b04a61
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
7 deletions
+66
-7
vmodtool.py
lib/libvcc/vmodtool.py
+66
-7
No files found.
lib/libvcc/vmodtool.py
View file @
24d6007d
...
...
@@ -529,7 +529,8 @@ class ProtoType(object):
class
stanza
(
object
):
def
__init__
(
self
,
l0
,
doc
,
vcc
):
def
__init__
(
self
,
toks
,
l0
,
doc
,
vcc
):
self
.
toks
=
toks
self
.
line
=
l0
while
doc
and
doc
[
0
]
==
''
:
doc
.
pop
(
0
)
...
...
@@ -545,6 +546,12 @@ class stanza(object):
def
dump
(
self
):
print
(
type
(
self
),
self
.
line
)
def
syntax
(
self
):
err
(
"Syntax error.
\n
"
+
"
\t
Should be: "
+
self
.
__doc__
.
strip
()
+
"
\n
"
+
"
\t
Is: "
+
" "
.
join
(
self
.
toks
)
+
"
\n
"
,
warn
=
False
)
def
rstfile
(
self
,
fo
,
man
):
if
self
.
rstlbl
is
not
None
:
fo
.
write
(
".. _"
+
self
.
rstlbl
+
":
\n\n
"
)
...
...
@@ -642,17 +649,31 @@ class s_module(stanza):
class
s_abi
(
stanza
):
''' $ABI [strict|vrt] '''
def
parse
(
self
):
if
self
.
line
[
1
]
not
in
(
'strict'
,
'vrt'
):
if
len
(
self
.
toks
)
!=
2
:
self
.
syntax
()
valid
=
{
'strict'
:
True
,
'vrt'
:
False
,
}
self
.
vcc
.
strict_abi
=
valid
.
get
(
self
.
toks
[
1
])
if
self
.
vcc
.
strict_abi
is
None
:
err
(
"Valid ABI types are 'strict' or 'vrt', got '
%
s'
\n
"
%
self
.
line
[
1
])
self
.
vcc
.
strict_abi
=
self
.
line
[
1
]
==
'strict'
self
.
toks
[
1
])
self
.
vcc
.
contents
.
append
(
self
)
class
s_prefix
(
stanza
):
''' $Prefix symbol '''
def
parse
(
self
):
self
.
vcc
.
sympfx
=
self
.
line
[
1
]
+
"_"
if
len
(
self
.
toks
)
!=
2
:
self
.
syntax
()
self
.
vcc
.
sympfx
=
self
.
toks
[
1
]
+
"_"
self
.
vcc
.
contents
.
append
(
self
)
...
...
@@ -834,6 +855,43 @@ DISPATCH = {
"Synopsis"
:
s_synopsis
,
}
def
tokenize
(
str
,
seps
=
None
,
quotes
=
None
):
if
seps
is
None
:
seps
=
"[](){},="
if
quotes
is
None
:
quotes
=
'"'
+
"'"
quote
=
None
out
=
[]
i
=
0
inside
=
False
while
i
<
len
(
str
):
c
=
str
[
i
]
# print("T", [c], quote, inside, i)
i
+=
1
if
quote
is
not
None
and
c
==
quote
:
inside
=
False
quote
=
None
out
[
-
1
]
+=
c
elif
quote
is
not
None
:
out
[
-
1
]
+=
c
elif
c
.
isspace
():
inside
=
False
elif
seps
.
find
(
c
)
>=
0
:
inside
=
False
out
.
append
(
c
)
elif
quotes
.
find
(
c
)
>=
0
:
quote
=
c
out
.
append
(
c
)
elif
inside
:
out
[
-
1
]
+=
c
else
:
out
.
append
(
c
)
inside
=
True
#print("TOK", [str])
#for i in out:
# print("\t", [i])
return
out
class
vcc
(
object
):
def
__init__
(
self
,
inputvcc
,
rstdir
,
outputprefix
):
...
...
@@ -866,12 +924,13 @@ class vcc(object):
self
.
copyright
=
s
.
pop
(
0
)
.
strip
()
while
s
:
ss
=
re
.
split
(
'
\n
([^
\t
])'
,
s
.
pop
(
0
),
maxsplit
=
1
)
toks
=
tokenize
(
ss
[
0
])
c
=
ss
[
0
]
.
split
()
d
=
""
.
join
(
ss
[
1
:])
m
=
DISPATCH
.
get
(
c
[
0
])
m
=
DISPATCH
.
get
(
toks
[
0
])
if
m
is
None
:
err
(
"Unknown stanze $
%
s"
%
ss
[:
i
])
m
([
c
[
0
],
" "
.
join
(
c
[
1
:])],
d
.
split
(
'
\n
'
),
self
)
m
(
toks
,
[
c
[
0
],
" "
.
join
(
c
[
1
:])],
d
.
split
(
'
\n
'
),
self
)
inputline
=
None
def
rst_copyright
(
self
,
fo
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment