当前位置: 首页>>代码示例>>Python>>正文


Python parse_interface.parse_ndp函数代码示例

本文整理汇总了Python中mcdp_lang.parse_interface.parse_ndp函数的典型用法代码示例。如果您正苦于以下问题:Python parse_ndp函数的具体用法?Python parse_ndp怎么用?Python parse_ndp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse_ndp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_lang99

def check_lang99(): # TODO: rename
    s = """
    mcdp {
      requires r [Nat]
      f = Nat: 2 + required r
      provides f
    }
    """
    dp = parse_ndp(s).get_dp()
    print dp.repr_long() 

    s = """
    mcdp {
      requires r [Nat]
      f = Nat: 2 + r
      provides f
    }
    """
    dp = parse_ndp(s).get_dp()
    print dp.repr_long() 

    s = """
    mcdp {
      provides f [Nat]
      r = Nat: 2 + f
      requires r
    }
    """
    dp = parse_ndp(s).get_dp()
    print dp.repr_long()
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:30,代码来源:syntax_misc.py

示例2: check_comments16

def check_comments16():
    parse_wrap_check('1 g', Syntax.definitely_constant_value)
    parse_wrap_check("'Number of constants'", Syntax.comment_con)
    
    parse_wrap_check("axx = 1.2 g", Syntax.setname_rvalue)
    parse_wrap_check("axx", Syntax.constant_name)
    expr=Syntax.constant_name + Syntax.EQ + Syntax.definitely_constant_value
    parse_wrap_check("axx = 1.2 g", expr)
    def parse(t):
        return CDPLanguage.SetNameConstant(t[0], t[1], t[2])
    expr2 = sp(expr, parse)
    parse_wrap_check("axx = 1.2 g", expr2)
    parse_wrap_check("axx = 1.2 g", Syntax.setname_constant)
    parse_wrap_check("a = 1 g", Syntax.setname_constant)
    parse_wrap_check("a = 1 g  'Number of constants'", Syntax.setname_constant)
    parse_wrap_check("constant a = 1 g  'Number of constants'", Syntax.setname_constant)
    parse_wrap_check(
        "constant gravity = (9.8 m/s^2) / 6 dimensionless 'Gravity on Earth'",
        Syntax.setname_constant)
    s = """
     mcdp {
    ' One example of documentation for the entire MCDP.'

    requires     mass [kg]   'The mass that must be transported.'
    provides capacity [kWh]  'The capacity of the battery.'

    constant a = 1 g  'Number of constants'
  
    constant gravity = (9.8 m/s^2) / 6 dimensionless 'Gravity on Earth'

    variable x, y [Nat] 'constant '
  }"""
    parse_ndp(s)
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:33,代码来源:syntax_comments.py

示例3: check_comments03b

def check_comments03b():
    """ Double comments """

    s = """ mcdp { '''Doc''' } """
    parse_ndp(s)
    s = ''' mcdp { """Doc""" } '''
    parse_ndp(s)
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:7,代码来源:syntax_comments.py

示例4: check_approx_res4

def check_approx_res4(): # check_error line
    s = ("""
    
    
    mcdp {
        provides f [m]
        requires r [m]
        
        
        r >= f
        r >= f
        r >= f
        r >= f
        r >= f
        r >= f
        r >= f
        r >= f
        r >= f
        r >= f f
    
    """)
    try:
        parse_ndp(s)  # , Syntax.ndpt_dp_rvalue)
    except DPSyntaxError as e:
        s = str(e)
        assert  'line 18' in s
        return
    else:
        raise Exception()
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:29,代码来源:syntax_approximation.py

示例5: check_lang107

def check_lang107(): # TODO: rename
    """ sum of nat constants """
    s = """
    mcdp {
        requires x [Nat]
        required x >=  Nat:2 + Nat:1
    }
    """
    parse_ndp(s)
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:9,代码来源:syntax_misc.py

示例6: check_lang106

def check_lang106(): # TODO: rename
    """ Refininement when variables have the same name. """
    s = """
    mcdp {
        requires power [Nat]
        provides power [Nat]
        power >= power + Nat:1
    }
    """
    parse_ndp(s)
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:10,代码来源:syntax_misc.py

示例7: check_lang89b

def check_lang89b(): # TODO: rename
    s = """
    mcdp {
        provides f [Nat] 
        requires r [Nat] 
        
        r >= max(f, f, f) 
    }
    """

    parse_ndp(s).get_dp() 
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:11,代码来源:syntax_misc.py

示例8: check_lang118

