SFig 语言语法是否高效且清晰(并且比 Spring-Framework 的 XML DSL 更好)? [英] is SFig language syntax efficient and clear (and better than Spring-Framework's XML DSL)?

查看:24
本文介绍了SFig 语言语法是否高效且清晰(并且比 Spring-Framework 的 XML DSL 更好)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

附录

<块引用>

尚未接受此问题的答案没有任何反馈经验丰富的Spring框架开发人员.

我一直在研究用于 Spring-Framework applicationContext.xml 文件的替代 DSL(其中描述了 bean 初始化和依赖关系以加载到 Spring bean 工厂).

我的动机是,我完全不喜欢 Spring 为此目的使用 XML,也不喜欢迄今为止设计的任何替代方案.出于各种原因,我不会深入探讨,我想继续使用声明性语言,而不是某些命令式脚本语言,例如 Groovy.

因此,我使用了 ANTLR 解析器工具,并一直在设计一种新的 bean factory DSL,我将其命名为 SFig.这是一个链接,更多地讨论了这一点:

SFig™ - 替代元数据配置语言用于 Spring 框架

这里是源代码库站点:

http://code.google.com/p/sfig/

我很想知道到目前为止我在语言语法方面的表现如何.您认为 SFig 既高效又清晰易懂吗?(我现在特别关心多行文本字符串):

properties_include "classpath:application.properties";org.apache.commons.dbcp.BasicDataSource 数据源 {@scope = 单例;@destroy-method = 关闭;driverClassName = "${jdbc.driverClassName}";url = "${jdbc.url}";用户名 = "${jdbc.username}";密码 = "${jdbc.password}";defaultAutoCommit = true;}org.springframework.orm.ibatis.SqlMapClientFactoryBean sqlMapClient {@scope = 单例;@init-method = afterPropertiesSet;@factory-method = getObject;configLocation = "classpath:sqlmap-config.xml";数据源 = $数据源;}/* 该字符串将应用 Java unescape 编码 */STRING str = "\tA test\u0020string with \\ 转义字符编码\r\n";/* 这个字符串将保持原样 - 转义字符保留在原位 */字符串正则表达式 = @"(\$\{([a-zA-Z][a-zA-Z0-9._]*)\})";/* 多行文本块 - 相当于一个 java.lang.String 实例 */文本 my_multi_line_text =///这是一行文字.这又是一个.这是一个空行:现在又捡起来了.///;/* 转发使用'props' bean */java.util.HashMap 映射 {这个( $props );}/* 相当于一个 java.util.Propertis 实例 */属性道具{"James Ward" = "Adobe Flex 布道者";"Stu Stern" = "Gorilla Logic - Flex Monkey 测试自动化";Dilbert = "流行同名漫画中的角色";"应用标题显示" = "应用:${app.name}";"${app.desc}" = "JFig 处理文本格式的 Java 配置数据";}/* 相当于一个 java.util.ArrayList 实例 */列表列表{this( ["尘土飞扬", "发霉", "${app.version}", $str] );[234, 9798.76, -98, .05, "numbers", $props, ["red", "green", "blue"]];}

解决方案

我对您引用的 Spring XML 没有太多经验,因此您应该对以下反馈持保留意见.

作为第二个和第三个警告:

  • 提供一段代码将使风味了解该语言及其语义是什么.很难完全理解您已经做出的一些选择(并且有充分的理由),因此根据这些选择,此处的任何反馈都可能完全矛盾或不可能.
  • 语言设计既是一门艺术又是一门科学,因此在这个阶段,您可能获得的任何反馈都可能是非常主观的.

一个更大的元问题:作为一个 DSL,你是在尝试配置 Spring,还是作为一个更通用的框架类?

那里:警告清空者.现在我的主观和不完整的反馈 ;)

  • 我不确定我为什么要为 scopedestroy- 加上 @ 前缀方法,但不是driverClassName.此外,xml-case 和camelCase 的组合一开始并不完全明显.@ 前缀是类型修饰符,还是语言中的这些关键字?

  • 我不完全确定你对区块头格式的意图.您有类名,然后是该类的函数;是否打算指定您将用于特定功能的类?

例如

