From 43fdbf94ad87ea91a173c72688cad70a0a5f1ab4 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Fri, 30 Apr 2021 01:54:02 +0900 Subject: Add character property expression (Meet RL1.2 of UTS #18 partially) \p{property name=property value} matches a character has the property. When the property name is General_Category, it can be omitted. That is, \p{Letter} equals \p{General_Category=Letter}. Currently, only General_Category is supported. This feature meets RL1.2 of UTS #18 partially. RL1.2 Properties: https://unicode.org/reports/tr18/#RL1.2 --- compiler/parser_test.go | 73 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) (limited to 'compiler/parser_test.go') diff --git a/compiler/parser_test.go b/compiler/parser_test.go index c636d8b..5a138ab 100644 --- a/compiler/parser_test.go +++ b/compiler/parser_test.go @@ -29,6 +29,11 @@ func TestParser_parse(t *testing.T) { pattern string ast astNode syntaxError *SyntaxError + + // When an AST is large, as patterns containing a character property expression, + // this test only checks that the pattern is parsable. + // The check of the validity of such AST is performed by checking that it can be matched correctly using the driver. + skipTestAST bool }{ { pattern: "a", @@ -83,6 +88,10 @@ func TestParser_parse(t *testing.T) { newEndMarkerNodeWithPos(1, endPos(4)), ), }, + { + pattern: "\\p{Letter}?", + skipTestAST: true, + }, { pattern: "(a)?", ast: genConcatNode( @@ -185,6 +194,10 @@ func TestParser_parse(t *testing.T) { newEndMarkerNodeWithPos(1, endPos(4)), ), }, + { + pattern: "\\p{Letter}*", + skipTestAST: true, + }, { pattern: "((a*)*)*", ast: genConcatNode( @@ -289,6 +302,10 @@ func TestParser_parse(t *testing.T) { newEndMarkerNodeWithPos(1, endPos(7)), ), }, + { + pattern: "\\p{Letter}+", + skipTestAST: true, + }, { pattern: "((a+)+)+", ast: genConcatNode( @@ -837,6 +854,58 @@ func TestParser_parse(t *testing.T) { pattern: "\\u{}", syntaxError: synErrCPExpInvalidForm, }, + { + pattern: "\\p{Letter}", + skipTestAST: true, + }, + { + pattern: "\\p{General_Category=Letter}", + skipTestAST: true, + }, + { + pattern: "\\p{ Letter }", + skipTestAST: true, + }, + { + pattern: "\\p{ General_Category = Letter }", + skipTestAST: true, + }, + { + pattern: "\\p", + syntaxError: synErrCharPropExpInvalidForm, + }, + { + pattern: "\\p{", + syntaxError: synErrCharPropExpInvalidForm, + }, + { + pattern: "\\p{Letter", + syntaxError: synErrCharPropExpInvalidForm, + }, + { + pattern: "\\p{General_Category=}", + syntaxError: synErrCharPropExpInvalidForm, + }, + { + pattern: "\\p{General_Category= }", + syntaxError: synErrCharPropInvalidSymbol, + }, + { + pattern: "\\p{=Letter}", + syntaxError: synErrCharPropExpInvalidForm, + }, + { + pattern: "\\p{ =Letter}", + syntaxError: synErrCharPropInvalidSymbol, + }, + { + pattern: "\\p{=}", + syntaxError: synErrCharPropExpInvalidForm, + }, + { + pattern: "\\p{}", + syntaxError: synErrCharPropExpInvalidForm, + }, { pattern: "(a)", ast: newConcatNode( @@ -1031,7 +1100,9 @@ func TestParser_parse(t *testing.T) { t.Fatal("AST is nil") } // printAST(os.Stdout, ast, "", "", false) - testAST(t, tt.ast, ast) + if !tt.skipTestAST { + testAST(t, tt.ast, ast) + } } }) } -- cgit v1.2.3