You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


cmddb with recursive xml-inspired parser
05-23-2017, 10:26 AM
Post: #1
 (Print Post)
cmddb with recursive xml-inspired parser
Code Snippet: [Select]
#!/usr/bin/env python
# coding: utf-8
#### license: creative commons cc0 1.0 (public domain)
#### http://creativecommons.org/publicdomain/zero/1.0/
proginf = "cmddb 0.1, may 2017 mn"

db = """

[[output text with newline]]

[fig]print

print

category: output (shares line)

use: output main variable to the screen (aka stdout.) command name dates back to teletypes

[/]

[basic(1964)]
[/]

[qbasic]
[/]

[python]
[/]

[bash]
[/]

[awk]
[/]

[js]
[/]

[[/]]


[[output text without newline]]

[fig]prints

prints

category: output (shares line)

use: output main variable to the screen; like print but (s)tays on the same line.

[/]

[basic(1964)]
[/]

[qbasic]
[/]

[python]
[/]

[bash]
[/]

[awk]
[/]

[js]
[/]

[[/]]

"""

def left(p, x): return p[:x]

def right(p, x): return p[-x:]

def dbparse(p, l, cb):
    pflg = 0
    cflg = 0
    buf = ""
    if l == 0: print cb + p
    for t in p:  
        buf += t
        
        if pflg == 0:
            if right(buf, l) == "[" * l:
                buf = ""
                pflg = 1
        else:
            if right(buf, l * 2 + 1) == "[" * l + "/" + "]" * l:
                contents = left(buf, len(buf) - l * 2 - 1) ; buf = "" ; pflg = 0
                if len(contents.strip()) and l > 0: dbparse(contents, l - 1, cb + cbuf)
            elif right(buf, l) == "]" * l:
                cbuf = "\x1b[0;"+str(30+l)+"m" + left(buf, len(buf) -l) + "\x1b[0;37m\n" ; buf = ""
          


dblevel = 0
while 1:
    if "[" * (dblevel + 1) in db: dblevel += 1
    else: break

print dblevel


dbparse(db, dblevel, "")
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Bowditch curve
QB64 Member Project - RGB Color Wheel
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Pivot version two
QB64 Member Project - Amazon
QB64 Member Project - Kings Vallery version two
QB64 Member Project - Pivet version one
QB64 Member Project - ARB Checkers
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - Color Triangles
QB64 Member Project - OpenGL Triangles
QB64 Member Project - Full Color LED Sign
QB64 Member Project - Kings Court
QB64 Member Project - Score 4
QB64 Member Project - Splatter
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Sabotage
QB64 Member Project - Connect Four
QB64 Member Project - Touche
QB64 Member Project - Line Thickness
QB64 Member Project - Othello
QB64 Member Project - Algeria Weather
QB64 Member Project - Isolation
QB64 Member Project - Rotating Background
QB64 Member Project - Martin Fractals version one
QB64 Member Project - Dreamy Clock
QB64 Member Project - Qubic
QB64 Member Project - Dakapo
QB64 Member Project - Basic Dithering
QB64 Member Project - Color Rotating Text
QB64 Member Project - Exit
QB64 Member Project - Swirl
QB64 Member Project - Foursight
QB64 Member Project - Point Blank
QB64 Member Project - Inside Moves
QB64 Member Project - Quarto
QB64 Member Project - Rubix's Magic
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Overboard
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Martin Fractals version two
QB64 Member Project - 9 Board
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Domain
QB64 Member Project - Input
QB64 Member Project - Blokus
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Spiro Roses