- Add SourceLocation struct (XNeedle namespace) with FilePath, Encoding, and LineNumber (-1 sentinel when unavailable) - Add SLoc property to Context; Clone() propagates it for free - Expose XmlRoundtripWriter.DetectEncoding as internal static - Add XmlRoundtripWriter.CreateToString(filePath, encoding) returning a (writer, StringBuilder) tuple for in-memory style-preserving rendering - Update XmlFragParser.ChecksumData to accept tagName only; use OpeningTagAnchor to skip the opening tag robustly, and AnyChar.Until() to non-greedily capture content through the closing tag - Thread SourceLocation from Program.cs through Rule.Transform/Operate, refreshing LineNumber per node via IXmlLineInfo - Implement ContextFunctions.crc: render node via CreateToString, extract digest slice via ChecksumData, encode with SLoc.Encoding, return CRC32 as double for arithmetic compatibility Clanker: claude-sonnet_4.6
25 lines
755 B
C#
25 lines
755 B
C#
using Sprache;
|
|
|
|
namespace XNeedle.Parser
|
|
{
|
|
public class XmlFragParser
|
|
{
|
|
public static Parser<string> OpeningTagAnchor(string tag)
|
|
{
|
|
return
|
|
from lbraket in Parse.Char('<')
|
|
from tagname in Parse.String(tag)
|
|
from any in Parse.CharExcept('>').Many()
|
|
from rbraket in Parse.Char('>')
|
|
select new string([.. any]);
|
|
}
|
|
public static Parser<string> ChecksumData(string tagName)
|
|
{
|
|
var closing = "</" + tagName + ">";
|
|
return
|
|
from preamble in OpeningTagAnchor(tagName)
|
|
from content in Parse.AnyChar.Until(Parse.String(closing))
|
|
select new string([.. content]) + closing;
|
|
}
|
|
}
|
|
} |