hydra-kernel-0.18.1: hydra-kernel-json/hydra/core/print/pcre/regex.json
{
"name": "hydra.core.print.pcre.regex",
"metadata": {
"description": "Per-dialect printer rendering the hydra.core.regex AST into the PCRE / java.util.regex / ECMA family syntax (Java, Scala, Clojure, Python, Common Lisp, TypeScript). Differs from the canonical hydra.core.print.regex in exactly one place: Hydra's . (any character INCLUDING newline) renders as [\\s\\S] rather than a bare . (whose native meaning excludes newline in these engines). All other productions match the canonical form. See docs/specification/regex.md and issue #567.",
"comments": [],
"seeAlso": [],
"provisions": []},
"dependencies": [
{"module": "hydra.core.lib.equality"},
{"module": "hydra.core.lib.lists"},
{"module": "hydra.core.lib.literals"},
{"module": "hydra.core.lib.logic"},
{"module": "hydra.core.lib.strings"},
{"module": "hydra.core.regex"}],
"definitions": [
{
"term": {
"name": "hydra.core.print.pcre.regex.alternation",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"list": {"list": {"variable": "hydra.core.regex.Quantified"}}}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "alt",
"domain": {"list": {"list": {"variable": "hydra.core.regex.Quantified"}}},
"body": {
"let": {
"bindings": [
{
"name": "rendered",
"term": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {
"typeApplication": {"body": {"variable": "hydra.core.lib.lists.map"}, "type": {"list": {"variable": "hydra.core.regex.Quantified"}}}},
"type": {"literal": "string"}}},
"argument": {"variable": "hydra.core.print.pcre.regex.regexSequence"}}},
"argument": {"variable": "alt"}}},
"typeScheme": {"variables": [], "body": {"list": {"literal": "string"}}, "constraints": []}},
{
"name": "byLength",
"term": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.lib.lists.sortBy"}, "type": {"literal": "string"}}},
"type": {"literal": {"integer": "int32"}}}},
"argument": {"variable": "hydra.core.lib.strings.length"}}},
"argument": {"variable": "rendered"}}},
"typeScheme": {"variables": [], "body": {"list": {"literal": "string"}}, "constraints": []}}],
"body": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.strings.join"}, "argument": {"literal": {"string": "|"}}}},
"argument": {
"application": {
"function": {"typeApplication": {"body": {"variable": "hydra.core.lib.lists.reverse"}, "type": {"literal": "string"}}},
"argument": {"variable": "byLength"}}}}}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {
"literal": {
"string": "Render an alternation, joining its branches with the | operator. Branches are ordered by descending rendered length so that PCRE/ECMA's leftmost-first matching agrees with Hydra's leftmost-longest semantics for fixed-length alternatives."}}}]}}}}},
{
"term": {
"name": "hydra.core.print.pcre.regex.atom",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"variable": "hydra.core.regex.Atom"}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "a",
"domain": {"variable": "hydra.core.regex.Atom"},
"body": {
"application": {
"function": {
"cases": {
"typeName": "hydra.core.regex.Atom",
"cases": [
{
"name": "literal",
"handler": {
"lambda": {
"parameter": "c",
"domain": {"literal": {"integer": "int32"}},
"body": {"application": {"function": {"variable": "hydra.core.print.pcre.regex.escapeLiteral"}, "argument": {"variable": "c"}}}}}},
{
"name": "any",
"handler": {"lambda": {"parameter": "_", "domain": "unit", "body": {"literal": {"string": "[\\s\\S]"}}}}},
{
"name": "anchorStart",
"handler": {"lambda": {"parameter": "_", "domain": "unit", "body": {"literal": {"string": "^"}}}}},
{"name": "anchorEnd", "handler": {"lambda": {"parameter": "_", "domain": "unit", "body": {"literal": {"string": "$"}}}}},
{
"name": "group",
"handler": {
"lambda": {
"parameter": "g",
"domain": {"list": {"list": {"variable": "hydra.core.regex.Quantified"}}},
"body": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat"},
"argument": {
"list": [
{"literal": {"string": "("}},
{"application": {"function": {"variable": "hydra.core.print.pcre.regex.alternation"}, "argument": {"variable": "g"}}},
{"literal": {"string": ")"}}]}}}}}},
{
"name": "class",
"handler": {
"lambda": {
"parameter": "cc",
"domain": {"variable": "hydra.core.regex.CharacterClass"},
"body": {
"application": {"function": {"variable": "hydra.core.print.pcre.regex.characterClass"}, "argument": {"variable": "cc"}}}}}}]}},
"argument": {"variable": "a"}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {
"literal": {"string": "Render a single atom; the . metacharacter renders as [\\s\\S] to preserve newline-inclusive 'any'."}}}]}}}}},
{
"term": {
"name": "hydra.core.print.pcre.regex.characterClass",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"variable": "hydra.core.regex.CharacterClass"}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "cc",
"domain": {"variable": "hydra.core.regex.CharacterClass"},
"body": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat"},
"argument": {
"list": [
{"literal": {"string": "["}},
{
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"typeApplication": {"body": {"variable": "hydra.core.lib.logic.ifElse"}, "type": {"literal": "string"}}},
"argument": {
"application": {
"function": {"project": {"typeName": "hydra.core.regex.CharacterClass", "fieldName": "negated"}},
"argument": {"variable": "cc"}}}}},
"argument": {"literal": {"string": "^"}}}},
"argument": {"literal": {"string": ""}}}},
{
"application": {
"function": {"variable": "hydra.core.lib.strings.concat"},
"argument": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {
"typeApplication": {"body": {"variable": "hydra.core.lib.lists.map"}, "type": {"variable": "hydra.core.regex.ClassItem"}}},
"type": {"literal": "string"}}},
"argument": {"variable": "hydra.core.print.pcre.regex.classItem"}}},
"argument": {
"application": {
"function": {"project": {"typeName": "hydra.core.regex.CharacterClass", "fieldName": "items"}},
"argument": {"variable": "cc"}}}}}}},
{"literal": {"string": "]"}}]}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Render a character class, including the leading ^ for a negated class."}}}]}}}}},
{
"term": {
"name": "hydra.core.print.pcre.regex.classItem",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"variable": "hydra.core.regex.ClassItem"}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "item",
"domain": {"variable": "hydra.core.regex.ClassItem"},
"body": {
"application": {
"function": {
"cases": {
"typeName": "hydra.core.regex.ClassItem",
"cases": [
{
"name": "character",
"handler": {
"lambda": {
"parameter": "c",
"domain": {"literal": {"integer": "int32"}},
"body": {
"application": {"function": {"variable": "hydra.core.print.pcre.regex.escapeClassChar"}, "argument": {"variable": "c"}}}}}},
{
"name": "range",
"handler": {
"lambda": {
"parameter": "r",
"domain": {"variable": "hydra.core.regex.CharacterRange"},
"body": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat"},
"argument": {
"list": [
{
"application": {
"function": {"variable": "hydra.core.print.pcre.regex.escapeClassChar"},
"argument": {
"application": {
"function": {"project": {"typeName": "hydra.core.regex.CharacterRange", "fieldName": "from"}},
"argument": {"variable": "r"}}}}},
{"literal": {"string": "-"}},
{
"application": {
"function": {"variable": "hydra.core.print.pcre.regex.escapeClassChar"},
"argument": {
"application": {
"function": {"project": {"typeName": "hydra.core.regex.CharacterRange", "fieldName": "to"}},
"argument": {"variable": "r"}}}}}]}}}}}}]}},
"argument": {"variable": "item"}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Render one character-class member (a single character or an inclusive range)."}}}]}}}}},
{
"term": {
"name": "hydra.core.print.pcre.regex.escapeClassChar",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"literal": {"integer": "int32"}}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "c",
"domain": {"literal": {"integer": "int32"}},
"body": {
"let": {
"bindings": [
{
"name": "isMeta",
"term": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.lib.lists.foldl"}, "type": {"literal": "boolean"}}},
"type": {"literal": {"integer": "int32"}}}},
"argument": {
"lambda": {
"parameter": "acc",
"domain": {"literal": "boolean"},
"body": {
"lambda": {
"parameter": "m",
"domain": {"literal": {"integer": "int32"}},
"body": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.logic.or"}, "argument": {"variable": "acc"}}},
"argument": {
"application": {
"function": {
"application": {
"function": {"typeApplication": {"body": {"variable": "hydra.core.lib.equality.equal"}, "type": {"literal": {"integer": "int32"}}}},
"argument": {"variable": "c"}}},
"argument": {"variable": "m"}}}}}}}}}}},
"argument": {"literal": {"boolean": false}}}},
"argument": {
"list": [
{"literal": {"integer": {"int32": 92}}},
{"literal": {"integer": {"int32": 93}}},
{"literal": {"integer": {"int32": 94}}},
{"literal": {"integer": {"int32": 45}}}]}}},
"typeScheme": {"variables": [], "body": {"literal": "boolean"}, "constraints": []}}],
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"typeApplication": {"body": {"variable": "hydra.core.lib.logic.ifElse"}, "type": {"literal": "string"}}},
"argument": {"variable": "isMeta"}}},
"argument": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.strings.concat2"}, "argument": {"literal": {"string": "\\"}}}},
"argument": {"application": {"function": {"variable": "hydra.core.print.pcre.regex.printCodePoint"}, "argument": {"variable": "c"}}}}}}},
"argument": {"application": {"function": {"variable": "hydra.core.print.pcre.regex.printCodePoint"}, "argument": {"variable": "c"}}}}}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {
"literal": {"string": "Render a code point inside a character class, uniformly escaping the class metacharacters \\ ] ^ -."}}}]}}}}},
{
"term": {
"name": "hydra.core.print.pcre.regex.escapeLiteral",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"literal": {"integer": "int32"}}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "c",
"domain": {"literal": {"integer": "int32"}},
"body": {
"let": {
"bindings": [
{
"name": "isMeta",
"term": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {"typeApplication": {"body": {"variable": "hydra.core.lib.lists.foldl"}, "type": {"literal": "boolean"}}},
"type": {"literal": {"integer": "int32"}}}},
"argument": {
"lambda": {
"parameter": "acc",
"domain": {"literal": "boolean"},
"body": {
"lambda": {
"parameter": "m",
"domain": {"literal": {"integer": "int32"}},
"body": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.logic.or"}, "argument": {"variable": "acc"}}},
"argument": {
"application": {
"function": {
"application": {
"function": {"typeApplication": {"body": {"variable": "hydra.core.lib.equality.equal"}, "type": {"literal": {"integer": "int32"}}}},
"argument": {"variable": "c"}}},
"argument": {"variable": "m"}}}}}}}}}}},
"argument": {"literal": {"boolean": false}}}},
"argument": {
"list": [
{"literal": {"integer": {"int32": 46}}},
{"literal": {"integer": {"int32": 94}}},
{"literal": {"integer": {"int32": 36}}},
{"literal": {"integer": {"int32": 42}}},
{"literal": {"integer": {"int32": 43}}},
{"literal": {"integer": {"int32": 63}}},
{"literal": {"integer": {"int32": 40}}},
{"literal": {"integer": {"int32": 41}}},
{"literal": {"integer": {"int32": 91}}},
{"literal": {"integer": {"int32": 93}}},
{"literal": {"integer": {"int32": 123}}},
{"literal": {"integer": {"int32": 125}}},
{"literal": {"integer": {"int32": 124}}},
{"literal": {"integer": {"int32": 92}}}]}}},
"typeScheme": {"variables": [], "body": {"literal": "boolean"}, "constraints": []}}],
"body": {
"application": {
"function": {
"application": {
"function": {
"application": {
"function": {"typeApplication": {"body": {"variable": "hydra.core.lib.logic.ifElse"}, "type": {"literal": "string"}}},
"argument": {"variable": "isMeta"}}},
"argument": {
"application": {
"function": {"application": {"function": {"variable": "hydra.core.lib.strings.concat2"}, "argument": {"literal": {"string": "\\"}}}},
"argument": {"application": {"function": {"variable": "hydra.core.print.pcre.regex.printCodePoint"}, "argument": {"variable": "c"}}}}}}},
"argument": {"application": {"function": {"variable": "hydra.core.print.pcre.regex.printCodePoint"}, "argument": {"variable": "c"}}}}}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {
"literal": {"string": "Render a literal code point in top-level context, backslash-escaping PCRE/ECMA metacharacters."}}}]}}}}},
{
"term": {
"name": "hydra.core.print.pcre.regex.printCodePoint",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"literal": {"integer": "int32"}}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "c",
"domain": {"literal": {"integer": "int32"}},
"body": {
"application": {"function": {"variable": "hydra.core.lib.strings.fromList"}, "argument": {"list": [{"variable": "c"}]}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Render a single Unicode code point as a one-character string."}}}]}}}}},
{
"term": {
"name": "hydra.core.print.pcre.regex.printRegex",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"list": {"list": {"variable": "hydra.core.regex.Quantified"}}}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "r",
"domain": {"list": {"list": {"variable": "hydra.core.regex.Quantified"}}},
"body": {"application": {"function": {"variable": "hydra.core.print.pcre.regex.alternation"}, "argument": {"variable": "r"}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {
"literal": {
"string": "Render a hydra.core.regex AST into PCRE / java.util.regex / ECMA syntax. Identical to the canonical printer except that . (any incl. newline) becomes [\\s\\S]."}}}]}}}}},
{
"term": {
"name": "hydra.core.print.pcre.regex.quantified",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"variable": "hydra.core.regex.Quantified"}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "qa",
"domain": {"variable": "hydra.core.regex.Quantified"},
"body": {
"application": {
"function": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat2"},
"argument": {
"application": {
"function": {"variable": "hydra.core.print.pcre.regex.atom"},
"argument": {
"application": {
"function": {"project": {"typeName": "hydra.core.regex.Quantified", "fieldName": "atom"}},
"argument": {"variable": "qa"}}}}}}},
"argument": {
"application": {
"function": {"variable": "hydra.core.print.pcre.regex.quantifier"},
"argument": {
"application": {
"function": {"project": {"typeName": "hydra.core.regex.Quantified", "fieldName": "quantifier"}},
"argument": {"variable": "qa"}}}}}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Render an atom followed by its quantifier suffix."}}}]}}}}},
{
"term": {
"name": "hydra.core.print.pcre.regex.quantifier",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"variable": "hydra.core.regex.Quantifier"}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "q",
"domain": {"variable": "hydra.core.regex.Quantifier"},
"body": {
"application": {
"function": {
"cases": {
"typeName": "hydra.core.regex.Quantifier",
"cases": [
{"name": "one", "handler": {"lambda": {"parameter": "_", "domain": "unit", "body": {"literal": {"string": ""}}}}},
{"name": "zeroOrOne", "handler": {"lambda": {"parameter": "_", "domain": "unit", "body": {"literal": {"string": "?"}}}}},
{
"name": "zeroOrMore",
"handler": {"lambda": {"parameter": "_", "domain": "unit", "body": {"literal": {"string": "*"}}}}},
{"name": "oneOrMore", "handler": {"lambda": {"parameter": "_", "domain": "unit", "body": {"literal": {"string": "+"}}}}},
{
"name": "exactly",
"handler": {
"lambda": {
"parameter": "n",
"domain": {"literal": {"integer": "int32"}},
"body": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat"},
"argument": {
"list": [
{"literal": {"string": "{"}},
{"application": {"function": {"variable": "hydra.core.lib.literals.printInt32"}, "argument": {"variable": "n"}}},
{"literal": {"string": "}"}}]}}}}}},
{
"name": "atLeast",
"handler": {
"lambda": {
"parameter": "n",
"domain": {"literal": {"integer": "int32"}},
"body": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat"},
"argument": {
"list": [
{"literal": {"string": "{"}},
{"application": {"function": {"variable": "hydra.core.lib.literals.printInt32"}, "argument": {"variable": "n"}}},
{"literal": {"string": ",}"}}]}}}}}},
{
"name": "range",
"handler": {
"lambda": {
"parameter": "r",
"domain": {"variable": "hydra.core.regex.Range"},
"body": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat"},
"argument": {
"list": [
{"literal": {"string": "{"}},
{
"application": {
"function": {"variable": "hydra.core.lib.literals.printInt32"},
"argument": {
"application": {"function": {"project": {"typeName": "hydra.core.regex.Range", "fieldName": "min"}}, "argument": {"variable": "r"}}}}},
{"literal": {"string": ","}},
{
"application": {
"function": {"variable": "hydra.core.lib.literals.printInt32"},
"argument": {
"application": {"function": {"project": {"typeName": "hydra.core.regex.Range", "fieldName": "max"}}, "argument": {"variable": "r"}}}}},
{"literal": {"string": "}"}}]}}}}}}]}},
"argument": {"variable": "q"}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Render a quantifier suffix; the 'one' quantifier renders as the empty string."}}}]}}}}},
{
"term": {
"name": "hydra.core.print.pcre.regex.regexSequence",
"signature": {
"typeParameters": [],
"parameters": [{"name": "arg0", "type": {"list": {"variable": "hydra.core.regex.Quantified"}}, "isLazy": false}],
"result": {"type": {"literal": "string"}}},
"body": {
"annotated": {
"body": {
"lambda": {
"parameter": "s",
"domain": {"list": {"variable": "hydra.core.regex.Quantified"}},
"body": {
"application": {
"function": {"variable": "hydra.core.lib.strings.concat"},
"argument": {
"application": {
"function": {
"application": {
"function": {
"typeApplication": {
"body": {
"typeApplication": {"body": {"variable": "hydra.core.lib.lists.map"}, "type": {"variable": "hydra.core.regex.Quantified"}}},
"type": {"literal": "string"}}},
"argument": {"variable": "hydra.core.print.pcre.regex.quantified"}}},
"argument": {"variable": "s"}}}}}}},
"annotation": {
"map": [
{
"key": {"variable": "description"},
"value": {"literal": {"string": "Render a sequence of quantified atoms by concatenation."}}}]}}}}}]}