From c93864c7e4b6b90682624df277359637db38f1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominic=20H=C3=B6glinger?= Date: Fri, 24 Apr 2026 06:21:59 +0200 Subject: [PATCH] Add Bang parser One minor bug found after claude review. Clanker: claude-sonnet_4.6 --- Parser/XnParser.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Parser/XnParser.cs b/Parser/XnParser.cs index 91f224c..cfb2030 100644 --- a/Parser/XnParser.cs +++ b/Parser/XnParser.cs @@ -188,11 +188,10 @@ namespace XNeedle.Parser public static CommentParser Comment = new CommentParser { Single = "#", NewLine = Environment.NewLine }; - public static readonly Parser BangObject = + public static readonly Parser BangObject = from c1 in Comment.SingleLineComment.Optional() from bang in Parse.Char('!') from name in Parse.AnyChar.Until(Parse.Char('(')) - from bopen in Parse.Char('(') from arguments in Argument.DelimitedBy(Parse.Char(',').Token()) from bclose in Parse.Char(')') let ctx = new Context{XPathSelector = "//*."} @@ -200,7 +199,10 @@ namespace XNeedle.Parser from open in Parse.Char('{') from ws2 in Parse.WhiteSpace.Many().Optional() from c2 in Comment.SingleLineComment.Optional() - from expressions in ExprPart(ctx).Or(Parse.Ref(() => RuleObject)).Or(Parse.Ref(() => BangObject)).DelimitedBy(Parse.Char(';').Token()) + from expressions in Parse.Ref(() => BangObject) + .Or(Parse.Ref(() => RuleObject)) + .Or(ExprPart(ctx).Select(e => (Part)e)) + .DelimitedBy(Parse.Char(';').Token()) from tailingsemi in Parse.Char(';').Optional() from ws3 in Parse.WhiteSpace.Many().Optional() from close in Parse.Char('}') @@ -214,10 +216,14 @@ namespace XNeedle.Parser from open in Parse.Char('{') from ws2 in Parse.WhiteSpace.Many().Optional() from c2 in Comment.SingleLineComment.Optional() - from expressions in ExprPart(ctx).Or(Parse.Ref(() => RuleObject)).Or(Parse.Ref(() => BangObject)).DelimitedBy(Parse.Char(';').Token()) + from expressions in Parse.Ref(() => BangObject) + .Or(Parse.Ref(() => RuleObject)) + .Or(ExprPart(ctx).Select(e => (Part)e)) + .DelimitedBy(Parse.Char(';').Token()) from tailingsemi in Parse.Char(';').Optional() from ws3 in Parse.WhiteSpace.Many().Optional() from close in Parse.Char('}') select new Rule{XPathSelector = selector, Body = expressions}; + } } \ No newline at end of file