def check_lang118(): # TODO: rename
    """ Warnings """
    s = """
    mcdp {
        provides f [Nat]
        
        f <= Nat: 2
    }
    """ 
    context = ModelBuildingContext()
    parse_ndp(s, context)
    w = context.warnings
    assert_equal(len(w), 1)
    assert_equal(w[0].which, MCDPWarnings.LANGUAGE_REFERENCE_OK_BUT_IMPRECISE)
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:14,代码来源:syntax_misc.py

示例9: check_lang_invplus

def check_lang_invplus():
    assert_parsable_to_connected_ndp("""
mcdp {
    provides a [s]
    
    requires x [s]
    requires y [s]
    
    x + y >= a
}""")

    s = """
    mcdp {
        provides a [s]
        
        requires x [s]
        requires y [s]
        requires z [s]
        
        x + y * z >= a
    }"""
    try:
        parse_ndp(s)
    except DPSemanticError as e:
        if 'Inconsistent units' in str(e):
            pass
        else:
            msg = 'Expected inconsistent unit error.'
            raise_desc(Exception, msg)
    else:
        msg = 'Expected exception'
        raise_desc(Exception, msg)

    s = """
    mcdp {
        provides a [s]
        
        requires x [s]
        requires y [hour]
        
        x + y >= a
    }"""
    try:
        parse_ndp(s)
    except DPNotImplementedError as e:
        pass
    else:
        msg = 'Expected DPNotImplementedError'
        raise_desc(Exception, msg)
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:49,代码来源:syntax_misc.py

示例10: check_lang89d

def check_lang89d(): # TODO: rename

    # All of these should be equivalent to Min1(Nat, 2)
    min3s = [ """
    mcdp {
        provides f [Nat] 
        requires r [Nat]         
        r >= min(f, Nat:2) 
    } ""","""
    mcdp {
        provides f [Nat] 
        requires r [Nat]         
        r >= min(f, Nat:2, Nat:3) 
    } ""","""
    mcdp {
        provides f [Nat] 
        requires r [Nat]         
        r >= min(Nat:2, f, Nat:3) 
    }"""]

    for s in min3s:
#         print '-' * 10
#         print s
        dp = parse_ndp(s).get_dp()
#         print dp.repr_long()
        check_isinstance(dp, MinF1DP)
        assert dp.value == 2
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:27,代码来源:syntax_misc.py

示例11: check_comments_show_up

def check_comments_show_up():
    s = """
    # comment1
    mcdp {
        requires x [Nat]
        # comment2
        requires x [Nat]
    }
    """
    try:
        parse_ndp(s)
    except DPSemanticError as e:
        st = str(e)
        if not 'comment2' in st:
            msg = 'Comments are not preserved'
            raise_wrapped(Exception, e, msg)
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:16,代码来源:todo.py

示例12: assert_parse_ndp_semantic_error

def assert_parse_ndp_semantic_error(string, contains=None):
    """
        Asserts that parsing this string as an NDP will raise
        a DPSemanticError. If contains is not None, it is 
        a substring that must be contained in the error.
        
        Returns the exception. 
    """
    try:
        res = parse_ndp(string)
    except DPSemanticError as e:
        if contains is not None:
            s = str(e)
            if not contains in s:
                msg = 'Expected a DPSemanticError with substring %r.' % contains
                raise_wrapped(TestFailed, e, msg, string=string)
            return e
        else:
            return e
    except BaseException as e:
        msg = 'Expected DPSemanticError, but obtained %s.' % type(e)
        raise_wrapped(TestFailed, e, msg, string=string)

    msg = 'Expected DPSemanticError, but no exception was thrown.'
    raise_desc(TestFailed, msg, string=string, result=res) 
    assert False
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:26,代码来源:utils.py

示例13: assert_parsable_to_connected_ndp

def assert_parsable_to_connected_ndp(s , desc=None):  # @UnusedVariable
    """ This asserts that s can be compiled to a *connected* ndp. """
    res = parse_ndp(s)
    if isinstance(res, SimpleWrap):
        return res
    ndp = res.abstract()
    #print(ndp.repr_long())
    return ndp
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:8,代码来源:utils.py

示例14: check_approx_res3

def check_approx_res3():
    s = """
        mcdp {
            requires y [m]
            
            provides x [m]
            
            y >= approx(x, 1 J)
        }
    """
    try:
        parse_ndp(s)
    except DPSemanticError as e:
        s = str(e)
        assert 'The step is specified in a unit' in s
    else:
        raise Exception()
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:17,代码来源:syntax_approximation.py

示例15: check_lang96

def check_lang96(): # TODO: rename
    s = """
    mcdp {
      requires rb [J]
      provides f2 [J]
      f2 <= rb + 2 J
    }
    """
    dp = parse_ndp(s).get_dp()
    print dp.repr_long() 
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:10,代码来源:syntax_misc.py


注:本文中的mcdp_lang.parse_interface.parse_ndp函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。