postscript 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"bindings":null,"version":"0.1.0","grammar":"PostScript","shape":"parsanol-tree/v2","binding_version":1,"entries":{"main":{"root":"program","grammar":{"atoms":[{"Entity":{"atom":9}},{"Re":{"pattern":"[\\x00]"}},{"Re":{"pattern":"[\\x09]"}},{"Re":{"pattern":"[\\x0a]"}},{"Re":{"pattern":"[\\x0b]"}},{"Re":{"pattern":"[\\x0c]"}},{"Re":{"pattern":"[\\x0d]"}},{"Re":{"pattern":"[ ]"}},{"Alternative":{"atoms":[1,2,3,4,5,6,7]}},{"Repetition":{"atom":8,"min":1,"max":null,"tag":"Repetition"}},{"Entity":{"atom":17}},{"Str":{"pattern":"%%"}},{"Re":{"pattern":"[\\x0a]"}},{"Lookahead":{"atom":12,"positive":false}},{"Re":{"pattern":"[\\x00-\\u{10ffff}]"}},{"Sequence":{"atoms":[13,14]}},{"Repetition":{"atom":15,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[11,16]}},{"Named":{"name":"dsc","atom":10}},{"Entity":{"atom":26}},{"Str":{"pattern":"%"}},{"Re":{"pattern":"[\\x0a]"}},{"Lookahead":{"atom":21,"positive":false}},{"Re":{"pattern":"[\\x00-\\u{10ffff}]"}},{"Sequence":{"atoms":[22,23]}},{"Repetition":{"atom":24,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[20,25]}},{"Entity":{"atom":208}},{"Entity":{"atom":57}},{"Entity":{"atom":30}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Repetition":{"atom":29,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"#"}},{"Entity":{"atom":30}},{"Re":{"pattern":"[\\x41-\\x5a]"}},{"Re":{"pattern":"[\\x61-\\x7a]"}},{"Alternative":{"atoms":[33,34,35]}},{"Repetition":{"atom":36,"min":1,"max":null,"tag":"Repetition"}},{"Entity":{"atom":55}},{"Entity":{"atom":50}},{"Re":{"pattern":"[(]"}},{"Re":{"pattern":"[)]"}},{"Re":{"pattern":"[<]"}},{"Re":{"pattern":"[>]"}},{"Re":{"pattern":"[\\[]"}},{"Re":{"pattern":"[\\]]"}},{"Re":{"pattern":"[{]"}},{"Re":{"pattern":"[}]"}},{"Re":{"pattern":"[/]"}},{"Re":{"pattern":"[%]"}},{"Alternative":{"atoms":[40,41,42,43,44,45,46,47,48,49]}},{"Entity":{"atom":9}},{"Alternative":{"atoms":[39,51]}},{"Lookahead":{"atom":52,"positive":false}},{"Re":{"pattern":"[\\x00-\\u{10ffff}]"}},{"Sequence":{"atoms":[53,54]}},{"Lookahead":{"atom":38,"positive":false}},{"Sequence":{"atoms":[31,32,37,56]}},{"Named":{"name":"radix","atom":28}},{"Entity":{"atom":97}},{"Entity":{"atom":64}},{"Str":{"pattern":"+"}},{"Str":{"pattern":"-"}},{"Alternative":{"atoms":[61,62]}},{"Repetition":{"atom":63,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":30}},{"Repetition":{"atom":65,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"."}},{"Entity":{"atom":30}},{"Repetition":{"atom":68,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[67,69]}},{"Repetition":{"atom":70,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":80}},{"Re":{"pattern":"[e]"}},{"Re":{"pattern":"[E]"}},{"Alternative":{"atoms":[73,74]}},{"Entity":{"atom":64}},{"Repetition":{"atom":76,"min":0,"max":1,"tag":"Maybe"}},{"Entity":{"atom":30}},{"Repetition":{"atom":78,"min":1,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[75,77,79]}},{"Sequence":{"atoms":[66,71,72]}},{"Entity":{"atom":30}},{"Repetition":{"atom":82,"min":1,"max":null,"tag":"Repetition"}},{"Str":{"pattern":"."}},{"Entity":{"atom":30}},{"Repetition":{"atom":85,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[83,84,86]}},{"Str":{"pattern":"."}},{"Entity":{"atom":30}},{"Repetition":{"atom":89,"min":1,"max":null,"tag":"Repetition"}},{"Entity":{"atom":80}},{"Repetition":{"atom":91,"min":0,"max":1,"tag":"Maybe"}},{"Sequence":{"atoms":[88,90,92]}},{"Alternative":{"atoms":[81,87,93]}},{"Entity":{"atom":55}},{"Lookahead":{"atom":95,"positive":false}},{"Sequence":{"atoms":[60,94,96]}},{"Named":{"name":"real","atom":59}},{"Entity":{"atom":105}},{"Entity":{"atom":64}},{"Entity":{"atom":30}},{"Repetition":{"atom":101,"min":1,"max":null,"tag":"Repetition"}},{"Entity":{"atom":55}},{"Lookahead":{"atom":103,"positive":false}},{"Sequence":{"atoms":[100,102,104]}},{"Named":{"name":"integer","atom":99}},{"Entity":{"atom":130}},{"Str":{"pattern":"("}},{"Entity":{"atom":115}},{"Str":{"pattern":"\\"}},{"Re":{"pattern":"[\\x30-\\x37]"}},{"Repetition":{"atom":111,"min":1,"max":3,"tag":"Repetition"}},{"Re":{"pattern":"[\\x00-\\u{10ffff}]"}},{"Alternative":{"atoms":[112,113]}},{"Sequence":{"atoms":[110,114]}},{"Entity":{"atom":127}},{"Re":{"pattern":"[(]"}},{"Re":{"pattern":"[)]"}},{"Re":{"pattern":"[\\\\]"}},{"Alternative":{"atoms":[117,118,119]}},{"Lookahead":{"atom":120,"positive":false}},{"Re":{"pattern":"[\\x00-\\u{10ffff}]"}},{"Sequence":{"atoms":[121,122]}},{"Alternative":{"atoms":[109,116,123]}},{"Repetition":{"atom":124,"min":0,"max":null,"tag":"Repetition"}},{"Str":{"pattern":")"}},{"Sequence":{"atoms":[108,125,126]}},{"Alternative":{"atoms":[109,116,123]}},{"Repetition":{"atom":128,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[108,129,126]}},{"Named":{"name":"string","atom":107}},{"Entity":{"atom":143}},{"Str":{"pattern":"<"}},{"Entity":{"atom":138}},{"Re":{"pattern":"[\\x30-\\x39]"}},{"Re":{"pattern":"[\\x41-\\x46]"}},{"Re":{"pattern":"[\\x61-\\x66]"}},{"Alternative":{"atoms":[135,136,137]}},{"Entity":{"atom":9}},{"Alternative":{"atoms":[134,139]}},{"Repetition":{"atom":140,"min":0,"max":null,"tag":"Repetition"}},{"Str":{"pattern":">"}},{"Sequence":{"atoms":[133,141,142]}},{"Named":{"name":"hex_string","atom":132}},{"Entity":{"atom":206}},{"Str":{"pattern":"<<"}},{"Named":{"name":"open","atom":146}},{"Entity":{"atom":9}},{"Entity":{"atom":17}},{"Named":{"name":"dsc","atom":149}},{"Entity":{"atom":26}},{"Entity":{"atom":200}},{"Named":{"name":"dictionary","atom":145}},{"Entity":{"atom":198}},{"Str":{"pattern":"["}},{"Named":{"name":"open","atom":155}},{"Entity":{"atom":9}},{"Entity":{"atom":17}},{"Named":{"name":"dsc","atom":158}},{"Entity":{"atom":26}},{"Entity":{"atom":192}},{"Named":{"name":"array","atom":154}},{"Entity":{"atom":190}},{"Str":{"pattern":"{"}},{"Named":{"name":"open","atom":164}},{"Entity":{"atom":9}},{"Entity":{"atom":17}},{"Named":{"name":"dsc","atom":167}},{"Entity":{"atom":26}},{"Entity":{"atom":184}},{"Named":{"name":"procedure","atom":163}},{"Entity":{"atom":178}},{"Str":{"pattern":"/"}},{"Str":{"pattern":"\\"}},{"Alternative":{"atoms":[173,174]}},{"Entity":{"atom":55}},{"Repetition":{"atom":176,"min":0,"max":null,"tag":"Repetition"}},{"Sequence":{"atoms":[175,177]}},{"Named":{"name":"literal_name","atom":172}},{"Entity":{"atom":182}},{"Entity":{"atom":55}},{"Repetition":{"atom":181,"min":1,"max":null,"tag":"Repetition"}},{"Named":{"name":"name","atom":180}},{"Alternative":{"atoms":[58,98,106,131,144,153,162,171,179,183]}},{"Alternative":{"atoms":[166,168,169,170]}},{"Repetition":{"atom":185,"min":0,"max":null,"tag":"Repetition"}},{"Named":{"name":"items","atom":186}},{"Str":{"pattern":"}"}},{"Named":{"name":"close","atom":188}},{"Sequence":{"atoms":[165,187,189]}},{"Named":{"name":"procedure","atom":163}},{"Alternative":{"atoms":[58,98,106,131,144,153,162,191,179,183]}},{"Alternative":{"atoms":[157,159,160,161]}},{"Repetition":{"atom":193,"min":0,"max":null,"tag":"Repetition"}},{"Named":{"name":"items","atom":194}},{"Str":{"pattern":"]"}},{"Named":{"name":"close","atom":196}},{"Sequence":{"atoms":[156,195,197]}},{"Named":{"name":"array","atom":154}},{"Alternative":{"atoms":[58,98,106,131,144,153,199,191,179,183]}},{"Alternative":{"atoms":[148,150,151,152]}},{"Repetition":{"atom":201,"min":0,"max":null,"tag":"Repetition"}},{"Named":{"name":"items","atom":202}},{"Str":{"pattern":">>"}},{"Named":{"name":"close","atom":204}},{"Sequence":{"atoms":[147,203,205]}},{"Named":{"name":"dictionary","atom":145}},{"Alternative":{"atoms":[58,98,106,131,144,207,199,191,179,183]}},{"Alternative":{"atoms":[0,18,19,27]}},{"Repetition":{"atom":209,"min":0,"max":null,"tag":"Repetition"}}],"root":210},"bindings":[]}},"preprocess":{},"tables":{},"lint":{"order_warnings":["rule object: branches 1 and 2 are order-dependent (shared first bytes; ordered choice is decisive)","rule object: branches 1 and 3 are order-dependent (shared first bytes; ordered choice is decisive)","rule object: branches 1 and 10 are order-dependent (first set not statically known)","rule object: branches 2 and 3 are order-dependent (shared first bytes; ordered choice is decisive)","rule object: branches 2 and 10 are order-dependent (first set not statically known)","rule object: branches 3 and 10 are order-dependent (first set not statically known)","rule object: branches 4 and 10 are order-dependent (first set not statically known)","rule object: branches 5 and 6 are order-dependent (shared first bytes; ordered choice is decisive)","rule object: branches 5 and 10 are order-dependent (first set not statically known)","rule object: branches 6 and 10 are order-dependent (first set not statically known)","rule object: branches 7 and 10 are order-dependent (first set not statically known)","rule object: branches 8 and 10 are order-dependent (first set not statically known)","rule object: branches 9 and 10 are order-dependent (first set not statically known)"]},"default_entry":"main","render":{},"derive":{},"tests":[{"entry":"main","kind":"accept","input":"10 20 moveto (hi) show","expect":{}},{"entry":"main","kind":"accept","input":"(nested (deep (deeper)) here) print","expect":{}},{"entry":"main","kind":"accept","input":"/proc { 1 2 add } bind def","expect":{}},{"entry":"main","kind":"accept","input":"[1 2 (three) /Four [5 6]] aload","expect":{}},{"entry":"main","kind":"accept","input":"<</PageSize[612 792]>> setpagedevice","expect":{}},{"entry":"main","kind":"accept","input":"<4f 4b> print","expect":{}},{"entry":"main","kind":"accept","input":"16#FF setgray","expect":{}},{"entry":"main","kind":"accept","input":"-.002 6.02E23 scale","expect":{}},{"entry":"main","kind":"accept","input":"%%BeginSetup","expect":{}},{"entry":"main","kind":"accept","input":"123abc print","expect":{}},{"entry":"main","kind":"reject","input":"{ unclosed","expect":{}},{"entry":"main","kind":"reject","input":"(unterminated","expect":{}},{"entry":"main","kind":"reject","input":"<hex","expect":{}},{"entry":"main","kind":"reject","input":"[1 2","expect":{}},{"entry":"main","kind":"capture","input":"10 20 moveto","expect":{"integer":"10","name":"moveto"}},{"entry":"main","kind":"capture","input":"-.002 6.02E23 scale","expect":{"real":"-.002"}},{"entry":"main","kind":"capture","input":"16#FF setgray","expect":{"radix":"16#FF"}},{"entry":"main","kind":"capture","input":"123abc print","expect":{"name":"123abc"}},{"entry":"main","kind":"capture","input":"(a (b) c) show","expect":{"string":"(a (b) c)"}},{"entry":"main","kind":"capture","input":"<4f 4b> print","expect":{"hex_string":"<4f 4b>"}},{"entry":"main","kind":"capture","input":"/proc { 1 2 add } def","expect":{"literal_name":"/proc"}},{"entry":"main","kind":"capture","input":"%%BeginSetup\n1 pop","expect":{"dsc":"%%BeginSetup"}},{"entry":"main","kind":"capture","input":"[1 2]","expect":{"open":"[","close":"]"}},{"entry":"main","kind":"capture","input":"<< /A 1 >>","expect":{"open":"<<","close":">>"}},{"entry":"main","kind":"capture","input":"{ %%Page: 1\n }","expect":{"dsc":"%%Page: 1"}},{"entry":"main","kind":"capture","input":"%%A\rB\n1","expect":{"dsc":"%%A\rB"}},{"entry":"main","kind":"capture","input":"\\Name","expect":{"literal_name":"\\Name"}},{"entry":"main","kind":"capture","input":"// x","expect":{"literal_name":"/"}}],"docs":{"program":"Program: any sequence of whitespace, comments, and objects.\n(guide: docs/syntax/tokens.adoc, docs/syntax/objects.adoc)","ws":"Whitespace: NUL HT LF VT FF CR SPACE (guide: docs/syntax/tokens.adoc\nlists NUL HT LF FF CR SPACE; VT is included to match the lexer).","comment":"Comment: \"%\" to end of line (guide: docs/syntax/tokens.adoc). Only LF\nends it, as in the lexer; a lone CR is part of the comment.","dsc_comment":"DSC comment: \"%%\" line -- captured distinctly by the lexer\n(document structuring conventions; passes through to the model).\nOnly LF ends it, as for comment.","object":"Objects (guide: docs/syntax/objects.adoc). Every object is captured\nunder the name of its rule.\nOrdered choice: number/radix before name (a word is classified by\nshape, matching the lexer's scan_word_or_number + emit_word).","digit":"------------------------------------------------------------------\nNumbers (guide: docs/syntax/data-types.adoc)\n------------------------------------------------------------------","integer":"Integer: optional sign + digits. The !name_char guard enforces the\nlexer's maximal-munch word scan -- \"123abc\" is ONE name, not\ninteger \"123\" + name \"abc\".","real":"Real: sign + (fraction and/or exponent) -- a bare digit run is an\ninteger, so real requires \".\" or an exponent (e.g. 3.45, -7.89,\n1.0e10, 6E23, -.002).","radix":"Radix number: base#value (e.g. 16#FF) -- LEVEL 2+ (marked per the\nlevel-gating decision; see claricle/postscript#4).","string":"------------------------------------------------------------------\nStrings (guide: docs/syntax/strings.adoc)\n------------------------------------------------------------------\nLiteral string: balanced parentheses, \"\\\" escapes\n(\\n \\r \\t \\b \\f \\\\ \\( \\), \\ddd octal 1-3 digits, line continuations;\nunknown escapes stand for the escaped character -- mirrors\nlexer.rb handle_escape).","hex_string":"Hex string: <hexdigits, whitespace allowed> (guide: docs/syntax/strings.adoc).","delimiter":"------------------------------------------------------------------\nNames (guide: docs/syntax/operators.adoc, docs/syntax/tokens.adoc)\n------------------------------------------------------------------\nDelimiters: ( ) < > [ ] { } / % -- terminate names.","name_char":"Any byte that is neither a delimiter nor whitespace.","name":"Executable name: any run of non-delimiter, non-whitespace bytes.","literal_name":"Literal name: \"/\" prefix (guide: docs/syntax/operators.adoc). As in\nthe lexer, a leading backslash also starts one, and the name may be\nempty: \"//x\" is an empty literal name followed by \"/x\".","array":"------------------------------------------------------------------\nComposites\n------------------------------------------------------------------\nComposites capture their opening and closing delimiters (open,\nclose) and their contents (items), so each delimiter keeps its\nposition. DSC comments inside them are captured as at top level.\nArray: \"[ objects ]\" (guide: docs/syntax/arrays.adoc).","procedure":"Procedure: \"{ objects }\" -- executable array; PEG recursion covers\nnesting (guide: docs/syntax/procedures.adoc).","dictionary":"Dictionary: \"<< objects >>\" (guide: docs/syntax/dictionaries.adoc).\nKeys and values are objects; pairing is semantic (the interpreter\nstack), not syntactic."},"source":"# PostScript grammar -- PARG source (parsanol grammar language).\n# Normative source: the PostScript Language Guide\n# (claricle/postscript-guide); each rule cites the guide page it\n# derives from. Extraction target: the hand-written lexer/AST builder\n# in claricle/postscript lib/postscript/source/ -- the rules below\n# mirror that lexer's state machine (whitespace set, delimiter set,\n# string escape set, DSC comments).\n# Level 1/2/3 (per the design decision in claricle/postscript#4):\n# this grammar is LEVEL-AGNOSTIC -- the operator vocabulary is registry\n# metadata, not grammar structure. Level-gated literal forms (e.g.\n# radix numbers, Level 2+) are marked inline.\n# Compile: parsanol parg compile postscript.parg -o postscript.json\n\ngrammar PostScript version \"0.1.0\" {\n\n ## Program: any sequence of whitespace, comments, and objects.\n ## (guide: docs/syntax/tokens.adoc, docs/syntax/objects.adoc)\n program = 0*( ws / dsc_comment as dsc / comment / object )\n\n ## Whitespace: NUL HT LF VT FF CR SPACE (guide: docs/syntax/tokens.adoc\n ## lists NUL HT LF FF CR SPACE; VT is included to match the lexer).\n ws = 1*( %x00 / %x09 / %x0A / %x0B / %x0C / %x0D / %x20 )\n\n ## Comment: \"%\" to end of line (guide: docs/syntax/tokens.adoc). Only LF\n ## ends it, as in the lexer; a lone CR is part of the comment.\n comment = \"%\" 0*( !%x0A ANY )\n\n ## DSC comment: \"%%\" line -- captured distinctly by the lexer\n ## (document structuring conventions; passes through to the model).\n ## Only LF ends it, as for comment.\n dsc_comment = \"%%\" 0*( !%x0A ANY )\n\n ## Objects (guide: docs/syntax/objects.adoc). Every object is captured\n ## under the name of its rule.\n ## Ordered choice: number/radix before name (a word is classified by\n ## shape, matching the lexer's scan_word_or_number + emit_word).\n object = radix as radix / real as real / integer as integer / string as string / hex_string as hex_string / dictionary as dictionary / array as array / procedure as procedure / literal_name as literal_name / name as name\n\n ## ------------------------------------------------------------------\n ## Numbers (guide: docs/syntax/data-types.adoc)\n ## ------------------------------------------------------------------\n\n digit = %x30-39\n\n sign = [\"+\" / \"-\"]\n\n ## Integer: optional sign + digits. The !name_char guard enforces the\n ## lexer's maximal-munch word scan -- \"123abc\" is ONE name, not\n ## integer \"123\" + name \"abc\".\n integer = sign 1*digit !name_char\n\n ## Real: sign + (fraction and/or exponent) -- a bare digit run is an\n ## integer, so real requires \".\" or an exponent (e.g. 3.45, -7.89,\n ## 1.0e10, 6E23, -.002).\n real = sign ( 1*digit [\".\" 0*digit] exponent / 1*digit \".\" 0*digit / \".\" 1*digit [exponent] ) !name_char\n\n exponent = ( %x65 / %x45 ) [sign] 1*digit\n\n ## Radix number: base#value (e.g. 16#FF) -- LEVEL 2+ (marked per the\n ## level-gating decision; see claricle/postscript#4).\n radix = 1*digit \"#\" 1*( digit / %x41-5A / %x61-7A ) !name_char\n\n ## ------------------------------------------------------------------\n ## Strings (guide: docs/syntax/strings.adoc)\n ## ------------------------------------------------------------------\n\n ## Literal string: balanced parentheses, \"\\\" escapes\n ## (\\n \\r \\t \\b \\f \\\\ \\( \\), \\ddd octal 1-3 digits, line continuations;\n ## unknown escapes stand for the escaped character -- mirrors\n ## lexer.rb handle_escape).\n string = \"(\" 0*( escaped / string / !(%x28 / %x29 / %x5C) ANY ) \")\"\n escaped = \"\\\\\" ( 1*3(%x30-37) / ANY )\n\n ## Hex string: <hexdigits, whitespace allowed> (guide: docs/syntax/strings.adoc).\n hex_string = \"<\" 0*( hexdigit / ws ) \">\"\n hexdigit = %x30-39 / %x41-46 / %x61-66\n\n ## ------------------------------------------------------------------\n ## Names (guide: docs/syntax/operators.adoc, docs/syntax/tokens.adoc)\n ## ------------------------------------------------------------------\n\n ## Delimiters: ( ) < > [ ] { } / % -- terminate names.\n delimiter = %x28 / %x29 / %x3C / %x3E / %x5B / %x5D / %x7B / %x7D / %x2F / %x25\n\n ## Any byte that is neither a delimiter nor whitespace.\n name_char = !( delimiter / ws ) ANY\n\n ## Executable name: any run of non-delimiter, non-whitespace bytes.\n name = 1*name_char\n\n ## Literal name: \"/\" prefix (guide: docs/syntax/operators.adoc). As in\n ## the lexer, a leading backslash also starts one, and the name may be\n ## empty: \"//x\" is an empty literal name followed by \"/x\".\n literal_name = ( \"/\" / \"\\\\\" ) 0*name_char\n\n ## ------------------------------------------------------------------\n ## Composites\n ## ------------------------------------------------------------------\n\n ## Composites capture their opening and closing delimiters (open,\n ## close) and their contents (items), so each delimiter keeps its\n ## position. DSC comments inside them are captured as at top level.\n\n ## Array: \"[ objects ]\" (guide: docs/syntax/arrays.adoc).\n array = \"[\" as open 0*( ws / dsc_comment as dsc / comment / object ) as items \"]\" as close\n\n ## Procedure: \"{ objects }\" -- executable array; PEG recursion covers\n ## nesting (guide: docs/syntax/procedures.adoc).\n procedure = \"{\" as open 0*( ws / dsc_comment as dsc / comment / object ) as items \"}\" as close\n\n ## Dictionary: \"<< objects >>\" (guide: docs/syntax/dictionaries.adoc).\n ## Keys and values are objects; pairing is semantic (the interpreter\n ## stack), not syntactic.\n dictionary = \"<<\" as open 0*( ws / dsc_comment as dsc / comment / object ) as items \">>\" as close\n\n ## ------------------------------------------------------------------\n ## Operator vocabulary\n ## ------------------------------------------------------------------\n ## Operators are executable names -- the vocabulary is REGISTRY\n ## metadata (Model::Operators), gated per Level 1/2/3 by profile\n ## validation after parsing (design decision: claricle/postscript#4).\n ## The guide's docs/commands/** categories enumerate the vocabulary.\n\n ## ------------------------------------------------------------------\n ## Smoke tests (full-input consumption enforced by the entry rule)\n ## ------------------------------------------------------------------\n entry main: program\n\n test main {\n accept \"10 20 moveto (hi) show\"\n accept \"(nested (deep (deeper)) here) print\"\n accept \"/proc { 1 2 add } bind def\"\n accept \"[1 2 (three) /Four [5 6]] aload\"\n accept \"<</PageSize[612 792]>> setpagedevice\"\n accept \"<4f 4b> print\"\n accept \"16#FF setgray\"\n accept \"-.002 6.02E23 scale\"\n accept \"%%BeginSetup\"\n accept \"123abc print\"\n reject \"{ unclosed\"\n reject \"(unterminated\"\n reject \"<hex\"\n reject \"[1 2\"\n # Each token is captured under its rule's name (the first capture\n # of each name is checked).\n capture \"10 20 moveto\" { integer: \"10\" name: \"moveto\" }\n capture \"-.002 6.02E23 scale\" { real: \"-.002\" }\n capture \"16#FF setgray\" { radix: \"16#FF\" }\n capture \"123abc print\" { name: \"123abc\" }\n capture \"(a (b) c) show\" { string: \"(a (b) c)\" }\n capture \"<4f 4b> print\" { hex_string: \"<4f 4b>\" }\n capture \"/proc { 1 2 add } def\" { literal_name: \"/proc\" }\n capture \"%%BeginSetup\\n1 pop\" { dsc: \"%%BeginSetup\" }\n capture \"[1 2]\" { open: \"[\" close: \"]\" }\n capture \"<< /A 1 >>\" { open: \"<<\" close: \">>\" }\n capture \"{ %%Page: 1\\n }\" { dsc: \"%%Page: 1\" }\n capture \"%%A\\rB\\n1\" { dsc: \"%%A\\rB\" }\n capture \"\\\\Name\" { literal_name: \"\\\\Name\" }\n capture \"// x\" { literal_name: \"/\" }\n }\n}\n","source_hash":"3a1a57c1bab8c6bd9621642f42514c3ee8c2c9415190642bb90f856814dc9592","unicode_tables":"onigmo (Ruby 3.4.13)","compiler_version":"1.5.15","edition":2,"semantics_hash":"sha256:541f506068eb52081666caafcb24f374a767525d92ec3b867ba37231d6c679b7","checksum":"sha256:3dde9034e228fcc36e0e1132194aba178cb34b954432d4cb9bbeba1018568cb3","validated":{"lint_errors":0,"lint_warnings":13,"tests_total":28,"tests_failures":0,"self_test":true},"byte_checksum":"sha256:08fe97a8aee397805fae7ea631e17dcc93886874f853e75ce5d3bf0254e61f06"}
@@ -0,0 +1,161 @@
1
+ # PostScript grammar -- PARG source (parsanol grammar language).
2
+ # Normative source: the PostScript Language Guide
3
+ # (claricle/postscript-guide); each rule cites the guide page it
4
+ # derives from. Extraction target: the hand-written lexer/AST builder
5
+ # in claricle/postscript lib/postscript/source/ -- the rules below
6
+ # mirror that lexer's state machine (whitespace set, delimiter set,
7
+ # string escape set, DSC comments).
8
+ # Level 1/2/3 (per the design decision in claricle/postscript#4):
9
+ # this grammar is LEVEL-AGNOSTIC -- the operator vocabulary is registry
10
+ # metadata, not grammar structure. Level-gated literal forms (e.g.
11
+ # radix numbers, Level 2+) are marked inline.
12
+ # Compile: parsanol parg compile postscript.parg -o postscript.json
13
+
14
+ grammar PostScript version "0.1.0" {
15
+
16
+ ## Program: any sequence of whitespace, comments, and objects.
17
+ ## (guide: docs/syntax/tokens.adoc, docs/syntax/objects.adoc)
18
+ program = 0*( ws / dsc_comment as dsc / comment / object )
19
+
20
+ ## Whitespace: NUL HT LF VT FF CR SPACE (guide: docs/syntax/tokens.adoc
21
+ ## lists NUL HT LF FF CR SPACE; VT is included to match the lexer).
22
+ ws = 1*( %x00 / %x09 / %x0A / %x0B / %x0C / %x0D / %x20 )
23
+
24
+ ## Comment: "%" to end of line (guide: docs/syntax/tokens.adoc). Only LF
25
+ ## ends it, as in the lexer; a lone CR is part of the comment.
26
+ comment = "%" 0*( !%x0A ANY )
27
+
28
+ ## DSC comment: "%%" line -- captured distinctly by the lexer
29
+ ## (document structuring conventions; passes through to the model).
30
+ ## Only LF ends it, as for comment.
31
+ dsc_comment = "%%" 0*( !%x0A ANY )
32
+
33
+ ## Objects (guide: docs/syntax/objects.adoc). Every object is captured
34
+ ## under the name of its rule.
35
+ ## Ordered choice: number/radix before name (a word is classified by
36
+ ## shape, matching the lexer's scan_word_or_number + emit_word).
37
+ object = radix as radix / real as real / integer as integer / string as string / hex_string as hex_string / dictionary as dictionary / array as array / procedure as procedure / literal_name as literal_name / name as name
38
+
39
+ ## ------------------------------------------------------------------
40
+ ## Numbers (guide: docs/syntax/data-types.adoc)
41
+ ## ------------------------------------------------------------------
42
+
43
+ digit = %x30-39
44
+
45
+ sign = ["+" / "-"]
46
+
47
+ ## Integer: optional sign + digits. The !name_char guard enforces the
48
+ ## lexer's maximal-munch word scan -- "123abc" is ONE name, not
49
+ ## integer "123" + name "abc".
50
+ integer = sign 1*digit !name_char
51
+
52
+ ## Real: sign + (fraction and/or exponent) -- a bare digit run is an
53
+ ## integer, so real requires "." or an exponent (e.g. 3.45, -7.89,
54
+ ## 1.0e10, 6E23, -.002).
55
+ real = sign ( 1*digit ["." 0*digit] exponent / 1*digit "." 0*digit / "." 1*digit [exponent] ) !name_char
56
+
57
+ exponent = ( %x65 / %x45 ) [sign] 1*digit
58
+
59
+ ## Radix number: base#value (e.g. 16#FF) -- LEVEL 2+ (marked per the
60
+ ## level-gating decision; see claricle/postscript#4).
61
+ radix = 1*digit "#" 1*( digit / %x41-5A / %x61-7A ) !name_char
62
+
63
+ ## ------------------------------------------------------------------
64
+ ## Strings (guide: docs/syntax/strings.adoc)
65
+ ## ------------------------------------------------------------------
66
+
67
+ ## Literal string: balanced parentheses, "\" escapes
68
+ ## (\n \r \t \b \f \\ \( \), \ddd octal 1-3 digits, line continuations;
69
+ ## unknown escapes stand for the escaped character -- mirrors
70
+ ## lexer.rb handle_escape).
71
+ string = "(" 0*( escaped / string / !(%x28 / %x29 / %x5C) ANY ) ")"
72
+ escaped = "\\" ( 1*3(%x30-37) / ANY )
73
+
74
+ ## Hex string: <hexdigits, whitespace allowed> (guide: docs/syntax/strings.adoc).
75
+ hex_string = "<" 0*( hexdigit / ws ) ">"
76
+ hexdigit = %x30-39 / %x41-46 / %x61-66
77
+
78
+ ## ------------------------------------------------------------------
79
+ ## Names (guide: docs/syntax/operators.adoc, docs/syntax/tokens.adoc)
80
+ ## ------------------------------------------------------------------
81
+
82
+ ## Delimiters: ( ) < > [ ] { } / % -- terminate names.
83
+ delimiter = %x28 / %x29 / %x3C / %x3E / %x5B / %x5D / %x7B / %x7D / %x2F / %x25
84
+
85
+ ## Any byte that is neither a delimiter nor whitespace.
86
+ name_char = !( delimiter / ws ) ANY
87
+
88
+ ## Executable name: any run of non-delimiter, non-whitespace bytes.
89
+ name = 1*name_char
90
+
91
+ ## Literal name: "/" prefix (guide: docs/syntax/operators.adoc). As in
92
+ ## the lexer, a leading backslash also starts one, and the name may be
93
+ ## empty: "//x" is an empty literal name followed by "/x".
94
+ literal_name = ( "/" / "\\" ) 0*name_char
95
+
96
+ ## ------------------------------------------------------------------
97
+ ## Composites
98
+ ## ------------------------------------------------------------------
99
+
100
+ ## Composites capture their opening and closing delimiters (open,
101
+ ## close) and their contents (items), so each delimiter keeps its
102
+ ## position. DSC comments inside them are captured as at top level.
103
+
104
+ ## Array: "[ objects ]" (guide: docs/syntax/arrays.adoc).
105
+ array = "[" as open 0*( ws / dsc_comment as dsc / comment / object ) as items "]" as close
106
+
107
+ ## Procedure: "{ objects }" -- executable array; PEG recursion covers
108
+ ## nesting (guide: docs/syntax/procedures.adoc).
109
+ procedure = "{" as open 0*( ws / dsc_comment as dsc / comment / object ) as items "}" as close
110
+
111
+ ## Dictionary: "<< objects >>" (guide: docs/syntax/dictionaries.adoc).
112
+ ## Keys and values are objects; pairing is semantic (the interpreter
113
+ ## stack), not syntactic.
114
+ dictionary = "<<" as open 0*( ws / dsc_comment as dsc / comment / object ) as items ">>" as close
115
+
116
+ ## ------------------------------------------------------------------
117
+ ## Operator vocabulary
118
+ ## ------------------------------------------------------------------
119
+ ## Operators are executable names -- the vocabulary is REGISTRY
120
+ ## metadata (Model::Operators), gated per Level 1/2/3 by profile
121
+ ## validation after parsing (design decision: claricle/postscript#4).
122
+ ## The guide's docs/commands/** categories enumerate the vocabulary.
123
+
124
+ ## ------------------------------------------------------------------
125
+ ## Smoke tests (full-input consumption enforced by the entry rule)
126
+ ## ------------------------------------------------------------------
127
+ entry main: program
128
+
129
+ test main {
130
+ accept "10 20 moveto (hi) show"
131
+ accept "(nested (deep (deeper)) here) print"
132
+ accept "/proc { 1 2 add } bind def"
133
+ accept "[1 2 (three) /Four [5 6]] aload"
134
+ accept "<</PageSize[612 792]>> setpagedevice"
135
+ accept "<4f 4b> print"
136
+ accept "16#FF setgray"
137
+ accept "-.002 6.02E23 scale"
138
+ accept "%%BeginSetup"
139
+ accept "123abc print"
140
+ reject "{ unclosed"
141
+ reject "(unterminated"
142
+ reject "<hex"
143
+ reject "[1 2"
144
+ # Each token is captured under its rule's name (the first capture
145
+ # of each name is checked).
146
+ capture "10 20 moveto" { integer: "10" name: "moveto" }
147
+ capture "-.002 6.02E23 scale" { real: "-.002" }
148
+ capture "16#FF setgray" { radix: "16#FF" }
149
+ capture "123abc print" { name: "123abc" }
150
+ capture "(a (b) c) show" { string: "(a (b) c)" }
151
+ capture "<4f 4b> print" { hex_string: "<4f 4b>" }
152
+ capture "/proc { 1 2 add } def" { literal_name: "/proc" }
153
+ capture "%%BeginSetup\n1 pop" { dsc: "%%BeginSetup" }
154
+ capture "[1 2]" { open: "[" close: "]" }
155
+ capture "<< /A 1 >>" { open: "<<" close: ">>" }
156
+ capture "{ %%Page: 1\n }" { dsc: "%%Page: 1" }
157
+ capture "%%A\rB\n1" { dsc: "%%A\rB" }
158
+ capture "\\Name" { literal_name: "\\Name" }
159
+ capture "// x" { literal_name: "/" }
160
+ }
161
+ }
@@ -0,0 +1,7 @@
1
+ # The vendored grammar and artifact are copies of these files at this
2
+ # commit. script/check_grammar.rb fails if they differ.
3
+ repository: claricle/postscript-parg
4
+ commit: c017fb65bfd342fc08596a13ce9c53355e6cb9d7
5
+ files:
6
+ - postscript.parg
7
+ - postscript.json
@@ -18,18 +18,14 @@ module Postscript
18
18
  DESC
19
19
  def parse(input_path)
20
20
  source = read_input(input_path)
21
- program = Postscript.parse(source)
22
- say "Program: #{program.body.length} statement(s)"
23
- say "BoundingBox: #{program.header.bounding_box.inspect}" if program.header.bounding_box
24
- program.body.each do |node|
25
- say " #{node.class}"
26
- end
21
+ describe_program(Postscript.parse(source))
27
22
  rescue Postscript::Error => e
28
23
  say "Parse error: #{e.message}", :red
29
24
  exit 1
30
25
  end
31
26
 
32
- desc "serialize INPUT [OUTPUT]", "Round-trip a PS file through parse + serialize"
27
+ desc "serialize INPUT [OUTPUT]",
28
+ "Round-trip a PS file through parse + serialize"
33
29
  long_desc <<~DESC
34
30
  Read INPUT, parse to a Model::Program, serialize back to PS
35
31
  source. Writes to OUTPUT if given, otherwise stdout.
@@ -58,7 +54,8 @@ module Postscript
58
54
  def tokenize(input_path)
59
55
  source = read_input(input_path)
60
56
  Postscript.tokenize(source).each do |token|
61
- puts "%4d:%-4d %-12s %s" % [token.line, token.column, token.type, token.value]
57
+ puts "%4d:%-4d %-12s %s" % [token.line, token.column, token.type,
58
+ token.value]
62
59
  end
63
60
  rescue Postscript::Error => e
64
61
  say "Lex error: #{e.message}", :red
@@ -72,6 +69,13 @@ module Postscript
72
69
 
73
70
  private
74
71
 
72
+ def describe_program(program)
73
+ say "Program: #{program.body.length} statement(s)"
74
+ bounding_box = program.header.bounding_box
75
+ say "BoundingBox: #{bounding_box.inspect}" if bounding_box
76
+ program.body.each { |node| say " #{node.class}" }
77
+ end
78
+
75
79
  def read_input(path)
76
80
  unless File.exist?(path)
77
81
  say "Error: input file '#{path}' not found", :red
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Postscript
4
+ # A grammar, language-level, or unknown-name finding. Severity is
5
+ # :error or :warning; source locations and vocabulary entry may be nil.
6
+ Diagnostic = Struct.new(:code, :kind, :severity, :message, :offset,
7
+ :line, :column, :rule, :expected, :entry,
8
+ keyword_init: true) do
9
+ def initialize(expected: [], **attributes)
10
+ super(**attributes, expected: expected.dup.freeze)
11
+ freeze
12
+ end
13
+ end
14
+ end
@@ -22,6 +22,10 @@ module Postscript
22
22
  # missing operands, malformed literal).
23
23
  class SyntaxError < ParseError; end
24
24
 
25
+ # engine: :native was asked for, but parsanol (>= 1.3.96, with its
26
+ # native extension) is not available.
27
+ class NativeEngineUnavailable < Error; end
28
+
25
29
  # PS -> SVG / serializer execution failed.
26
30
  class RenderError < Error
27
31
  attr_reader :operator_name
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lens_core"
4
+ require "postscript/model/vocabulary"
5
+ require "postscript/version"
6
+
7
+ module Postscript
8
+ # Explicitly require this optional integration when LensCore is available.
9
+ module LensCitations
10
+ PLRM_URI = "https://www.adobe.com/products/postscript/pdfs/PLRM.pdf"
11
+ # Guide page titles are operator keywords, but filenames can differ.
12
+ GUIDE_SLUGS = { "index" => "psindex" }.freeze
13
+
14
+ class << self
15
+ def profile(level)
16
+ unless level.is_a?(Integer) && (1..3).cover?(level)
17
+ raise ArgumentError, "level must be 1, 2 or 3, got #{level.inspect}"
18
+ end
19
+
20
+ citation = LensCore::Citation.new(
21
+ uri: PLRM_URI, label: "PLRM 3rd ed.: LanguageLevel #{level}",
22
+ )
23
+ [citation].freeze
24
+ end
25
+
26
+ def entry(vocabulary_entry)
27
+ guide = vocabulary_entry.source == :guide
28
+ uri = guide ? guide_uri(vocabulary_entry.keyword) : override_uri
29
+ title = if guide
30
+ "PostScript Language Guide"
31
+ else
32
+ override_reason(vocabulary_entry.keyword)
33
+ end
34
+ LensCore::Citation.new(
35
+ uri: uri,
36
+ label: "#{title}: #{vocabulary_entry.keyword}, " \
37
+ "LanguageLevel #{vocabulary_entry.level}",
38
+ )
39
+ end
40
+
41
+ private
42
+
43
+ def override_uri
44
+ "https://github.com/claricle/postscript/blob/" \
45
+ "v#{VERSION}/data/operator_overrides.yml"
46
+ end
47
+
48
+ def override_reason(keyword)
49
+ File.open(Model::Vocabulary::OVERRIDES) do |file|
50
+ YAML.safe_load(file).fetch("operators").fetch(keyword).fetch("reason")
51
+ end
52
+ end
53
+
54
+ def guide_uri(keyword)
55
+ metadata = File.open(Model::Vocabulary::GUIDE) do |file|
56
+ YAML.safe_load(file).fetch("guide")
57
+ end
58
+ slug = GUIDE_SLUGS.fetch(keyword, keyword)
59
+ "https://github.com/#{metadata.fetch('repository')}/blob/" \
60
+ "#{metadata.fetch('commit')}/docs/commands/references/#{slug}.adoc"
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "lens_core"
5
+ rescue LoadError => e
6
+ raise Postscript::Error,
7
+ "Postscript.validate requires lens_core and Ruby >= 3.1: #{e.message}"
8
+ end
9
+
10
+ require "postscript/lens_citations"
11
+
12
+ module Postscript
13
+ # Adapts the internal validation findings to LensCore diagnostics v1.
14
+ module LensReport
15
+ REQUIREMENTS = {
16
+ grammar: "postscript.grammar.syntax",
17
+ level: "postscript.level.operator-available",
18
+ unknown_name: "postscript.vocabulary.known-name",
19
+ }.freeze
20
+
21
+ class << self
22
+ def call(validation_report, level:, engine:, timestamp: nil)
23
+ citations = LensCitations.profile(level)
24
+ LensCore::Report.new(
25
+ producer: LensCore::Producer.new(name: "postscript",
26
+ version: VERSION),
27
+ profile: LensCore::Profile.new(id: "postscript-level-#{level}",
28
+ citations: citations),
29
+ valid: validation_report.ok?, timestamp: timestamp,
30
+ diagnostics: validation_report.diagnostics.map do |diagnostic|
31
+ convert(diagnostic, level, engine, citations)
32
+ end
33
+ )
34
+ end
35
+
36
+ private
37
+
38
+ def convert(diagnostic, level, engine, profile_citations)
39
+ LensCore::Diagnostic.new(
40
+ severity: diagnostic.severity.to_s,
41
+ kind: diagnostic.kind.to_s.tr("_", "-"),
42
+ requirement_id: REQUIREMENTS.fetch(diagnostic.kind),
43
+ message: utf8(diagnostic.message),
44
+ citations: citations(diagnostic, profile_citations),
45
+ remediation: remediation(diagnostic),
46
+ context: json_value(context(diagnostic, level, engine)),
47
+ )
48
+ end
49
+
50
+ def citations(diagnostic, profile_citations)
51
+ case diagnostic.kind
52
+ when :grammar then profile_citations
53
+ when :level then [LensCitations.entry(diagnostic.entry)]
54
+ else []
55
+ end
56
+ end
57
+
58
+ def remediation(diagnostic)
59
+ return unless diagnostic.kind == :level
60
+
61
+ "declare %%LanguageLevel: #{diagnostic.entry.level} " \
62
+ "or remove #{diagnostic.entry.keyword}"
63
+ end
64
+
65
+ def context(diagnostic, level, engine)
66
+ case diagnostic.kind
67
+ when :grammar
68
+ { line: diagnostic.line, column: diagnostic.column,
69
+ offset: diagnostic.offset, rule: diagnostic.rule,
70
+ expected: diagnostic.expected, engine: engine }
71
+ when :level
72
+ { "keyword" => diagnostic.entry.keyword,
73
+ "required_level" => diagnostic.entry.level,
74
+ "target_level" => level }
75
+ when :unknown_name
76
+ # The internal Diagnostic has no keyword field; Vocabulary's name
77
+ # is carried verbatim after this prefix by Validator.
78
+ { "keyword" => diagnostic.message.delete_prefix("Unknown name: ") }
79
+ end
80
+ end
81
+
82
+ def json_value(value)
83
+ case value
84
+ when String, Symbol then utf8(value.to_s)
85
+ when Array then value.map { |item| json_value(item) }
86
+ when Hash
87
+ value.to_h { |key, item| [utf8(key.to_s), json_value(item)] }
88
+ else value
89
+ end
90
+ end
91
+
92
+ # Lexers preserve source bytes in binary strings. LensCore requires
93
+ # UTF-8 text; retain valid sequences and replace invalid ones for display.
94
+ def utf8(value)
95
+ value.dup.force_encoding(Encoding::UTF_8).scrub
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Postscript
4
+ # An operator keyword and the PostScript language level it needs.
5
+ LevelViolation = Struct.new(:keyword, :level, keyword_init: true)
6
+ end
@@ -22,13 +22,19 @@ module Postscript
22
22
  # Called at the bottom of each subclass definition.
23
23
  def register_as(keyword, consumes: 0, produces: 0)
24
24
  Operators.register(keyword, self)
25
+ @registered_keyword = keyword
25
26
  define_method(:keyword) { keyword }
26
27
  define_method(:visit_name) { keyword }
27
28
  @consumes = consumes
28
29
  @produces = produces
29
30
  end
30
31
 
31
- attr_reader :consumes, :produces
32
+ attr_reader :consumes, :produces, :registered_keyword
33
+
34
+ # Language level from the vocabulary, or nil if unregistered.
35
+ def language_level
36
+ registered_keyword && Vocabulary.level(registered_keyword)
37
+ end
32
38
 
33
39
  # Default: a no-op factory that pops nothing. Subclasses
34
40
  # override to consume operands off the parse stack.
@@ -42,6 +48,11 @@ module Postscript
42
48
  end
43
49
 
44
50
  def operator? = true
51
+
52
+ # Language level from the vocabulary for this operator's keyword.
53
+ def language_level
54
+ Vocabulary.level(keyword)
55
+ end
45
56
  end
46
57
 
47
58
  # Sentinel value the parser pushes onto the operand stack when an
@@ -84,6 +84,9 @@ module Postscript
84
84
  def visit_name = "invoke_procedure"
85
85
 
86
86
  def keyword = name.to_s
87
+
88
+ # User-defined procedures have no language level.
89
+ def language_level = nil
87
90
  end
88
91
  end
89
92
  end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Postscript
6
+ module Model
7
+ # The PostScript operator vocabulary. data/guide_operators.yml is
8
+ # generated from the PostScript Language Guide; data/operator_overrides.yml
9
+ # supplies levels and categories the Guide lacks, each with a reason.
10
+ # Per operator, an override's fields replace the Guide's, and operators
11
+ # listed only in the overrides are included.
12
+ module Vocabulary
13
+ GUIDE = File.expand_path("../../../data/guide_operators.yml", __dir__)
14
+ OVERRIDES = File.expand_path("../../../data/operator_overrides.yml",
15
+ __dir__)
16
+
17
+ Entry = Struct.new(:keyword, :categories, :level, :source,
18
+ keyword_init: true)
19
+
20
+ class << self
21
+ def entry(keyword)
22
+ entries[keyword]
23
+ end
24
+
25
+ def level(keyword)
26
+ entry(keyword)&.level
27
+ end
28
+
29
+ def keywords
30
+ @keywords ||= entries.keys.sort.freeze
31
+ end
32
+
33
+ private
34
+
35
+ def entries
36
+ @entries ||= load_entries
37
+ end
38
+
39
+ def load_entries
40
+ guide = operators(GUIDE)
41
+ overrides = operators(OVERRIDES)
42
+ merged = guide.merge(overrides) do |_keyword, original, override|
43
+ original.merge(override)
44
+ end
45
+ merged.each_with_object({}) do |(keyword, fields), result|
46
+ source = overrides.key?(keyword) ? :override : :guide
47
+ result[keyword] = build_entry(keyword, fields, source)
48
+ end.freeze
49
+ end
50
+
51
+ # Not YAML.safe_load_file: it needs Psych 3.3.2, and Ruby 3.0
52
+ # ships Psych 3.3.0.
53
+ def operators(path)
54
+ File.open(path) { |file| YAML.safe_load(file) }.fetch("operators")
55
+ end
56
+
57
+ def build_entry(keyword, fields, source)
58
+ Entry.new(
59
+ keyword: keyword.freeze,
60
+ categories: Array(fields["categories"]).map(&:freeze).freeze,
61
+ level: fields["level"],
62
+ source: source,
63
+ ).freeze
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -6,12 +6,13 @@ module Postscript
6
6
  # the parser emits Model::Program; the renderer / serializer consume
7
7
  # Model::Program.
8
8
  module Model
9
+ autoload :Vocabulary, "postscript/model/vocabulary"
9
10
  autoload :Token, "postscript/model/token"
10
11
  autoload :Program, "postscript/model/program"
11
12
  autoload :Literals, "postscript/model/literals"
12
13
  autoload :Operator, "postscript/model/operator"
13
- autoload :UnknownOperator, "postscript/model/operator"
14
- autoload :InvokeProcedure, "postscript/model/operator"
14
+ autoload :UnknownOperator, "postscript/model/operators"
15
+ autoload :InvokeProcedure, "postscript/model/operators"
15
16
  autoload :Operators, "postscript/model/operators"
16
17
  end
17
18
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Postscript
4
+ module Validation
5
+ # An immutable collection of validation findings in source order.
6
+ class Report
7
+ attr_reader :diagnostics
8
+
9
+ def initialize(diagnostics: [])
10
+ @diagnostics = diagnostics.dup.freeze
11
+ freeze
12
+ end
13
+
14
+ def ok?
15
+ diagnostics.none? { |diagnostic| diagnostic.severity == :error }
16
+ end
17
+
18
+ def errors
19
+ diagnostics.select { |diagnostic| diagnostic.severity == :error }
20
+ end
21
+
22
+ def warnings
23
+ diagnostics.select { |diagnostic| diagnostic.severity == :warning }
24
+ end
25
+
26
+ def to_h
27
+ { diagnostics: diagnostics.map(&:to_h) }
28
+ end
29
+ end
30
+ end
31
+ end