How to use the fparser.pattern_tools.Pattern function in fparser

To help you get started, we’ve selected a few fparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pearu / f2py / fparser / pattern_tools.py View on Github external
abs_intrinsic_type_name = abs(intrinsic_type_name)
double_complex_name = Pattern('','DOUBLE\s*COMPLEX', flags=re.I, value='DOUBLE COMPLEX')
double_precision_name = Pattern('','DOUBLE\s*PRECISION', flags=re.I, value='DOUBLE PRECISION')
abs_double_complex_name = abs(double_complex_name)
abs_double_precision_name = abs(double_precision_name)

access_spec = Pattern('',r'PUBLIC|PRIVATE',flags=re.I)
abs_access_spec = abs(access_spec)

implicit_none = Pattern('',r'IMPLICIT\s*NONE',flags=re.I, value='IMPLICIT NONE')
abs_implicit_none = abs(implicit_none)

attr_spec = Pattern('',r'ALLOCATABLE|ASYNCHRONOUS|EXTERNAL|INTENT|INTRINSIC|OPTIONAL|PARAMETER|POINTER|PROTECTED|SAVE|TARGET|VALUE|VOLATILE',flags=re.I)
abs_attr_spec = abs(attr_spec)

dimension = Pattern('',r'DIMENSION', flags=re.I)
abs_dimension = abs(dimension)

intent = Pattern('', r'INTENT', flags=re.I)
abs_intent = abs(intent)

intent_spec = Pattern('', r'INOUT|IN|OUT', flags=re.I)
abs_intent_spec = abs(intent_spec)

function = Pattern('', r'FUNCTION', flags=re.I)
subroutine = Pattern('', r'SUBROUTINE', flags=re.I)

select_case = Pattern('', r'SELECT\s*CASE', flags=re.I, value='SELECT CASE')
abs_select_case = abs(select_case)

def _test():
    assert name.match('a1_a')
github pearu / f2py / fparser / pattern_tools.py View on Github external
attr_spec = Pattern('',r'ALLOCATABLE|ASYNCHRONOUS|EXTERNAL|INTENT|INTRINSIC|OPTIONAL|PARAMETER|POINTER|PROTECTED|SAVE|TARGET|VALUE|VOLATILE',flags=re.I)
abs_attr_spec = abs(attr_spec)

dimension = Pattern('',r'DIMENSION', flags=re.I)
abs_dimension = abs(dimension)

intent = Pattern('', r'INTENT', flags=re.I)
abs_intent = abs(intent)

intent_spec = Pattern('', r'INOUT|IN|OUT', flags=re.I)
abs_intent_spec = abs(intent_spec)

function = Pattern('', r'FUNCTION', flags=re.I)
subroutine = Pattern('', r'SUBROUTINE', flags=re.I)

select_case = Pattern('', r'SELECT\s*CASE', flags=re.I, value='SELECT CASE')
abs_select_case = abs(select_case)

def _test():
    assert name.match('a1_a')
    assert abs(name).match('a1_a')
    assert not abs(name).match('a1_a[]')

    m = abs(kind_param)
    assert m.match('23')
    assert m.match('SHORT')

    m = abs(signed_digit_string)
    assert m.match('23')
    assert m.match('+ 23')
    assert m.match('- 23')
    assert m.match('-23')
github pearu / f2py / fparser / pattern_tools.py View on Github external
access_spec = Pattern('',r'PUBLIC|PRIVATE',flags=re.I)
abs_access_spec = abs(access_spec)

implicit_none = Pattern('',r'IMPLICIT\s*NONE',flags=re.I, value='IMPLICIT NONE')
abs_implicit_none = abs(implicit_none)

attr_spec = Pattern('',r'ALLOCATABLE|ASYNCHRONOUS|EXTERNAL|INTENT|INTRINSIC|OPTIONAL|PARAMETER|POINTER|PROTECTED|SAVE|TARGET|VALUE|VOLATILE',flags=re.I)
abs_attr_spec = abs(attr_spec)

dimension = Pattern('',r'DIMENSION', flags=re.I)
abs_dimension = abs(dimension)

