• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python parse_interface.parse_ndp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: check_shortcut5_context

def check_shortcut5_context():
    s = """
    mcdp {
        provides f1,f2 [Nat]
        requires r1,r2 [Nat]
    }
    """
    ndp = parse_ndp(s)
    assert_equal(['r1','r2'], ndp.get_rnames())
    assert_equal(['f1','f2'], ndp.get_fnames())
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:10,代码来源:syntax_shortcuts.py


示例17: check_addmake1

def check_addmake1():
    parse_wrap_check(""" addmake(root: code mcdp_lang_tests.syntax_misc.f) mcdp {} """,
                     Syntax.ndpt_addmake)

    ndp = parse_ndp(""" addmake(root: code mcdp_lang_tests.syntax_misc.f) mcdp {} """)

    assert len(ndp.make) == 1
    assert ndp.make[0][0] == 'root'
    from mcdp_lang.eval_ndp_imp import ImportedFunction
    assert isinstance(ndp.make[0][1], ImportedFunction)
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:10,代码来源:syntax_misc.py


示例18: check_lang113

def check_lang113(): # TODO: rename
    s="""
     mcdp {
         provides x = Nat:1 * 10 g
     } 
     """   
    
    ndp = parse_ndp(s)
    dp = ndp.get_dp()
    print dp.repr_long()
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:10,代码来源:syntax_misc.py


示例19: check_lang94

def check_lang94(): # TODO: rename
    s = """
    mcdp {
        provides f [m]
        requires r [m] 
        
        provided f <= min(required r, 5m) 
    }
    """
    dp = parse_ndp(s).get_dp()
    print dp.repr_long() 
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:11,代码来源:syntax_misc.py


示例20: check_lang111

def check_lang111(): # TODO: rename
    """ constant ref for functions """
    s = """
    mcdp {
        c = Nat: 2
        provides f = c
    }
    """
    ndp = parse_ndp(s)
    dp = ndp.get_dp()
    print dp.repr_long()
开发者ID:AndreaCensi,项目名称:mcdp,代码行数:11,代码来源:syntax_misc.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python command.SimpleRevisionCommand类代码示例发布时间:2022-05-27
下一篇:
Python mcasym.num函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap