Package PyFoam :: Package RunDictionary :: Module ParsedParameterFile :: Class FoamFileParser
[hide private]
[frames] | no frames]

Class FoamFileParser

source code

                object --+    
                         |    
Basics.PlyParser.PlyParser --+
                             |
                            FoamFileParser
Known Subclasses:
FoamStringParser

Class that parses a string that contains the contents of an OpenFOAM-file and builds a nested structure of directories and lists from it

Instance Methods [hide private]
  __init__(self, content, debug=False, noHeader=False, boundaryDict=False)
  __getitem__(self, key)
  __setitem__(self, key, value)
  getData(self)
Get the data structure
  getHeader(self)
Get the OpenFOAM-header
  printContext(self, c, ind)
Prints the context of the current index
  parserError(self, text, c, ind)
Prints the error message of the parser and exit
  t_NAME(self, t)
[a-zA-Z_][<>(),.\*|a-zA-Z_0-9+]*
  t_newline(self, t)
\n+
  t_ccode_comment(self, t)
(/\*(.|\n)*?\*/)|(//.*)
  t_error(self, t)
  p_global(self, p)
global : header dictbody
  p_noHeader(self, p)
noHeader : dictbody
  p_boundaryDict(self, p)
boundaryDict : header list | header prelist
  p_header(self, p)
header : FOAMFILE dictionary
  p_integer(self, p)
integer : ICONST
  p_float(self, p)
integer : FCONST
  p_dictionary(self, p)
dictionary : '{' dictbody '}' | '{' '}'
  p_dictbody(self, p)
dictbody : dictbody dictline | dictline | empty
  p_list(self, p)
list : '(' itemlist ')'
  p_prelist(self, p)
prelist : integer '(' itemlist ')'
  p_itemlist(self, p)
itemlist : itemlist item | item
  p_dictline(self, p)
dictline : NAME dictitem ';' | NAME list ';' | NAME prelist ';' | NAME fieldvalue ';' | NAME dictionary
  p_number(self, p)
number : integer | FCONST
  p_dimension(self, p)
dimension : '[' number number number number number number number ']'
  p_vector(self, p)
vector : '(' number number number ')'
  p_fieldvalue_uniform(self, p)
fieldvalue : UNIFORM number | UNIFORM vector
  p_fieldvalue_nonuniform(self, p)
fieldvalue : NONUNIFORM NAME list | NONUNIFORM NAME prelist
  p_dictitem(self, p)
dictitem : longitem | pitem
  p_longitem(self, p)
longitem : pitemlist pitem
  p_pitemlist(self, p)
pitemlist : pitemlist pitem | pitem
  p_pitem(self, p)
pitem : NAME | SCONST | number | dictionary | list | dimension | empty
  p_item(self, p)
item : pitem | list | dictionary
  p_empty(self, p)
empty :
  p_error(self, p)

Inherited from Basics.PlyParser.PlyParser: parse

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__


Class Variables [hide private]
  tokens = ('NAME', 'ICONST', 'FCONST', 'SCONST', 'FOAMFILE', '...
  reserved = {'FoamFile': 'FOAMFILE', 'nonuniform': 'NONUNIFORM',...
  t_ICONST = '(-|)\\d+([uU]|[lL]|[uU][lL]|[lL][uU])?'
  t_FCONST = '(-|)((\\d+)(\\.\\d+)(e(\\+|-)?(\\d+))? | (\\d+)e(\\...
  t_SCONST = '\\"([^\\\\\\n]|(\\\\.))*?\\"'
  literals = '(){};[]'
  t_ignore = ' \t'

Inherited from Basics.PlyParser.PlyParser: precedence


Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, content, debug=False, noHeader=False, boundaryDict=False)
(Constructor)

source code 
Parameters:
  • content - the string to be parsed
  • debug - output debug information during parsing
  • noHeader - switch that turns off the parsing of the header
Overrides: Basics.PlyParser.PlyParser.__init__

__getitem__(self, key)
(Indexing operator)

source code 
None

__setitem__(self, key, value)
(Index assignment operator)

source code 
None

getData(self)

source code 
Get the data structure

getHeader(self)

source code 
Get the OpenFOAM-header

printContext(self, c, ind)

source code 
Prints the context of the current index

parserError(self, text, c, ind)

source code 
Prints the error message of the parser and exit

t_NAME(self, t)

source code 
[a-zA-Z_][<>(),.\*|a-zA-Z_0-9+]*

t_newline(self, t)

source code 
\n+

t_ccode_comment(self, t)

source code 
(/\*(.|\n)*?\*/)|(//.*)

t_error(self, t)

source code 
None

p_global(self, p)

source code 
global : header dictbody

p_noHeader(self, p)

source code 
noHeader : dictbody

p_boundaryDict(self, p)

source code 
boundaryDict : header list | header prelist

p_header(self, p)

source code 
header : FOAMFILE dictionary

p_integer(self, p)

source code 
integer : ICONST

p_float(self, p)

source code 
integer : FCONST

p_dictionary(self, p)

source code 
dictionary : '{' dictbody '}' | '{' '}'

p_dictbody(self, p)

source code 
dictbody : dictbody dictline | dictline | empty

p_list(self, p)

source code 
list : '(' itemlist ')'

p_prelist(self, p)

source code 
prelist : integer '(' itemlist ')'

p_itemlist(self, p)

source code 
itemlist : itemlist item | item

p_dictline(self, p)

source code 
dictline : NAME dictitem ';' | NAME list ';' | NAME prelist ';' | NAME fieldvalue ';' | NAME dictionary

p_number(self, p)

source code 
number : integer | FCONST

p_dimension(self, p)

source code 
dimension : '[' number number number number number number number ']'

p_vector(self, p)

source code 
vector : '(' number number number ')'

p_fieldvalue_uniform(self, p)

source code 
fieldvalue : UNIFORM number | UNIFORM vector

p_fieldvalue_nonuniform(self, p)

source code 
fieldvalue : NONUNIFORM NAME list | NONUNIFORM NAME prelist

p_dictitem(self, p)

source code 
dictitem : longitem | pitem

p_longitem(self, p)

source code 
longitem : pitemlist pitem

p_pitemlist(self, p)

source code 
pitemlist : pitemlist pitem | pitem

p_pitem(self, p)

source code 
pitem : NAME | SCONST | number | dictionary | list | dimension | empty

p_item(self, p)

source code 
item : pitem | list | dictionary

p_empty(self, p)

source code 
empty :

p_error(self, p)

source code 
None

Class Variable Details [hide private]

tokens

None
Value:
('NAME', 'ICONST', 'FCONST', 'SCONST', 'FOAMFILE', 'UNIFORM', 'NONUNIF
ORM')                                                                  
      

reserved

None
Value:
{'FoamFile': 'FOAMFILE', 'nonuniform': 'NONUNIFORM', 'uniform': 'UNIFO
RM'}                                                                   
      

t_ICONST

None
Value:
'(-|)\\d+([uU]|[lL]|[uU][lL]|[lL][uU])?'                               
      

t_FCONST

None
Value:
'(-|)((\\d+)(\\.\\d+)(e(\\+|-)?(\\d+))? | (\\d+)e(\\+|-)?(\\d+))([lL]|
[fF])?'                                                                
      

t_SCONST

None
Value:
'''\\"([^\\\\\
]|(\\\\.))*?\\"'''                                                     
      

literals

None
Value:
'(){};[]'                                                              
      

t_ignore

None
Value:
' \t'