intent = Pattern('', r'INTENT', flags=re.I)
abs_intent = abs(intent)

intent_spec = Pattern('', r'INOUT|IN|OUT', flags=re.I)
abs_intent_spec = abs(intent_spec)

function = Pattern('', r'FUNCTION', flags=re.I)
subroutine = Pattern('', r'SUBROUTINE', flags=re.I)

select_case = Pattern('', r'SELECT\s*CASE', flags=re.I, value='SELECT CASE')
abs_select_case = abs(select_case)

def _test():
    assert name.match('a1_a')
    assert abs(name).match('a1_a')
    assert not abs(name).match('a1_a[]')

    m = abs(kind_param)
    assert m.match('23')
    assert m.match('SHORT')
github pearu / f2py / fparser / pattern_tools.py View on Github external
def __call__(self, string):
        m = self.match(string)
        if m is None: return
        if self.value is not None: return self.value
        return m.group()

# Predefined patterns

letter = Pattern('','[A-Z]',flags=re.I)
if dollar_ok:
    name = Pattern('', r'[A-Z][\w$]*',flags=re.I)
else:
    name = Pattern('', r'[A-Z]\w*',flags=re.I)
digit = Pattern('',r'\d')
underscore = Pattern('', '_')
binary_digit = Pattern('',r'[01]')
octal_digit = Pattern('',r'[0-7]')
hex_digit = Pattern('',r'[\dA-F]',flags=re.I)

digit_string = Pattern('',r'\d+')
abs_digit_string = abs(digit_string)
abs_digit_string_named = abs(digit_string.named('value'))
binary_digit_string = Pattern('',r'[01]+')
octal_digit_string = Pattern('',r'[0-7]+')
hex_digit_string = Pattern('',r'[\dA-F]+',flags=re.I)

sign = Pattern('',r'[+-]')
exponent_letter = Pattern('',r'[ED]',flags=re.I)

alphanumeric_character = Pattern('',r'\w') # [A-Z0-9_]
special_character = Pattern('',r'[ =+-*/\()[\]{},.:;!"%&~<>?,\'`^|$#@]')
github pearu / f2py / fparser / pattern_tools.py View on Github external
exponent = signed_digit_string
significand = digit_string + '.' + ~digit_string | '.' + digit_string
real_literal_constant = significand + ~(exponent_letter + exponent) + ~ ('_' + kind_param) | \
                        digit_string + exponent_letter + exponent + ~ ('_' + kind_param)
real_literal_constant_named = (significand + ~(exponent_letter + exponent) |\
                               digit_string + exponent_letter + exponent).named('value') +  ~ ('_' + kind_param_named)
signed_real_literal_constant_named = (~sign + (significand + ~(exponent_letter + exponent) |\
                               digit_string + exponent_letter + exponent)).named('value') +  ~ ('_' + kind_param_named)
signed_real_literal_constant = ~sign + real_literal_constant

named_constant = name
real_part = signed_int_literal_constant | signed_real_literal_constant | named_constant
imag_part = real_part
complex_literal_constant = '(' + real_part + ',' + imag_part + ')'

a_n_rep_char = Pattern('',r'\w')
rep_char = Pattern('',r'.')
char_literal_constant = ~( kind_param + '_') + ("'" + ~~rep_char + "'" | '"' + ~~rep_char + '"' )
a_n_char_literal_constant_named1 = ~( kind_param_named + '_') + (~~~("'" + ~~a_n_rep_char + "'" )).named('value')
a_n_char_literal_constant_named2 = ~( kind_param_named + '_') + (~~~('"' + ~~a_n_rep_char + '"' )).named('value')

logical_literal_constant = (r'[.]\s*(TRUE|FALSE)\s*[.]' + ~ ('_' + kind_param)).flags(re.I)
logical_literal_constant_named = Pattern('',r'[.]\s*(TRUE|FALSE)\s*[.]',flags=re.I).named() + ~ ('_' + kind_param_named)
literal_constant = int_literal_constant | real_literal_constant | complex_literal_constant | logical_literal_constant | char_literal_constant | boz_literal_constant
constant = literal_constant | named_constant
int_constant = int_literal_constant | boz_literal_constant | named_constant
char_constant = char_literal_constant | named_constant

