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

Class FoamFileParser

source code

                object --+    
                         |    
Basics.PlyParser.PlyParser --+
                             |
                            FoamFileParser

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, fName=None, debug=False, noHeader=False, noBody=False, doMacroExpansion=False, boundaryDict=False, preserveComments=True, preserveNewlines=True, listDict=False, listDictWithHeader=False, listLengthUnparsed=None)
Constructs the parser and the lexer
source code
 
__contains__(self, key) source code
 
__getitem__(self, key) source code
 
__setitem__(self, key, value) source code
 
__delitem__(self, key) source code
 
__iter__(self) source code
 
resetDecoration(self) source code
 
addToDecoration(self, text) source code
 
addCommentToDecorations(self, text) source code
 
addNewlinesToDecorations(self, text) source code
 
getDecoration(self) source code
 
directory(self) source code
 
getData(self)
Get the data structure
source code
 
getHeader(self)
Get the OpenFOAM-header
source code
 
printContext(self, c, ind)
Prints the context of the current index
source code
 
parserError(self, text, c, ind)
Prints the error message of the parser and exit
source code
 
condenseAllPreFixLists(self, orig)
Checks whether this list is a list that consists only of prefix-Lists
source code
 
t_unparsed_left(self, t)
\(
source code
 
t_unparsed_right(self, t)
\)
source code
 
t_unparsed_error(self, t) source code
 
t_NAME(self, t)
[a-zA-Z_][+\-<>(),.\*|a-zA-Z_0-9&%:]*
source code
 
t_SUBSTITUITION(self, t)
\$[a-zA-Z_][+\-<>(),.\*|a-zA-Z_0-9&%:]*
source code
 
t_newline(self, t)
\n+
source code
 
