def-file docs
This commit is contained in:
1 parent
e6a0d59d44
commit
7f4026f504
1 file changed
+12
@@ -1,3 +1,9 @@
|
|||||||
|
"""A simple and incomplete parser for the Design Exchange Format (DEF).
|
||||||
|
|
||||||
|
This parser extracts information on components and nets from DEF files and make them available
|
||||||
|
as an intermediate representation (:class:`DefFile` object).
|
||||||
|
"""
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from lark import Lark, Transformer, Tree
|
from lark import Lark, Transformer, Tree
|
||||||
@@ -69,6 +75,7 @@ class DefPin:
|
|||||||
|
|
||||||
|
|
||||||
class DefFile:
|
class DefFile:
|
||||||
|
"""Intermediate representation of a DEF file."""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.rows = []
|
self.rows = []
|
||||||
self.tracks = []
|
self.tracks = []
|
||||||
@@ -278,8 +285,13 @@ GRAMMAR = r"""
|
|||||||
|
|
||||||
|
|
||||||
def parse(text):
|
def parse(text):
|
||||||
|
"""Parses the given ``text`` and returns a :class:`DefFile` object."""
|
||||||
return Lark(GRAMMAR, parser="lalr", transformer=DefTransformer()).parse(text)
|
return Lark(GRAMMAR, parser="lalr", transformer=DefTransformer()).parse(text)
|
||||||
|
|
||||||
|
|
||||||
def load(file):
|
def load(file):
|
||||||
|
"""Parses the contents of ``file`` and returns a :class:`DefFile` object.
|
||||||
|
|
||||||
|
Files with `.gz`-suffix are decompressed on-the-fly.
|
||||||
|
"""
|
||||||
return parse(readtext(file))
|
return parse(readtext(file))
|
||||||
Reference in new issue
Block a user