{"id":22396135,"url":"https://github.com/hoehrmann/srng2json","last_synced_at":"2025-08-29T17:11:20.892Z","repository":{"id":140338959,"uuid":"1484781","full_name":"hoehrmann/srng2json","owner":"hoehrmann","description":"srng2json compiles RELAX NG schemas into a state machine encoded in JSON","archived":false,"fork":false,"pushed_at":"2011-03-15T21:49:52.000Z","size":96,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T23:13:56.994Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hoehrmann.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-03-15T21:45:16.000Z","updated_at":"2015-09-03T05:10:10.000Z","dependencies_parsed_at":"2023-03-13T10:43:41.171Z","dependency_job_id":null,"html_url":"https://github.com/hoehrmann/srng2json","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hoehrmann/srng2json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoehrmann%2Fsrng2json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoehrmann%2Fsrng2json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoehrmann%2Fsrng2json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoehrmann%2Fsrng2json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoehrmann","download_url":"https://codeload.github.com/hoehrmann/srng2json/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoehrmann%2Fsrng2json/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272730539,"owners_count":24983731,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-29T02:00:10.610Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T06:07:05.003Z","updated_at":"2025-08-29T17:11:20.847Z","avatar_url":"https://github.com/hoehrmann.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"I made an ad-hoc tool that turns a RELAX NG schema in simply syntax\r\ninto a parser table for efficient (and so far approximate) validation.\r\nThe source code for the tool as well as a demonstration using the XHTML\r\n1.0 Transitional schema generated through trang and rng2srng is at:\r\n\r\n  http://www.websitedev.de/temp/xhtml1-transitional-validator.html.gz\r\n\r\nThe tool largely ignores data types, fixed values, lists, and name\r\nclasses (though infrastructure for name classes is there). The tool\r\ngenerates a JSON table that allows running the validation process like\r\n\r\nIt is based on http://www.thaiopensource.com/relaxng/derivative.html\r\nwith one important difference in that there is no After pattern. In-\r\nstead it simulates, for a given qualified name, the union of all\r\nmatching \u003cdefine\u003es and notes where in the simulation process the\r\nelements underneath become nullable. Those accepting states are then\r\nused in the transition table of the parent, so validation becomes\r\nsomething like:\r\n\r\n  state = automaton[state][attribute1];\r\n  state = automaton[state][attribute2];\r\n  ...\r\n  childstate = recursive(child1);\r\n  state = automaton[state][childstate];\r\n\r\n  childstate = recursive(child2);\r\n  state = automaton[state][childstate];\r\n  ...\r\n\r\nObviously in order to keep the validation process this simple you'd\r\nhave to turn data types and so on into similar DFAs, but that would \r\nmake things quickly become weird and complicated and slow, especially\r\nin inefficient machine code like JavaScript, and there is very little\r\ntool support for that. Besides, grammars usually don't come with much\r\nbeyond a couple of fixed keyword and maybe some xsd:int somewhere.\r\n\r\nInfrastructure for name classes is there (I regard AnyName, NsName,\r\nand a new LnName construct as patterns and have patterns for comple-\r\nment and intersection, and simply decide membership by computing the\r\nderivatives with respect to namespace names and local names) but it's\r\nobviously not easy to lookup unknown names in a static table, so the\r\nsupport for name classes for elements does little, and support for\r\nname classes for attributes is absent.\r\n\r\nIt might be possible to simply have some \"##other\" names in the table\r\nto support unknown names, but I haven't thought through that yet for\r\nelements, and for attributes this might make things kinda messy.\r\n\r\nThe JavaScript demo as it is churns through a couple of megabyte per\r\nsecond on commodity hardware, that's probably somewhere around the\r\nedge of \"tolerable\" for something like a real-time browser addon.\r\n\r\nThere is also no error recovery of any kind, although that would be\r\neasy to add, if you go by James Clark's work you could similarily \r\npre-compute recovery states, and things like ignoring failures due\r\nto attributes could be done directly in the validator without changes\r\nin the parser tables. Giving better error messages by analyzing the\r\ngraph is also an option.\r\n\r\nThis builds up on earlier work I've done, for instance, once I turned\r\nDTDs into tables with regular expressions and let browser's regular ex-\r\npression engines do the matching, attribute values in the obvious way,\r\nand content models by turning lists of children into lists separated by\r\na separator:\r\n\r\n  http://lists.w3.org/Archives/Public/www-validator/2006Nov/0000.html\r\n\r\nAnyway, I mostly wanted to invest a couple of hours to support the point\r\nthat validation is really simple with the right tools, and this might be\r\na meaningful contribution to that end. The backend-tool is written in C#\r\nand available under the GPLv2+, and available from the page noted above,\r\nor from here.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoehrmann%2Fsrng2json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoehrmann%2Fsrng2json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoehrmann%2Fsrng2json/lists"}