t_ccode_comment(self, t)
(/\*(.|\n)*?\*/)|(//.*)
source code
 
t_error(self, t) source code
 
p_global(self, p)
global : header dictbody
source code
 
p_gotHeader(self, p)
gotHeader :
source code
 
p_noBody(self, p)
noBody : FOAMFILE '{' dictbody gotHeader '}'
source code
 
p_noHeader(self, p)
noHeader : dictbody
source code
 
p_pureList(self, p)
pureList : list
source code
 
p_pureListWithHeader(self, p)
pureListWithHeader : header list | header prelist
source code
 
p_boundaryDict(self, p)
boundaryDict : header list | header prelist
source code
 
p_header(self, p)
header : FOAMFILE dictionary
source code
 
p_macro(self, p)
macro : KANALGITTER include | KANALGITTER inputMode | KANALGITTER remove
source code
 
p_include(self, p)
include : INCLUDE SCONST | INCLUDEIFPRESENT SCONST
source code
 
p_inputMode(self, p)
inputMode : INPUTMODE ERROR | INPUTMODE WARN | INPUTMODE PROTECT | INPUTMODE DEFAULT | INPUTMODE MERGE | INPUTMODE OVERWRITE
source code
 
p_remove(self, p)
remove : REMOVE word | REMOVE wlist
source code
 
p_integer(self, p)
integer : ICONST
source code
 
p_float(self, p)
integer : FCONST
source code
 
p_enter_dict(self, p)
enter_dict :
source code
 
p_exit_dict(self, p)
exit_dict :
source code
 
p_dictionary(self, p)
dictionary : '{' enter_dict dictbody '}' exit_dict | '{' '}'
source code
 
p_dictbody(self, p)
dictbody : dictbody dictline | dictline | empty
source code
 
p_list(self, p)
list : '(' itemlist ')'
source code
 
p_wlist(self, p)
wlist : '(' wordlist ')'
source code
 
p_unparsed(self, p)
unparsed : UNPARSEDCHUNK
source code
 
p_prelist_seen(self, p)
prelist_seen :
source code
 
p_prelist(self, p)
prelist : integer prelist_seen '(' itemlist ')' | integer prelist_seen '(' unparsed ')'
source code
 
p_itemlist(self, p)
itemlist : itemlist item | item
source code
 
p_wordlist(self, p)
wordlist : wordlist word | word
source code
 
p_word(self, p)
word : NAME | UNIFORM | NONUNIFORM | MERGE | OVERWRITE | DEFAULT | WARN | PROTECT | ERROR
source code
 
p_substitution(self, p)
substitution : SUBSTITUTION
source code
 
p_dictkey(self, p)
dictkey : word | SCONST
source code
 
p_dictline(self, p)
dictline : dictkey dictitem ';' | dictkey list ';' | dictkey prelist ';' | dictkey fieldvalue ';' | macro | dictkey dictionary
source code
 
p_number(self, p)
number : integer | FCONST
source code
 
p_dimension(self, p)
dimension : '[' number number number number number number number ']' | '[' number number number number number ']'
source code
 
p_vector(self, p)
vector : '(' number number number ')'
source code
 
p_tensor(self, p)
tensor : '(' number number number number number number number number number ')'
source code
 
p_symmtensor(self, p)
symmtensor : '(' number number number number number number ')'
source code
 
p_fieldvalue_uniform(self, p)
fieldvalue : UNIFORM number | UNIFORM vector | UNIFORM tensor | UNIFORM symmtensor
source code
 
p_fieldvalue_nonuniform(self, p)
fieldvalue : NONUNIFORM NAME list | NONUNIFORM NAME prelist
source code
 
p_dictitem(self, p)
dictitem : longitem | pitem
source code
 
p_longitem(self, p)
longitem : pitemlist pitem
source code
 
p_pitemlist(self, p)
pitemlist : pitemlist pitem | pitem
source code
 
p_pitem(self, p)
pitem : word | SCONST | number | dictionary | list | dimension | substitution | empty
source code
 
p_item(self, p)
item : pitem | REACTION | list | dictionary
source code
 
p_empty(self, p)
empty :
source code
 
p_error(self, p) source code

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', 'UN...
  reserved = {'FoamFile': 'FOAMFILE', 'uniform': 'UNIFORM', 'non...
  states = 'unparsed', 'exclusive',
  t_unparsed_ignore = ' \t\n0123456789.-+e'
  t_KANALGITTER = r'\#'
  t_ICONST = r'(-|)\d+([uU]|[lL]|[uU][lL]|[lL][uU])?'
  t_FCONST = r'(-|)((\d+)(\.\d*)(e(\+|-)?(\d+))? | (\d+)e(\+|-)?...
  t_SCONST = r'\"([^\\\n]|(\\.))*?\"'
  literals = "(){};[]"
  t_ignore = " \t\r"

Inherited from Basics.PlyParser.PlyParser: precedence

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, content, fName=None, debug=False, noHeader=False, noBody=False, doMacroExpansion=False, boundaryDict=False, preserveComments=True, preserveNewlines=True, listDict=False, listDictWithHeader=False, listLengthUnparsed=None)
(Constructor)

source code 

Constructs the parser and the lexer

Parameters:
  • content - the string to be parsed
  • fName - Name of the actual file (if any)
  • debug - output debug information during parsing
  • noHeader - switch that turns off the parsing of the header
Overrides: object.__init__

Class Variable Details [hide private]

tokens

Value:
'NAME', 'ICONST', 'FCONST', 'SCONST', 'FOAMFILE', 'UNIFORM', 'NONUNIFO\
RM', 'UNPARSEDCHUNK', 'REACTION', 'SUBSTITUTION', 'MERGE', 'OVERWRITE'\
, 'ERROR', 'WARN', 'PROTECT', 'DEFAULT', 'INCLUDE', 'INCLUDEIFPRESENT'\
, 'REMOVE', 'INPUTMODE', 'KANALGITTER',

reserved

Value:
{'FoamFile': 'FOAMFILE', 'uniform': 'UNIFORM', 'nonuniform': 'NONUNIFO\
RM', 'include': 'INCLUDE', 'includeIfPresent': 'INCLUDEIFPRESENT', 're\
move': 'REMOVE', 'inputMode': 'INPUTMODE', 'merge': 'MERGE', 'overwrit\
e': 'OVERWRITE', 'error': 'ERROR', 'warn': 'WARN', 'protect': 'PROTECT\
', 'default': 'DEFAULT',}

t_FCONST

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