小编Bra*_*uif的帖子

lark-parser 缩进 DSL 和多行文档字符串

我正在尝试使用lark实现记录定义 DSL 。它基于缩进,这使事情变得更加复杂。

Lark 是一个很棒的工具,但我面临一些困难。

这是我正在实施的 DSL 片段:

record Order :
    """Order record documentation
    should have arbitrary size"""

    field1 Int
    field2 Datetime:
        """Attributes should also have
        multiline documentation"""

    field3 String "inline documentation also works"
Run Code Online (Sandbox Code Playgroud)

这是使用的语法:

?start: (_NEWLINE | redorddef)*

simple_type: NAME

multiline_doc:  MULTILINE_STRING _NEWLINE
inline_doc: INLINE_STRING

?element_doc:  ":" _NEWLINE _INDENT multiline_doc _DEDENT | inline_doc

attribute_name: NAME
attribute_simple_type: attribute_name simple_type [element_doc] _NEWLINE
attributes: attribute_simple_type+
_recordbody: _NEWLINE _INDENT [multiline_doc] attributes _DEDENT
redorddef: "record" NAME ":" _recordbody



MULTILINE_STRING: /"""([^"\\]*(\\.[^"\\]*)*)"""/
INLINE_STRING: /"([^"\\]*(\\.[^"\\]*)*)"/ …
Run Code Online (Sandbox Code Playgroud)

python grammar parsing lark-parser

5
推荐指数
1
解决办法
997
查看次数

标签 统计

grammar ×1

lark-parser ×1

parsing ×1

python ×1