# assume that replace_string_map is applied:
part_ref = name + ~((r'[(]' + name + r'[)]'))
data_ref = part_ref + ~~~(r'[%]' + part_ref)
primary = constant | name | data_ref | (r'[(]' + name + r'[)]')
github pearu / f2py / fparser / pattern_tools.py View on Github external
logical_literal_constant = (r'[.]\s*(TRUE|FALSE)\s*[.]' + ~ ('_' + kind_param)).flags(re.I)
logical_literal_constant_named = Pattern('',r'[.]\s*(TRUE|FALSE)\s*[.]',flags=re.I).named() + ~ ('_' + kind_param_named)
literal_constant = int_literal_constant | real_literal_constant | complex_literal_constant | logical_literal_constant | char_literal_constant | boz_literal_constant
constant = literal_constant | named_constant
int_constant = int_literal_constant | boz_literal_constant | named_constant
char_constant = char_literal_constant | named_constant

# assume that replace_string_map is applied:
part_ref = name + ~((r'[(]' + name + r'[)]'))
data_ref = part_ref + ~~~(r'[%]' + part_ref)
primary = constant | name | data_ref | (r'[(]' + name + r'[)]')

power_op = Pattern('',r'(?',r'(?',r'[+-]')
concat_op = Pattern('',r'(?','[.]\s*EQ\s*[.]|[.]\s*NE\s*[.]|[.]\s*LT\s*[.]|[.]\s*LE\s*[.]|[.]\s*GT\s*[.]|[.]\s*GE\s*[.]|[=]{2}|/[=]|[<][=]|[<]|[>][=]|[>]',flags=re.I)
not_op = Pattern('','[.]\s*NOT\s*[.]',flags=re.I)
and_op = Pattern('','[.]\s*AND\s*[.]',flags=re.I)
or_op = Pattern('','[.]\s*OR\s*[.]',flags=re.I)
equiv_op = Pattern('','[.]\s*EQV\s*[.]|[.]\s*NEQV\s*[.]',flags=re.I)
percent_op = Pattern('',r'%',flags=re.I)
intrinsic_operator = power_op | mult_op | add_op | concat_op | rel_op | not_op | and_op | or_op | equiv_op
extended_intrinsic_operator = intrinsic_operator

defined_unary_op = Pattern('','[.]\s*[A-Z]+\s*[.]',flags=re.I)
defined_binary_op = Pattern('','[.]\s*[A-Z]+\s*[.]',flags=re.I)
defined_operator = defined_unary_op | defined_binary_op | extended_intrinsic_operator
abs_defined_operator = abs(defined_operator)
defined_op = Pattern('','[.]\s*[A-Z]+\s*[.]',flags=re.I)
abs_defined_op = abs(defined_op)
github pearu / f2py / fparser / pattern_tools.py View on Github external
abs_hex_constant = abs(hex_constant)

intrinsic_type_name = Pattern('',r'(INTEGER|REAL|COMPLEX|LOGICAL|CHARACTER|DOUBLE\s*COMPLEX|DOUBLE\s*PRECISION|BYTE)',flags=re.I)
abs_intrinsic_type_name = abs(intrinsic_type_name)
double_complex_name = Pattern('','DOUBLE\s*COMPLEX', flags=re.I, value='DOUBLE COMPLEX')
double_precision_name = Pattern('','DOUBLE\s*PRECISION', flags=re.I, value='DOUBLE PRECISION')
abs_double_complex_name = abs(double_complex_name)
abs_double_precision_name = abs(double_precision_name)

access_spec = Pattern('',r'PUBLIC|PRIVATE',flags=re.I)
abs_access_spec = abs(access_spec)

implicit_none = Pattern('',r'IMPLICIT\s*NONE',flags=re.I, value='IMPLICIT NONE')
abs_implicit_none = abs(implicit_none)