sqlMapClient: org.springframework.orm.ibatis.SqlMapClientFactoryBean {# 身体.}

甚至:

sqlMapClient {@class = org.springframework.orm.ibatis.SqlMapClientFactoryBean;# 如果缺少这个,是否有一个合理的(也许是内置的)默认值?}

  • 我喜欢变量替换;我认为这些值将来自系统属性?

  • 我喜欢能够指定字符串文字(无需转义),尤其是对于您展示的正则表达式.但是,使用多字符引用或引用修饰符似乎有点陌生.我猜你考虑过单引号(shell 和 Perl 对文字字符串使用单引号).

  • 另一方面,我认为 多行 TEXT 的三重正斜杠是正确的方法,但两个让人想起 C 风格的注释语言.为此,Python 使用了三重 ".一些 shell 习语具有我不会复制的多行文本约定.

  • 我非常喜欢属性和配置位置的外观,使用看起来像 URI 寻址概念.如果这是一个 URI,classpath://file.xml 可能更清楚.然而,我可能在这里的错误结束.

  • 我也非常喜欢你所拥有的列表和地图文字的概念,虽然我不确定在哪里:

    • this 进入其中(我猜是对 Java 构造函数的调用)
    • 为什么有些类型是大写的,有些则不是.我是否认为有一个默认的 MAP 类型,如果您愿意,可以使用更具体的类型?
    • Dilbert 是一个不带引号的字符串吗?

最后,我会向您指出另一个配置 DSL,但可能更多用于系统管理员:Puppet.

一切顺利.

ADDENDUM EDIT:

Have not accepted an answer to this as there has not been any feedback from experienced Spring Framework developers.

I've been working on a replacement DSL to use for Spring-Framework applicationContext.xml files (where bean initialization and dependency relationships are described for loading up into the Spring bean factory).

My motivation is that I just flat out don't like Spring's use of XML for this purpose nor do I really like any of the alternatives that have been devised so far. For various reasons that I won't go into, I want to stay with a declarative language and not some imperative scripting language such as Groovy.

So I grabbed the ANTLR parser tool and have been devising a new bean factory DSL that I've dubbed SFig. Here's a link that talks more about that:

SFig™ - alternative metadata config language for Spring-Framework

And here is the source code repository site:

http://code.google.com/p/sfig/

I'm interested to know how I'm doing on the language syntax so far. Do you think SFig is both efficient and clear to understand? (I'm particularly concerned right now with the mulit-line text string):

properties_include "classpath:application.properties";


org.apache.commons.dbcp.BasicDataSource dataSource {
    @scope = singleton;
    @destroy-method = close;
    driverClassName = "${jdbc.driverClassName}";
    url = "${jdbc.url}";
    username = "${jdbc.username}";
    password = "${jdbc.password}";
    defaultAutoCommit = true;
}


org.springframework.orm.ibatis.SqlMapClientFactoryBean sqlMapClient {
    @scope = singleton;
    @init-method = afterPropertiesSet;
    @factory-method = getObject;
    configLocation = "classpath:sqlmap-config.xml";
    dataSource = $dataSource;
}


/* this string will have Java unescape encoding applied */
STRING str = "\tA test\u0020string with \\ escaped character encodings\r\n";


/* this string will remain literal - with escape characters remaining in place */
STRING regexp = @"(\$\{([a-zA-Z][a-zA-Z0-9._]*)\})";


/* multi-line text block - equates to a java.lang.String instance */
TEXT my_multi_line_text = ///
Here is a line of text.
This is yet another. Here is a blank line:

Now picks up again.
///;


/* forward use of 'props' bean */
java.util.HashMap map {
    this( $props );
}


/* equates to a java.util.Propertis instance */
PROPERTIES props {
    "James Ward" = "Adobe Flex evangelist";
    "Stu Stern" = "Gorilla Logic - Flex Monkey test automation";
    Dilbert = "character in popular comic strip of same title";
    "App Title Display" = "Application: ${app.name}";
    "${app.desc}" = "JFig processes text-format Java configuration data";
}


/* equates to a java.util.ArrayList instance */
LIST list {
    this( ["dusty", "moldy", "${app.version}", $str] );
    [234, 9798.76, -98, .05, "numbers", $props, ["red", "green", "blue"]];
}

解决方案

I haven't much experience with the Spring XML you refer, so you should take the following feedback with a pinch of salt.

As a second and third caveat:

  • providing a snippet of code will give a flavour of what the language and its semantics are. It is difficult to completely understand some of the choices you have already made (and with good reason), so any feedback here may be completely contradictory or impossible in the light of those choices.
  • language design is as much an art as a science, and so at this stage, any feedback you may get is likely to be quite subjective.

A larger, meta-, question: as a DSL are you trying to do configuration of Spring, or as a more general class of frameworks?

There: caveat emptor. Now my subjective and incomplete feedback ;)

  • I'm not sure I understand the reason why you have the @ prefix for scope and destroy-method, but not driverClassName. Also the mix of both xml-case and camelCase isn't completely apparent to start with. Is the @ prefix a type modifier, or are these keywords in the language?

  • I'm not completely sure of your intentions about the block header format. You have class name, then a function of that class; is the intention to specify what class your are going to use for a particular function?

e.g.

sqlMapClient: org.springframework.orm.ibatis.SqlMapClientFactoryBean {
    # body.
}

or even:

sqlMapClient {
    @class = org.springframework.orm.ibatis.SqlMapClientFactoryBean;
    # is there a sensible (perhaps built-in) default if this is missing?
}

  • I like the variable substitution; I presume the values will come from System properties?

  • I like being able to specify string literals (without escaping), especially for the regular expressions you've shown. However, having multi-character quote or quote modifier seems a little alien. I guess you considered the single-quote (shell and Perl use single-quotes for literal strings).

  • On the other hand, I think the triple forward slash for multi-line TEXT is the right approach, but two reminiscent of comments in C-style languages. Python uses a triple " for this purpose. Some shell idioms have a multi-line text convention I would not copy.

  • I very much like the look of properties and config location, using what looks like a URI notion of addressing. If this is a URI, classpath://file.xml may be clearer. I may have the wrong end of the stick here, however.

  • I also very much like the notion of list and map literals you have, though I'm not sure where:

    • this comes into it (I guess a call to a Java constructor)
    • why some types are capitalized, and others are not. Do I take it that there is a default MAP type, which you can be more specific type if you wish to?
    • is Dilbert an unquoted string literal?

Finally, I'd point you to another configuration DSL, though perhaps more for sysadmin usage: Puppet.

Go well.

这篇关于SFig 语言语法是否高效且清晰(并且比 Spring-Framework 的 XML DSL 更好)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