Add Bang parser

One minor bug found after claude review.

Clanker: claude-sonnet_4.6
This commit is contained in:
Dominic Höglinger 2026-04-24 06:21:59 +02:00
parent fa6d9e3ace
commit c93864c7e4

View File

@ -188,11 +188,10 @@ namespace XNeedle.Parser
public static CommentParser Comment = new CommentParser { Single = "#", NewLine = Environment.NewLine }; public static CommentParser Comment = new CommentParser { Single = "#", NewLine = Environment.NewLine };
public static readonly Parser<Part> BangObject = public static readonly Parser<Part> BangObject =
from c1 in Comment.SingleLineComment.Optional() from c1 in Comment.SingleLineComment.Optional()
from bang in Parse.Char('!') from bang in Parse.Char('!')
from name in Parse.AnyChar.Until(Parse.Char('(')) from name in Parse.AnyChar.Until(Parse.Char('('))
from bopen in Parse.Char('(')
from arguments in Argument.DelimitedBy(Parse.Char(',').Token()) from arguments in Argument.DelimitedBy(Parse.Char(',').Token())
from bclose in Parse.Char(')') from bclose in Parse.Char(')')
let ctx = new Context{XPathSelector = "//*."} let ctx = new Context{XPathSelector = "//*."}
@ -200,7 +199,10 @@ namespace XNeedle.Parser
from open in Parse.Char('{') from open in Parse.Char('{')
from ws2 in Parse.WhiteSpace.Many().Optional() from ws2 in Parse.WhiteSpace.Many().Optional()
from c2 in Comment.SingleLineComment.Optional() from c2 in Comment.SingleLineComment.Optional()
from expressions in ExprPart(ctx).Or<Part>(Parse.Ref(() => RuleObject)).Or<Part>(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 tailingsemi in Parse.Char(';').Optional()
from ws3 in Parse.WhiteSpace.Many().Optional() from ws3 in Parse.WhiteSpace.Many().Optional()
from close in Parse.Char('}') from close in Parse.Char('}')
@ -214,10 +216,14 @@ namespace XNeedle.Parser
from open in Parse.Char('{') from open in Parse.Char('{')
from ws2 in Parse.WhiteSpace.Many().Optional() from ws2 in Parse.WhiteSpace.Many().Optional()
from c2 in Comment.SingleLineComment.Optional() from c2 in Comment.SingleLineComment.Optional()
from expressions in ExprPart(ctx).Or<Part>(Parse.Ref(() => RuleObject)).Or<Part>(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 tailingsemi in Parse.Char(';').Optional()
from ws3 in Parse.WhiteSpace.Many().Optional() from ws3 in Parse.WhiteSpace.Many().Optional()
from close in Parse.Char('}') from close in Parse.Char('}')
select new Rule{XPathSelector = selector, Body = expressions}; select new Rule{XPathSelector = selector, Body = expressions};
} }
} }