File: TTCN3Parser

package info (click to toggle)
ttcn3parser 20050130-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 396 kB
  • ctags: 25
  • sloc: python: 1,126; makefile: 11
file content (85 lines) | stat: -rwxr-xr-x 2,544 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python

# Copyright 2005, W. Borgert <debacle@debian.org>
# GPL v2
# Complete BNF: http://people.debian.org/~debacle/ttcn-bnf.html

try:
    import psyco
    psyco.full()
except:
    pass

import getopt, sys, time
import pyparsing
import ttcn3parser

options = {}
version = "20050130"

def process_opts(argv):
    # options not implemented - only for compatibility w/ older versions
    global options
    options = {'help':                0,
               'no-flattening':       0,
               'pretty-print':        0,
               'print-symbol-tables': 0,
               'print-tree':          0,
               'read-stdin':          0,
               'version':             0}
    try:
        opts, args = getopt.getopt(argv[1:], "hfpTtsv",
                                   ["help",
                                    "no-flattening",
                                    "pretty-print",
                                    "print-symbol-tables",
                                    "print-tree'",
                                    "read-stdin",
                                    "version"])
    except getopt.GetoptError:
        usage(argv[0])
        sys.exit(1)
    for o, a in opts:
        if o in ("-h", "--help"):
            options['help'] = 1
        if o in ("-f", "--no-flattening"):
            options['no-flattening'] = 1
        if o in ("-p", "--pretty-print"):
            options['pretty-print'] = 1
        if o in ("-T", "--print-symbol-tables"):
            options['print-symbol-tables'] = 1
        if o in ("-t", "--print-tree"):
            options['print-tree'] = 1
        if o in ("-s", "--read-stdin"):
            options['read-stdin'] = 1
        if o in ("-v", "--version"):
            options['version'] = 1
    return args

def usage(name):
    print "Usage: " + name + " [options] files(s)\n"

if __name__ == "__main__":
    files = process_opts(sys.argv)
    if options['help']:
        usage(sys.argv[0])
        sys.exit(0)
    if options['version']:
        print version
        sys.exit(0)
    bnf = ttcn3parser.BNF()
    for f in files:
        start = 0
        try:
            start = time.time()
            tokens = bnf.parseFile(f)
        except pyparsing.ParseException, err:
            print "File:", f
            print err.line
            print " "*(err.column-1) + "^"
            print err
        end = time.time()
        if options['print-tree']:
            print tokens.asXML()
        print "Parsed file %s in %.2f seconds" % (f, end - start)