Add bang parsing
This commit is contained in:
parent
1899db4156
commit
fa6d9e3ace
@ -8,6 +8,8 @@ using XNeedle.Parser.Elements;
|
||||
using Part = XNeedle.Parser.Elements.Part;
|
||||
using XNeedle.Transformation;
|
||||
using Rule = XNeedle.Transformation.Rule;
|
||||
using System.Data;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace XNeedle.Parser
|
||||
{
|
||||
@ -186,6 +188,24 @@ namespace XNeedle.Parser
|
||||
|
||||
public static CommentParser Comment = new CommentParser { Single = "#", NewLine = Environment.NewLine };
|
||||
|
||||
public static readonly Parser<Part> 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 = "//*."}
|
||||
from ws1 in Parse.WhiteSpace.Many().Optional()
|
||||
from open in Parse.Char('{')
|
||||
from ws2 in Parse.WhiteSpace.Many().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 tailingsemi in Parse.Char(';').Optional()
|
||||
from ws3 in Parse.WhiteSpace.Many().Optional()
|
||||
from close in Parse.Char('}')
|
||||
select new Bang{Name = new string([.. name]), Arguments = arguments, Body = expressions};
|
||||
|
||||
public static readonly Parser<Part> RuleObject =
|
||||
from c1 in Comment.SingleLineComment.Optional()
|
||||
from selector in Selector(XPath).Token()
|
||||
@ -194,7 +214,7 @@ 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<Part>(Parse.Ref(() => RuleObject)).DelimitedBy(Parse.Char(';').Token())
|
||||
from expressions in ExprPart(ctx).Or<Part>(Parse.Ref(() => RuleObject)).Or<Part>(Parse.Ref(() => BangObject)).DelimitedBy(Parse.Char(';').Token())
|
||||
from tailingsemi in Parse.Char(';').Optional()
|
||||
from ws3 in Parse.WhiteSpace.Many().Optional()
|
||||
from close in Parse.Char('}')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user