source: vanHelsing/trunk/webservice/cfgparser.py@ 927

Last change on this file since 927 was 798, checked in by hmueller, on Oct 14, 2009 at 4:03:57 PM

parser in class gepackt

  • Property svn:executable set to *
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-python
File size: 2.7 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3'''
4Created on 10.07.2009
5
6@author: hmueller
7
8Syntax description of bacula config files
9'''
10
11from simpleparse.common import numbers, strings, comments
12from simpleparse.parser import Parser
13
14import resource
15
16declaration = r"""
17#text_pattern := ’\/’
18#text_subst := delim_init / ’/’
19#text_args := delim_init / ’)’
20#text_exp := delim_init / delim_close / ’:’ / ’+’
21text := delim_init / index_open /index_close
22delim_init := '$'
23delim_open := '{'
24delim_close := '}'
25index_open := '['
26index_close := ']'
27index_mark := '#'
28name_chars := [a-zA-Z0-9]
29"""
30
31if __name__ == "__main__":
32 parser = Parser(declaration)
33
34#input ::= ( TEXT
35# | variable
36# | INDEX_OPEN input INDEX_CLOSE (loop_limits)?
37# )*
38#variable ::= DELIM_INIT (name|expression)
39#name ::= (NAME_CHARS)+
40#expression ::= DELIM_OPEN
41# (name|variable)+
42# (INDEX_OPEN num_exp INDEX_CLOSE)?
43# (’:’ command)*
44# DELIM_CLOSE
45#command ::= ’-’ (TEXT_EXP|variable)+
46# | ’+’ (TEXT_EXP|variable)+
47# | ’o’ NUMBER (’-’|’,’) (NUMBER)?
48# | ’#’
49# | ’*’ (TEXT_EXP|variable)+
50# | ’s’ ’/’ (TEXT_PATTERN)+
51# ’/’ (variable|TEXT_SUBST)*
52# ’/’ (’m’|’g’|’i’|’t’)*
53# | ’y’ ’/’ (variable|TEXT_SUBST)+
54# ’/’ (variable|TEXT_SUBST)*
55# ’/’
56# | ’p’ ’/’ NUMBER
57# ’/’ (variable|TEXT_SUBST)*
58# ’/’ (’r’|’l’|’c’)
59# | ’%’ (name|variable)+
60# (’(’ (TEXT_ARGS)? ’)’)?
61# | ’l’
62# | ’u’
63# num_exp ::= operand
64# | operand (’+’|’-’|’*’|’/’|’%’) num_exp
65# operand ::= (’+’|’-’)? NUMBER
66# | INDEX_MARK
67# | ’(’ num_exp ’)’
68# | variable
69# loop_limits ::= DELIM_OPEN
70# (num_exp)? ’,’ (num_exp)? (’,’ (num_exp)?)?
71# DELIM_CLOSE
72# NUMBER ::= (’0’|...|’9’)+
73# TEXT_PATTERN::= (^(’/’))+
74# TEXT_SUBST ::= (^(DELIM_INIT|’/’))+
75# TEXT_ARGS ::= (^(DELIM_INIT|’)’))+
76# TEXT_EXP ::= (^(DELIM_INIT|DELIM_CLOSE|’:’|’+’))+
77# TEXT ::= (^(DELIM_INIT|INDEX_OPEN|INDEX_CLOSE))+
78# DELIM_INIT ::= ’$’
79# DELIM_OPEN ::= ’{’
80# DELIM_CLOSE ::= ’}’
81# INDEX_OPEN ::= ’[’
82# INDEX_CLOSE ::= ’]’
83# INDEX_MARK ::= ’#’
84# NAME_CHARS ::= ’a’|...|’z’|’A’|...|’Z’|’0’|...|’9’
85
Note: See TracBrowser for help on using the repository browser.