GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python-mvdxml/mvdxml_expression.py at master · opensourceBIM/python-mvdxml

Expand file tree

/

mvdxml_expression.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
46 lines (36 loc) · 1.43 KB
/

mvdxml_expression.py

Copy path

File metadata and controls

46 lines (36 loc) · 1.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from __future__ import annotations
from dataclasses import dataclass
import pyparsing as pp
@dataclass(frozen=True)
class node:
a: str | None
b: str | None
c: str
@classmethod
def from_tokens(cls, args: pp.ParseResults) -> node:
if len(args) == 3 and args[1] == "=":
return cls(args[0], None, args[2])
if (args[1], args[3], args[4]) == ("[", "]", "="):
return cls(args[0], args[2], args[5])
return cls(None, args[1], args[4])
def __repr__(self):
return "{%s[%s]=%s}" % (self.a, self.b, self.c)
word = pp.Word(pp.alphanums + "_" + " " + "/" + "#")
quoted = pp.Combine("'" + pp.Optional(word) + "'")
bool_value = pp.CaselessLiteral("TRUE") | pp.CaselessLiteral("FALSE")
ref_val = word + "[" + word + "]"
rhs = quoted | bool_value | ref_val | word
stmt = (pp.Optional(word) + pp.Optional("[" + word + "]") + "=" + rhs).setParseAction(
node.from_tokens
)
bool_op = pp.CaselessLiteral("AND") | pp.CaselessLiteral("OR")
grammar = stmt + pp.Optional(pp.OneOrMore(bool_op + stmt))
def parse(exprs: str) -> tuple[tuple[node | str, ...], ...]:
parsed: list[tuple[node | str, ...]] = []
for expression in exprs.split(";"):
expression = "".join(
character for character in expression if character not in "\r\n"
)
if expression:
parsed.append(tuple(grammar.parseString(expression, parseAll=True)))
return tuple(parsed)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.