浏览代码

Grammar: Added support for line breaks, using \\

gm/2021-09-23T00Z/github.com--lark-parser-lark/v0.12.0
Erez Sh 3 年前
父节点
当前提交
9230c67d28
共有 2 个文件被更改,包括 12 次插入1 次删除
  1. +2
    -1
      lark/load_grammar.py
  2. +10
    -0
      tests/test_grammar.py

+ 2
- 1
lark/load_grammar.py 查看文件

@@ -94,6 +94,7 @@ TERMINALS = {
'_NL_OR': r'(\r?\n)+\s*\|',
'WS': r'[ \t]+',
'COMMENT': r'\s*//[^\n]*',
'BACKSLASH': r'\\[ ]*\n',
'_TO': '->',
'_IGNORE': r'%ignore',
'_OVERRIDE': r'%override',
@@ -917,7 +918,7 @@ def _get_parser():
for r, _p, xs, o in rules for i, x in enumerate(xs)]
callback = ParseTreeBuilder(rules, ST).create_callback()
import re
lexer_conf = LexerConf(terminals, re, ['WS', 'COMMENT'])
lexer_conf = LexerConf(terminals, re, ['WS', 'COMMENT', 'BACKSLASH'])
parser_conf = ParserConf(rules, callback, ['start'])
lexer_conf.lexer_type = 'standard'
parser_conf.parser_type = 'lalr'


+ 10
- 0
tests/test_grammar.py 查看文件

@@ -270,6 +270,16 @@ class TestGrammar(TestCase):
imports = list_grammar_imports('%import common.WS', [])
assert len(imports) == 1 and imports[0].pkg_name == 'lark'

def test_line_breaks(self):
p = Lark(r"""start: "a" \
"b"
""")
p.parse('ab')






if __name__ == '__main__':
main()


正在加载...
取消
保存