attr_spec = Pattern('',r'ALLOCATABLE|ASYNCHRONOUS|EXTERNAL|INTENT|INTRINSIC|OPTIONAL|PARAMETER|POINTER|PROTECTED|SAVE|TARGET|VALUE|VOLATILE',flags=re.I)
abs_attr_spec = abs(attr_spec)

dimension = Pattern('',r'DIMENSION', flags=re.I)
abs_dimension = abs(dimension)

intent = Pattern('', r'INTENT', flags=re.I)
abs_intent = abs(intent)

intent_spec = Pattern('', r'INOUT|IN|OUT', flags=re.I)
abs_intent_spec = abs(intent_spec)

function = Pattern('', r'FUNCTION', flags=re.I)
subroutine = Pattern('', r'SUBROUTINE', flags=re.I)

select_case = Pattern('', r'SELECT\s*CASE', flags=re.I, value='SELECT CASE')
abs_select_case = abs(select_case)
github pearu / f2py / fparser / pattern_tools.py View on Github external
def flags(self, *flags):
        f = self._flags
        for f1 in flags:
            f = f | f1
        return Pattern(self.label, self.pattern, optional=self.optional, flags=f, value=self.value)
github pearu / f2py / fparser / pattern_tools.py View on Github external
def rename(self, label):
        if label[0]+label[-1]!='<>':
            label = '<%s>' % (label)
        return Pattern(label, self.pattern, optional=self.optional, flags=self._flags, value=self.value)

    def __call__(self, string):
        m = self.match(string)
        if m is None: return
        if self.value is not None: return self.value
        return m.group()

# Predefined patterns

letter = Pattern('','[A-Z]',flags=re.I)
if dollar_ok:
    name = Pattern('', r'[A-Z][\w$]*',flags=re.I)
else:
    name = Pattern('', r'[A-Z]\w*',flags=re.I)
digit = Pattern('',r'\d')
underscore = Pattern('', '_')
binary_digit = Pattern('',r'[01]')
octal_digit = Pattern('',r'[0-7]')
hex_digit = Pattern('',r'[\dA-F]',flags=re.I)

digit_string = Pattern('',r'\d+')
abs_digit_string = abs(digit_string)
abs_digit_string_named = abs(digit_string.named('value'))
binary_digit_string = Pattern('',r'[01]+')
octal_digit_string = Pattern('',r'[0-7]+')
hex_digit_string = Pattern('',r'[\dA-F]+',flags=re.I)

sign = Pattern('',r'[+-]')
github pearu / f2py / fparser / pattern_tools.py View on Github external
letter = Pattern('','[A-Z]',flags=re.I)
if dollar_ok:
    name = Pattern('', r'[A-Z][\w$]*',flags=re.I)
else:
    name = Pattern('', r'[A-Z]\w*',flags=re.I)
digit = Pattern('',r'\d')
underscore = Pattern('', '_')
binary_digit = Pattern('',r'[01]')
octal_digit = Pattern('',r'[0-7]')
hex_digit = Pattern('',r'[\dA-F]',flags=re.I)

digit_string = Pattern('',r'\d+')
abs_digit_string = abs(digit_string)
abs_digit_string_named = abs(digit_string.named('value'))
binary_digit_string = Pattern('',r'[01]+')
octal_digit_string = Pattern('',r'[0-7]+')
hex_digit_string = Pattern('',r'[\dA-F]+',flags=re.I)

sign = Pattern('',r'[+-]')
exponent_letter = Pattern('',r'[ED]',flags=re.I)

alphanumeric_character = Pattern('',r'\w') # [A-Z0-9_]
special_character = Pattern('',r'[ =+-*/\()[\]{},.:;!"%&~<>?,\'`^|$#@]')
character = alphanumeric_character | special_character

kind_param = digit_string | name
kind_param_named = kind_param.named('kind-param')
signed_digit_string = ~sign + digit_string
int_literal_constant = digit_string + ~('_' + kind_param)
signed_int_literal_constant = ~sign + int_literal_constant
int_literal_constant_named = digit_string.named('value') + ~ ('_' + kind_param_named)