postscript 0.2.0 → 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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +0 -6
  3. data/Gemfile +11 -0
  4. data/README.adoc +201 -0
  5. data/data/guide_operators.yml +667 -0
  6. data/data/operator_overrides.yml +163 -0
  7. data/docs/operators.adoc +205 -0
  8. data/docs/plans/issue-4-native-parser.md +162 -0
  9. data/grammars/README.md +22 -0
  10. data/grammars/postscript.json +1 -0
  11. data/grammars/postscript.parg +161 -0
  12. data/grammars/upstream.yml +7 -0
  13. data/lib/postscript/cli.rb +12 -8
  14. data/lib/postscript/diagnostic.rb +14 -0
  15. data/lib/postscript/errors.rb +4 -0
  16. data/lib/postscript/lens_citations.rb +64 -0
  17. data/lib/postscript/lens_report.rb +99 -0
  18. data/lib/postscript/level_violation.rb +6 -0
  19. data/lib/postscript/model/operator.rb +12 -1
  20. data/lib/postscript/model/operators/color.rb +8 -0
  21. data/lib/postscript/model/operators/graphics_state.rb +4 -0
  22. data/lib/postscript/model/operators/path.rb +28 -0
  23. data/lib/postscript/model/operators/transformations.rb +12 -0
  24. data/lib/postscript/model/operators.rb +3 -0
  25. data/lib/postscript/model/vocabulary.rb +68 -0
  26. data/lib/postscript/model.rb +3 -2
  27. data/lib/postscript/report.rb +31 -0
  28. data/lib/postscript/serializer.rb +50 -7
  29. data/lib/postscript/source/ast_builder.rb +17 -22
  30. data/lib/postscript/source/lexer.rb +126 -57
  31. data/lib/postscript/source/native_engine.rb +125 -0
  32. data/lib/postscript/source/native_lexer.rb +185 -0
  33. data/lib/postscript/source.rb +22 -2
  34. data/lib/postscript/validation/grammar.rb +51 -0
  35. data/lib/postscript/validation/levels.rb +76 -0
  36. data/lib/postscript/validation/vocabulary.rb +42 -0
  37. data/lib/postscript/validation.rb +10 -0
  38. data/lib/postscript/validator.rb +59 -0
  39. data/lib/postscript/version.rb +1 -1
  40. data/lib/postscript.rb +34 -4
  41. metadata +23 -2
@@ -0,0 +1,163 @@
1
+ # Levels and categories the Guide does not give. Every entry has a reason.
2
+ operators:
3
+ and:
4
+ categories: [relational-boolean]
5
+ level: 1
6
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
7
+ ashow:
8
+ level: 1
9
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
10
+ awidthshow:
11
+ level: 1
12
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
13
+ charpath:
14
+ level: 1
15
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
16
+ copypage:
17
+ categories: [device-output]
18
+ level: 1
19
+ reason: "No Guide page; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
20
+ currentfont:
21
+ level: 1
22
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
23
+ currentglobal:
24
+ level: 2
25
+ reason: "Named only on level-2.adoc; no Guide category for VM operators; PLRM 3rd ed.: LanguageLevel 2; Guide gap: claricle/postscript-guide#11"
26
+ currentpagedevice:
27
+ categories: [device-output]
28
+ level: 2
29
+ reason: "Named only on level-2.adoc; PLRM 3rd ed.: LanguageLevel 2; Guide gap: claricle/postscript-guide#11"
30
+ definefont:
31
+ level: 1
32
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
33
+ eq:
34
+ categories: [relational-boolean]
35
+ level: 1
36
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
37
+ "false":
38
+ categories: [relational-boolean]
39
+ level: 1
40
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
41
+ filter:
42
+ categories: [file-io]
43
+ level: 2
44
+ reason: "Named only on level-2.adoc; PLRM 3rd ed.: LanguageLevel 2; Guide gap: claricle/postscript-guide#11"
45
+ findfont:
46
+ level: 1
47
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
48
+ ge:
49
+ categories: [relational-boolean]
50
+ level: 1
51
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
52
+ gt:
53
+ categories: [relational-boolean]
54
+ level: 1
55
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
56
+ kshow:
57
+ level: 1
58
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
59
+ le:
60
+ categories: [relational-boolean]
61
+ level: 1
62
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
63
+ lt:
64
+ categories: [relational-boolean]
65
+ level: 1
66
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
67
+ makefont:
68
+ level: 1
69
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
70
+ makepattern:
71
+ categories: [color]
72
+ level: 2
73
+ reason: "Named only on level-2.adoc; PLRM 3rd ed.: LanguageLevel 2; Guide gap: claricle/postscript-guide#11"
74
+ ne:
75
+ categories: [relational-boolean]
76
+ level: 1
77
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
78
+ not:
79
+ categories: [relational-boolean]
80
+ level: 1
81
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
82
+ nulldevice:
83
+ categories: [device-output]
84
+ level: 1
85
+ reason: "No Guide page; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
86
+ or:
87
+ categories: [relational-boolean]
88
+ level: 1
89
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
90
+ scalefont:
91
+ level: 1
92
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
93
+ setblackgeneration:
94
+ categories: [color]
95
+ level: 2
96
+ reason: "Named only on level-3.adoc, which lists it; PLRM 3rd ed.: LanguageLevel 2 (Level 1 CMYK color extension); Guide gaps: claricle/postscript-guide#11, claricle/postscript-guide#10"
97
+ setcolor:
98
+ categories: [color]
99
+ level: 2
100
+ reason: "Named only on level-2.adoc; PLRM 3rd ed.: LanguageLevel 2; Guide gap: claricle/postscript-guide#11"
101
+ setcolorspace:
102
+ categories: [color]
103
+ level: 2
104
+ reason: "Named only on level-2.adoc; PLRM 3rd ed.: LanguageLevel 2; Guide gap: claricle/postscript-guide#11"
105
+ setfont:
106
+ level: 1
107
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
108
+ setglobal:
109
+ level: 2
110
+ reason: "Named only on level-2.adoc; no Guide category for VM operators; PLRM 3rd ed.: LanguageLevel 2; Guide gap: claricle/postscript-guide#11"
111
+ sethalftone:
112
+ categories: [graphics-state]
113
+ level: 2
114
+ reason: "Named only on level-3.adoc, which lists it; PLRM 3rd ed.: LanguageLevel 2; Guide gaps: claricle/postscript-guide#11, claricle/postscript-guide#10"
115
+ setpacking:
116
+ categories: [array-string]
117
+ level: 2
118
+ reason: "Named only on level-2.adoc; PLRM 3rd ed.: LanguageLevel 2 (Level 1 version 25.0 extension); Guide gap: claricle/postscript-guide#11"
119
+ setpagedevice:
120
+ categories: [device-output]
121
+ level: 2
122
+ reason: "Named only on level-2.adoc; PLRM 3rd ed.: LanguageLevel 2; Guide gap: claricle/postscript-guide#11"
123
+ setpattern:
124
+ categories: [color]
125
+ level: 2
126
+ reason: "Named only on level-2.adoc; PLRM 3rd ed.: LanguageLevel 2; Guide gap: claricle/postscript-guide#11"
127
+ setsmoothness:
128
+ categories: [graphics-state]
129
+ level: 3
130
+ reason: "Named only on level-3.adoc; PLRM 3rd ed.: LanguageLevel 3; Guide gap: claricle/postscript-guide#11"
131
+ setundercolorremoval:
132
+ categories: [color]
133
+ level: 2
134
+ reason: "Named only on level-3.adoc, which lists it; PLRM 3rd ed.: LanguageLevel 2 (Level 1 CMYK color extension); Guide gaps: claricle/postscript-guide#11, claricle/postscript-guide#10"
135
+ shfill:
136
+ categories: [painting]
137
+ level: 3
138
+ reason: "Named only on level-3.adoc; PLRM 3rd ed.: LanguageLevel 3; Guide gap: claricle/postscript-guide#11"
139
+ show:
140
+ level: 1
141
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
142
+ showpage:
143
+ categories: [device-output]
144
+ level: 1
145
+ reason: "No Guide page; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
146
+ stringwidth:
147
+ level: 1
148
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
149
+ "true":
150
+ categories: [relational-boolean]
151
+ level: 1
152
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
153
+ widthshow:
154
+ level: 1
155
+ reason: "Guide page states no level; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#8"
156
+ xor:
157
+ categories: [relational-boolean]
158
+ level: 1
159
+ reason: "No Guide page and no Guide category for relational/boolean operators; PLRM 3rd ed.: LanguageLevel 1; Guide gap: claricle/postscript-guide#9"
160
+ xyshow:
161
+ categories: [font-text]
162
+ level: 2
163
+ reason: "No Guide page; PLRM 3rd ed.: LanguageLevel 2; Guide gap: claricle/postscript-guide#9"
@@ -0,0 +1,205 @@
1
+ = PostScript operator inventory
2
+
3
+ This page is generated; do not edit. Regenerate with `bundle exec rake vocabulary:doc`. It is built from `data/guide_operators.yml` (PostScript Language Guide) and `data/operator_overrides.yml`, and lists each operator with the gem class that models it or `UnknownOperator` when no class is registered (the parser then yields `Postscript::Model::UnknownOperator`).
4
+
5
+ [cols="2,3,1,1,5",options="header"]
6
+ |===
7
+ |Operator |Categories |Level |Source |Gem class
8
+
9
+ |`+abs+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Abs`
10
+ |`+add+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Add`
11
+ |`+aload+` |array-string |1 |guide |`UnknownOperator`
12
+ |`+anchorsearch+` |array-string |1 |guide |`Postscript::Model::Operators::Container::Anchorsearch`
13
+ |`+and+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::And`
14
+ |`+arc+` |path-construction |1 |guide |`Postscript::Model::Operators::Path::Arc`
15
+ |`+arcn+` |path-construction |1 |guide |`Postscript::Model::Operators::Path::Arcn`
16
+ |`+arct+` |path-construction |2 |guide |`UnknownOperator`
17
+ |`+arcto+` |path-construction |1 |guide |`UnknownOperator`
18
+ |`+array+` |array-string |1 |guide |`UnknownOperator`
19
+ |`+ashow+` |font-text |1 |override |`UnknownOperator`
20
+ |`+astore+` |array-string |1 |guide |`Postscript::Model::Operators::Container::Astore`
21
+ |`+atan+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Atan`
22
+ |`+awidthshow+` |font-text |1 |override |`UnknownOperator`
23
+ |`+begin+` |dictionary, graphics-state |1 |guide |`Postscript::Model::Operators::Dictionary::Begin`
24
+ |`+bitshift+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Boolean::Bitshift`
25
+ |`+ceiling+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Ceiling`
26
+ |`+charpath+` |font-text |1 |override |`Postscript::Model::Operators::Font::Charpath`
27
+ |`+clear+` |stack-manipulation |1 |guide |`Postscript::Model::Operators::Stack::Clear`
28
+ |`+cleartomark+` |stack-manipulation |1 |guide |`UnknownOperator`
29
+ |`+clip+` |painting |1 |guide |`Postscript::Model::Operators::Painting::Clip`
30
+ |`+clippath+` |painting |1 |guide |`UnknownOperator`
31
+ |`+closepath+` |path-construction |1 |guide |`Postscript::Model::Operators::Path::Closepath`
32
+ |`+concat+` |transformations |1 |guide |`Postscript::Model::Operators::Transformations::Concat`
33
+ |`+concatmatrix+` |transformations |1 |guide |`UnknownOperator`
34
+ |`+copy+` |stack-manipulation |1 |guide |`UnknownOperator`
35
+ |`+copypage+` |device-output |1 |override |`Postscript::Model::Operators::Device::Copypage`
36
+ |`+cos+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Cos`
37
+ |`+count+` |stack-manipulation |1 |guide |`Postscript::Model::Operators::Stack::Count`
38
+ |`+countdictstack+` |dictionary |1 |guide |`Postscript::Model::Operators::Dictionary::Countdictstack`
39
+ |`+counttomark+` |stack-manipulation |1 |guide |`UnknownOperator`
40
+ |`+cshow+` |font-text |2 |guide |`UnknownOperator`
41
+ |`+currentcmykcolor+` |graphics-state |2 |guide |`UnknownOperator`
42
+ |`+currentdash+` |graphics-state |1 |guide |`UnknownOperator`
43
+ |`+currentdict+` |dictionary |1 |guide |`Postscript::Model::Operators::Dictionary::Currentdict`
44
+ |`+currentfont+` |font-text |1 |override |`UnknownOperator`
45
+ |`+currentglobal+` |- |2 |override |`UnknownOperator`
46
+ |`+currentgray+` |graphics-state |1 |guide |`UnknownOperator`
47
+ |`+currentgstate+` |graphics-state |2 |guide |`UnknownOperator`
48
+ |`+currenthsbcolor+` |graphics-state |1 |guide |`UnknownOperator`
49
+ |`+currentlinecap+` |graphics-state |1 |guide |`UnknownOperator`
50
+ |`+currentlinejoin+` |graphics-state |1 |guide |`UnknownOperator`
51
+ |`+currentlinewidth+` |graphics-state |1 |guide |`UnknownOperator`
52
+ |`+currentmatrix+` |transformations |1 |guide |`Postscript::Model::Operators::Transformations::Currentmatrix`
53
+ |`+currentmiterlimit+` |graphics-state |1 |guide |`UnknownOperator`
54
+ |`+currentpagedevice+` |device-output |2 |override |`UnknownOperator`
55
+ |`+currentpoint+` |path-construction |1 |guide |`Postscript::Model::Operators::Path::Currentpoint`
56
+ |`+currentrgbcolor+` |graphics-state |1 |guide |`UnknownOperator`
57
+ |`+curveto+` |path-construction |1 |guide |`Postscript::Model::Operators::Path::Curveto`
58
+ |`+cvi+` |array-string |1 |guide |`UnknownOperator`
59
+ |`+cvlit+` |array-string |1 |guide |`UnknownOperator`
60
+ |`+cvn+` |array-string |1 |guide |`UnknownOperator`
61
+ |`+cvr+` |array-string |1 |guide |`UnknownOperator`
62
+ |`+cvs+` |array-string |1 |guide |`Postscript::Model::Operators::Container::Cvs`
63
+ |`+cvx+` |array-string, control-flow |1 |guide |`UnknownOperator`
64
+ |`+def+` |dictionary |1 |guide |`Postscript::Model::Operators::Dictionary::Def`
65
+ |`+defaultmatrix+` |transformations |1 |guide |`UnknownOperator`
66
+ |`+definefont+` |font-text |1 |override |`UnknownOperator`
67
+ |`+dict+` |dictionary |1 |guide |`Postscript::Model::Operators::Dictionary::Dict`
68
+ |`+dictstack+` |dictionary |1 |guide |`Postscript::Model::Operators::Dictionary::Dictstack`
69
+ |`+div+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Div`
70
+ |`+dtransform+` |transformations |1 |guide |`Postscript::Model::Operators::Transformations::Dtransform`
71
+ |`+dup+` |stack-manipulation |1 |guide |`Postscript::Model::Operators::Stack::Dup`
72
+ |`+end+` |dictionary |1 |guide |`Postscript::Model::Operators::Dictionary::End`
73
+ |`+eoclip+` |painting |1 |guide |`Postscript::Model::Operators::Painting::Eoclip`
74
+ |`+eofill+` |painting |1 |guide |`Postscript::Model::Operators::Painting::Eofill`
75
+ |`+eq+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::Eq`
76
+ |`+exch+` |stack-manipulation |1 |guide |`Postscript::Model::Operators::Stack::Exch`
77
+ |`+exec+` |control-flow |1 |guide |`Postscript::Model::Operators::ControlFlow::Exec`
78
+ |`+exit+` |control-flow |1 |guide |`Postscript::Model::Operators::ControlFlow::Exit`
79
+ |`+exp+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Exp`
80
+ |`+false+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::False`
81
+ |`+fill+` |painting |1 |guide |`Postscript::Model::Operators::Painting::Fill`
82
+ |`+filter+` |file-io |2 |override |`UnknownOperator`
83
+ |`+findfont+` |font-text |1 |override |`Postscript::Model::Operators::Font::Findfont`
84
+ |`+floor+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Floor`
85
+ |`+for+` |control-flow |1 |guide |`Postscript::Model::Operators::ControlFlow::For`
86
+ |`+forall+` |array-string, control-flow, dictionary |1 |guide |`Postscript::Model::Operators::Container::Forall`
87
+ |`+ge+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::Ge`
88
+ |`+get+` |array-string, dictionary |1 |guide |`Postscript::Model::Operators::Container::Get`
89
+ |`+getinterval+` |array-string |1 |guide |`Postscript::Model::Operators::Container::Getinterval`
90
+ |`+grestore+` |graphics-state, transformations |1 |guide |`Postscript::Model::Operators::GraphicsState::Grestore`
91
+ |`+grestoreall+` |graphics-state |1 |guide |`Postscript::Model::Operators::GraphicsState::Grestoreall`
92
+ |`+gsave+` |graphics-state, transformations |1 |guide |`Postscript::Model::Operators::GraphicsState::Gsave`
93
+ |`+gstate+` |graphics-state |2 |guide |`UnknownOperator`
94
+ |`+gt+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::Gt`
95
+ |`+identmatrix+` |transformations |1 |guide |`UnknownOperator`
96
+ |`+idiv+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Idiv`
97
+ |`+idtransform+` |transformations |1 |guide |`Postscript::Model::Operators::Transformations::Idtransform`
98
+ |`+if+` |control-flow |1 |guide |`Postscript::Model::Operators::ControlFlow::If`
99
+ |`+ifelse+` |control-flow |1 |guide |`Postscript::Model::Operators::ControlFlow::Ifelse`
100
+ |`+index+` |stack-manipulation |1 |guide |`Postscript::Model::Operators::Stack::Index`
101
+ |`+initmatrix+` |transformations |1 |guide |`UnknownOperator`
102
+ |`+invertmatrix+` |transformations |1 |guide |`UnknownOperator`
103
+ |`+itransform+` |transformations |1 |guide |`Postscript::Model::Operators::Transformations::Itransform`
104
+ |`+known+` |dictionary |1 |guide |`Postscript::Model::Operators::Dictionary::Known`
105
+ |`+kshow+` |font-text |1 |override |`UnknownOperator`
106
+ |`+le+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::Le`
107
+ |`+length+` |array-string, dictionary |1 |guide |`Postscript::Model::Operators::Container::Length`
108
+ |`+lineto+` |path-construction |1 |guide |`Postscript::Model::Operators::Path::Lineto`
109
+ |`+ln+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Ln`
110
+ |`+load+` |dictionary |1 |guide |`Postscript::Model::Operators::Dictionary::Load`
111
+ |`+log+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Log`
112
+ |`+loop+` |control-flow |1 |guide |`Postscript::Model::Operators::ControlFlow::Loop`
113
+ |`+lt+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::Lt`
114
+ |`+makefont+` |font-text |1 |override |`UnknownOperator`
115
+ |`+makepattern+` |color |2 |override |`UnknownOperator`
116
+ |`+mark+` |stack-manipulation |1 |guide |`UnknownOperator`
117
+ |`+matrix+` |transformations |1 |guide |`Postscript::Model::Operators::Transformations::Matrix`
118
+ |`+maxlength+` |dictionary |1 |guide |`Postscript::Model::Operators::Dictionary::Maxlength`
119
+ |`+mod+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Mod`
120
+ |`+moveto+` |path-construction |1 |guide |`Postscript::Model::Operators::Path::Moveto`
121
+ |`+mul+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Mul`
122
+ |`+ne+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::Ne`
123
+ |`+neg+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Neg`
124
+ |`+newpath+` |path-construction |1 |guide |`Postscript::Model::Operators::Path::Newpath`
125
+ |`+not+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::Not`
126
+ |`+nulldevice+` |device-output |1 |override |`Postscript::Model::Operators::Device::Nulldevice`
127
+ |`+or+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::Or`
128
+ |`+packedarray+` |array-string |2 |guide |`UnknownOperator`
129
+ |`+pop+` |stack-manipulation |1 |guide |`Postscript::Model::Operators::Stack::Pop`
130
+ |`+put+` |array-string, dictionary |1 |guide |`Postscript::Model::Operators::Container::Put`
131
+ |`+putinterval+` |array-string |1 |guide |`Postscript::Model::Operators::Container::Putinterval`
132
+ |`+quit+` |control-flow |1 |guide |`Postscript::Model::Operators::ControlFlow::Quit`
133
+ |`+rand+` |arithmetic-math |1 |guide |`UnknownOperator`
134
+ |`+rcheck+` |array-string |1 |guide |`UnknownOperator`
135
+ |`+rcurveto+` |path-construction |1 |guide |`Postscript::Model::Operators::Path::Rcurveto`
136
+ |`+rectclip+` |painting |2 |guide |`UnknownOperator`
137
+ |`+rectfill+` |painting |2 |guide |`UnknownOperator`
138
+ |`+rectstroke+` |painting |2 |guide |`UnknownOperator`
139
+ |`+repeat+` |control-flow |1 |guide |`Postscript::Model::Operators::ControlFlow::Repeat`
140
+ |`+rlineto+` |path-construction |1 |guide |`Postscript::Model::Operators::Path::Rlineto`
141
+ |`+rmoveto+` |path-construction |1 |guide |`Postscript::Model::Operators::Path::Rmoveto`
142
+ |`+roll+` |stack-manipulation |1 |guide |`Postscript::Model::Operators::Stack::Roll`
143
+ |`+rotate+` |transformations |1 |guide |`Postscript::Model::Operators::Transformations::Rotate`
144
+ |`+round+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Round`
145
+ |`+rrand+` |arithmetic-math |1 |guide |`UnknownOperator`
146
+ |`+scale+` |transformations |1 |guide |`Postscript::Model::Operators::Transformations::Scale`
147
+ |`+scalefont+` |font-text |1 |override |`Postscript::Model::Operators::Font::Scalefont`
148
+ |`+search+` |array-string |1 |guide |`Postscript::Model::Operators::Container::Search`
149
+ |`+setblackgeneration+` |color |2 |override |`UnknownOperator`
150
+ |`+setcmykcolor+` |graphics-state |2 |guide |`Postscript::Model::Operators::Color::Setcmykcolor`
151
+ |`+setcolor+` |color |2 |override |`UnknownOperator`
152
+ |`+setcolorspace+` |color |2 |override |`UnknownOperator`
153
+ |`+setdash+` |graphics-state |1 |guide |`Postscript::Model::Operators::GraphicsState::Setdash`
154
+ |`+setfont+` |font-text |1 |override |`Postscript::Model::Operators::Font::Setfont`
155
+ |`+setglobal+` |- |2 |override |`UnknownOperator`
156
+ |`+setgray+` |graphics-state |1 |guide |`Postscript::Model::Operators::Color::Setgray`
157
+ |`+setgstate+` |graphics-state |2 |guide |`UnknownOperator`
158
+ |`+sethalftone+` |graphics-state |2 |override |`UnknownOperator`
159
+ |`+sethsbcolor+` |graphics-state |1 |guide |`Postscript::Model::Operators::Color::Sethsbcolor`
160
+ |`+setlinecap+` |graphics-state |1 |guide |`Postscript::Model::Operators::GraphicsState::Setlinecap`
161
+ |`+setlinejoin+` |graphics-state |1 |guide |`Postscript::Model::Operators::GraphicsState::Setlinejoin`
162
+ |`+setlinewidth+` |graphics-state |1 |guide |`Postscript::Model::Operators::GraphicsState::Setlinewidth`
163
+ |`+setmatrix+` |transformations |1 |guide |`Postscript::Model::Operators::Transformations::Setmatrix`
164
+ |`+setmiterlimit+` |graphics-state |1 |guide |`Postscript::Model::Operators::GraphicsState::Setmiterlimit`
165
+ |`+setpacking+` |array-string |2 |override |`UnknownOperator`
166
+ |`+setpagedevice+` |device-output |2 |override |`UnknownOperator`
167
+ |`+setpattern+` |color |2 |override |`UnknownOperator`
168
+ |`+setrgbcolor+` |graphics-state |1 |guide |`Postscript::Model::Operators::Color::Setrgbcolor`
169
+ |`+setsmoothness+` |graphics-state |3 |override |`UnknownOperator`
170
+ |`+setundercolorremoval+` |color |2 |override |`UnknownOperator`
171
+ |`+shfill+` |painting |3 |override |`UnknownOperator`
172
+ |`+show+` |font-text |1 |override |`Postscript::Model::Operators::Font::Show`
173
+ |`+showpage+` |device-output |1 |override |`Postscript::Model::Operators::Device::Showpage`
174
+ |`+sin+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Sin`
175
+ |`+sqrt+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Sqrt`
176
+ |`+srand+` |arithmetic-math |1 |guide |`UnknownOperator`
177
+ |`+stop+` |control-flow |1 |guide |`UnknownOperator`
178
+ |`+stopped+` |control-flow |1 |guide |`Postscript::Model::Operators::ControlFlow::Stopped`
179
+ |`+store+` |dictionary |1 |guide |`Postscript::Model::Operators::Dictionary::Store`
180
+ |`+string+` |array-string |1 |guide |`Postscript::Model::Operators::Container::String`
181
+ |`+stringwidth+` |font-text |1 |override |`Postscript::Model::Operators::Font::Stringwidth`
182
+ |`+stroke+` |painting |1 |guide |`Postscript::Model::Operators::Painting::Stroke`
183
+ |`+strokepath+` |painting |1 |guide |`UnknownOperator`
184
+ |`+sub+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Sub`
185
+ |`+token+` |array-string |1 |guide |`Postscript::Model::Operators::Container::Token`
186
+ |`+transform+` |transformations |1 |guide |`Postscript::Model::Operators::Transformations::Transform`
187
+ |`+translate+` |transformations |1 |guide |`Postscript::Model::Operators::Transformations::Translate`
188
+ |`+true+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::True`
189
+ |`+truncate+` |arithmetic-math |1 |guide |`Postscript::Model::Operators::Arithmetic::Truncate`
190
+ |`+type+` |array-string |1 |guide |`UnknownOperator`
191
+ |`+ueofill+` |painting |2 |guide |`UnknownOperator`
192
+ |`+ufill+` |painting |2 |guide |`UnknownOperator`
193
+ |`+undef+` |dictionary |2 |guide |`UnknownOperator`
194
+ |`+undefinefont+` |font-text |2 |guide |`UnknownOperator`
195
+ |`+ustroke+` |painting |2 |guide |`UnknownOperator`
196
+ |`+ustrokepath+` |painting |2 |guide |`UnknownOperator`
197
+ |`+wcheck+` |array-string |1 |guide |`UnknownOperator`
198
+ |`+where+` |dictionary |1 |guide |`UnknownOperator`
199
+ |`+widthshow+` |font-text |1 |override |`UnknownOperator`
200
+ |`+xcheck+` |array-string |1 |guide |`UnknownOperator`
201
+ |`+xor+` |relational-boolean |1 |override |`Postscript::Model::Operators::Boolean::Xor`
202
+ |`+xyshow+` |font-text |2 |override |`Postscript::Model::Operators::Font::Xyshow`
203
+ |===
204
+
205
+ 194 operators; 120 with a gem class; 74 represented as UnknownOperator. By level: level 1: 161, level 2: 31, level 3: 2.
@@ -0,0 +1,162 @@
1
+ # Issue 4: PARG grammar and native parser
2
+
3
+ Issue: [Extract the PostScript grammar as PARG and port the parser to the parsanol native engine](https://github.com/claricle/postscript/issues/4)
4
+
5
+ ## Outcome and scope
6
+
7
+ Move the source syntax contract from the hand-written lexer into a guide-derived PARG grammar, ship its compiled artifact with this gem, and add an opt-in native tokenization path on the parsanol engine. `Postscript::Source.parse(source)` must continue returning the same typed `Postscript::Model::Program`; the existing Ruby lexer remains the default. The native lexer may become the default only after token-stream parity is established and it is measured faster than the Ruby lexer.
8
+
9
+ The grammar describes syntax, not runtime semantics. It accepts operator names as names. PostScript Language Level support belongs to operator vocabulary metadata and post-parse validation, not duplicate level-specific grammars. Existing Ruby `AstBuilder` behavior, including operator construction through `Model::Operator.from_operands`, remains the AST construction boundary. A guide syntax form omitted from the historical skeleton (such as immediately evaluated `//` names) is an inventory/spec gap to resolve explicitly, not silent scope expansion.
10
+
11
+ This plan covers the grammar and artifact, their packaging and CI checks, opt-in native engine selection, compatibility evidence, Language Guide vocabulary coverage, minimal post-parse level validation, and before/after parse benchmarks. It does not authorize implementation. It does not include interpreter semantics, a broad conformance framework, rendering changes, or replacing the Ruby AST builder.
12
+
13
+ ## Requirement reconciliation
14
+
15
+ | Status | Requirement and evidence |
16
+ |---|---|
17
+ | Confirmed | Preserve the `Postscript::Source.parse` signature and typed `Model::Program`, keep the Ruby fallback, compare the full current suite (the issue cites 149 examples), and record corpus benchmarks. [Issue body](https://github.com/claricle/postscript/issues/4) |
18
+ | Confirmed correction | Use the PostScript Language Guide as the normative syntax and vocabulary contract. Derive rules from its syntax pages and check all command categories and level references. [Issue comment](https://github.com/claricle/postscript/issues/4#issuecomment-6247408519) |
19
+ | Confirmed correction | The canonical grammar and compiled JSON originate in `claricle/postscript-parg`; vendor both into this repository. The PARG framework, embedded tests, and compiled-artifact parity CI are reported as merged upstream. [Issue comment](https://github.com/claricle/postscript/issues/4#issuecomment-6256686705) |
20
+ | Confirmed decision | Keep one level-agnostic grammar/artifact. Represent levels as operator-registry metadata and apply level checks after parsing, preserving tolerant parsing. [Issue comment](https://github.com/claricle/postscript/issues/4#issuecomment-6247605502) |
21
+ | Decided | Native parsing rides the parsanol Rust/Ruby pair, as the original issue says; this gem adds no FFI layer. `claricle/postscript-rs` is out of scope for this issue. |
22
+ | Verified upstream state | The canonical [`postscript-parg` snapshot b2cbfe2](https://github.com/claricle/postscript-parg/commit/b2cbfe2) has no captures, so it returns the whole input as one slice. [postscript-parg#3](https://github.com/claricle/postscript-parg/pull/3) captures every token under its rule name (integer, real, radix, name, string, hex_string, literal_name, array, procedure, dictionary, and top-level DSC comments as dsc), with choice order unchanged. Its CI runs the released parsanol CLI for embedded tests and fresh-compile payload equality. |
23
+ | Verified upstream defect | parsanol-ruby ≤ 1.3.95 (crate ≤ 0.18.8) returns wrong, *successful* parses for inputs of 8 KB or more: the bytecode VM, used from that size, decoded PARG's escaped classes (`[\x61-\x7a]`) wrongly and the bridge accepted a short parse. Fixed in [parsanol-rs#251](https://github.com/parsanol/parsanol-rs/pull/251) (crate 0.18.9) and [parsanol-ruby#242](https://github.com/parsanol/parsanol-ruby/pull/242) (gem 1.3.96, also versions the compiled-program cache). The native path requires `parsanol >= 1.3.96`. `Artifact#parse(entry, input, mode: :native)` falls back to the Ruby atom runtime when `Native.available?` is false, so the adapter must check that itself. parsanol requires Ruby ≥ 3.2; this gem supports ≥ 3.0. |
24
+ | Decided | parsanol is an optional dependency, not in the gemspec. Native tokenization is opt-in through `Source.parse(source, engine: :native)`; that call raises a clear error when parsanol ≥ 1.3.96 or its native extension is unavailable, and never silently runs the Ruby atom runtime. The default stays the Ruby lexer: measured with the fixed engine, native parse plus token conversion is 10–24× slower than `Lexer.tokenize` (5 KB: 86 ms vs 6 ms; 943 KB: 30 s vs 1.2 s). |
25
+ | Decided | Where the grammar and the current lexer disagree, the lexer wins for now: the parity spec requires identical tokens and the grammar is adjusted upstream to match. Each guide difference found (candidates: top-level-only `dsc_comment`, composite rules consuming comments, nonempty literal names, Ruby backslash names, immediately evaluated `//` names, EOF/tolerance behavior, malformed or unbalanced input) is recorded as a follow-up issue, not changed silently. |
26
+
27
+ ## Current implementation
28
+
29
+ `Postscript::Source.parse` in `lib/postscript/source.rb` composes `Lexer.tokenize` and `AstBuilder.build`. `lib/postscript/source/lexer.rb` emits frozen `Model::Token` values with type, value, line, column, and literal-name flag; it handles comments/DSC comments, nested escaped strings, hex strings, names, numeric words, and composite delimiters. `lib/postscript/source/ast_builder.rb` constructs literals, nested composites, DSC header values, registered operator instances, unknown operators, and procedure invocations. `Model::Operator.from_operands` consumes the builder's `OperandStack` and remains Ruby-side. Lexing errors use `Postscript::LexError` with `source_position`; structure errors use `Postscript::SyntaxError`.
30
+
31
+ `grammars/README.md` says the grammar lives upstream and the local grammar skeleton is historical; there is no current local PARG artifact. `README.adoc` presents `Source.parse` as the public source-to-program API. Relevant existing specs are `spec/postscript/source/lexer_spec.rb`, `spec/postscript/source/ast_builder_spec.rb`, `spec/postscript/round_trip_spec.rb`, and the fixture corpus under `spec/fixtures/`.
32
+
33
+ ## Ordered work items
34
+
35
+ ### Upstream ownership and prerequisites
36
+
37
+ | Owner | Repository/evidence | Required contribution or constraint |
38
+ |---|---|---|
39
+ | This repository | `claricle/postscript` | Vendor canonical PARG and JSON, package/CI checks, the opt-in Ruby-side adapter, metadata and validation. |
40
+ | PARG upstream | [`claricle/postscript-parg#3`](https://github.com/claricle/postscript-parg/pull/3) | Token captures. Must be merged before the grammar is vendored. |
41
+ | Engine upstream | [`parsanol-rs#251`](https://github.com/parsanol/parsanol-rs/pull/251) → crate 0.18.9; [`parsanol-ruby#242`](https://github.com/parsanol/parsanol-ruby/pull/242) → gem 1.3.96 | VM correctness for PARG grammars and a versioned program cache. Must be released before the native adapter merges. |
42
+
43
+ Effort is active engineer time in person-hours, including focused investigation and validation; elapsed time waiting on upstream releases or CI is excluded. Work items sum to 12–20 hours; a 20% contingency is 2.4–4.0 hours, for a total of **14.4–24 hours**.
44
+
45
+ ### 1. Confirm the released engine — 1 h
46
+
47
+ The route is decided (parsanol, opt-in). Once parsanol 1.3.96 is released, confirm on it that the captured artifact parses natively (`Native.available?` true) on the CI platforms, that the 8 KB-or-more fixtures parse identically in `mode: :native` and `mode: :ruby`, and record the exact version in the implementation PR.
48
+
49
+ **Depends on:** parsanol 1.3.96 released.
50
+
51
+ ### 2. Vendor and continuously validate the canonical grammar — 2–4 h
52
+
53
+ Copy the canonical upstream grammar and compiled artifact into `grammars/postscript.parg` and `grammars/postscript.json` (using the verified upstream filenames `postscript.parg` and its compiled JSON artifact). Keep the upstream grammar as the source of truth and document the update procedure in `grammars/README.md`. Preserve its embedded smoke tests and compile-versus-checked-in-artifact payload parity check in this repository's CI (in a job on Ruby ≥ 3.2 that installs parsanol as a development dependency only), using `bundle exec parsanol parg test` and `bundle exec parsanol parg compile` (verify flags/options against pinned release docs). Add a small repository task/script to compare compiled payloads after ignoring envelope checksum/compiler-version metadata. Separately load the committed artifact through `Parsanol::PARG::Artifact.load` to validate its checksum; payload equality does not replace envelope validation. Verify the vendored files match the pinned upstream source and artifact. Ensure the packaged gem includes both files by checking `Gem::Specification#files` or the built gem contents.
54
+
55
+ Review grammar rules against the guide pages listed in the issue correction: `docs/syntax/tokens.adoc`, `objects.adoc`, `data-types.adoc`, `strings.adoc`, `arrays.adoc`, `dictionaries.adoc`, `procedures.adoc`, and `operators.adoc`. Treat `docs/commands/**` as vocabulary coverage and `docs/levels/*` as level metadata coverage. The grammar accepts names independently of the target language level.
56
+
57
+ **Files:** existing `grammars/README.md`; proposed `grammars/postscript.parg`, `grammars/postscript.json`; proposed `.github/workflows/grammar.yml` (the existing `rake.yml` is autogenerated); proposed `script/check_parg_artifact.rb` for payload parity; gemspec packaging check.
58
+
59
+ **Depends on:** postscript-parg#3 merged; can proceed alongside the Ruby metadata inventory in work item 4 once exact guide paths are checked out or otherwise available.
60
+
61
+ ### 3. Add opt-in native tokenization with an unchanged public parse boundary — 3–6 h
62
+
63
+ Add `Source.parse(source, engine: :ruby)`; `engine: :native` tokenizes with the vendored artifact through parsanol and `engine: :ruby` (the default) calls `Lexer.tokenize` exactly as today. The native adapter loads parsanol lazily, requires `>= 1.3.96` and `Native.available?`, and raises a clear error otherwise; it never runs the Ruby atom runtime in place of the native engine. It converts captures to the same token contract consumed by `AstBuilder.build`: `Model::Token` type/value/line/column/literal readers, with line/column computed from capture byte offsets, and DSC/comment behavior required by the builder. Keep `AstBuilder` and `Model::Operator.from_operands` Ruby-side.
64
+
65
+ Errors: when the native parse fails, run `Lexer.tokenize` on the same source to raise the error. Failures then carry exactly the current `Postscript::LexError`/`Postscript::SyntaxError` class, message and `source_position`. This is limited to failed parses; successful native parses are never retried, so parity defects stay visible to the parity spec. Do not expose engine-specific tokens as a new public API. Do not add parsanol to the gemspec.
66
+
67
+ **Files/symbols:** `lib/postscript/source.rb`, `Postscript::Source.parse`, `Postscript::Source::Lexer`, proposed `lib/postscript/source/native_lexer.rb`, `Postscript::Model::Token`, `lib/postscript/errors.rb`.
68
+
69
+ **Depends on:** work items 1 and 2.
70
+
71
+ ### 4. Reconcile operator vocabulary and language-level metadata — 3–5 h
72
+
73
+ Compare every operator in the Guide's command categories with the gem's registry after `Model::Operators.load_all!`. Extend `Model::Operator.register_as` and the registry's registered-entry data only as needed to retain Level 1/2/3 availability. Add a Guide-derived inventory that lists every command category/operator as supported by a concrete class or intentionally represented by `Model::UnknownOperator`; do not silently omit categories or expand the implementation to add every missing operator. Add minimal post-parse validation against a requested level, preserving tolerant parse results and existing `Source.parse(source)` behavior. Define the smallest result/call shape in implementation after checking public API conventions; level violations must be observable. No level conditional may be added to the PARG grammar.
74
+
75
+ **Files/symbols:** `lib/postscript/model/operator.rb` (`register_as`), `lib/postscript/model/operators.rb` (`register`, `keywords`, `load_all!`), operator category files under `lib/postscript/model/operators/`, and proposed `lib/postscript/source/level_validator.rb`; proposed `spec/postscript/model/operator_guide_coverage_spec.rb`, proposed `spec/postscript/source/level_validator_spec.rb`, and proposed `data/postscript_operators.json` with category, operator name, language-level availability, registry mapping, and pinned Guide source provenance. Use the [Guide snapshot c45f337](https://github.com/claricle/postscript-guide/commit/c45f337f0112acc6a771cdc101a663858d23ee12) for command pages and `docs/levels/*` as explicit inventory sources. The checked-out Guide tree has 181 `docs/commands/**/*.adoc` pages across 17 subdirectories, while the issue cites 18 categories and 300+ operators; inventory work must reconcile pages, category indexes, and operator names rather than treating each page as one operator. Unknown operators remain explicit inventory rows.
76
+
77
+ **Depends on:** work item 2 for the Guide vocabulary source. This can be implemented independently of native dispatch after the grammar scope is confirmed.
78
+
79
+ ### 5. Prove token and model parity, error behavior, and performance — 3–4 h
80
+
81
+ Use the existing lexer as the parity oracle. Compare token streams over focused syntax cases and all relevant repository fixtures, including exact positions and literal-name flags. Compare native and Ruby-lexer `Model::Program` results over the current suite and source corpus, plus error class and `source_position` `[line, column]` for malformed strings, hex strings, and unbalanced composites. Verify that without parsanol the default path is unchanged and `engine: :native` raises a clear error. Use proposed `benchmark/corpus.json` to pin local fixtures and the external [`postsvg` fixture corpus at b699673](https://github.com/claricle/postsvg/commit/b699673d1a98235e38ad81f828ea2906ef3ada1c), including `spec/fixtures/ps2svg/new_tests/01_paths.ps` through `12_full_feature_test.ps` and `spec/fixtures/eps2svg/img.eps`; record expected parse failures separately and do not assume every rendering fixture parses as a complete document. Record a repeatable before/after benchmark on the same valid postscript/postsvg inputs and environment, with corpus manifest, successful/failed counts, and command in the PR; do not claim a speedup without measured results. The benchmark decides whether native may later become the default; current measurements say it may not.
82
+
83
+ The inspected `postsvg` converter currently calls `Postsvg::Parser.parse`, backed by its Parslet parser. Establish the actual consumer integration entry point before claiming a downstream smoke test; parsing its fixture corpus through `Postscript::Source.parse` alone does not demonstrate converter integration. Consumer changes and rendering verification require separately scoped work.
84
+
85
+ **Files:** add focused differential coverage in proposed `spec/postscript/source/native_parity_spec.rb` and preserve `spec/postscript/source/lexer_spec.rb`, `spec/postscript/source/ast_builder_spec.rb`, `spec/postscript/round_trip_spec.rb`, `spec/fixtures/`; proposed `benchmark/parse.rb` with `bundle exec ruby benchmark/parse.rb --engine ruby` and `--engine native` against the same manifest-selected valid corpus.
86
+
87
+ **Depends on:** work item 3; work item 4 for any level metadata coverage assertion.
88
+
89
+ ## Acceptance and planned verification
90
+
91
+ The commands below are **planned**, not run as part of this plan. Confirm exact CLI spelling against the selected parsanol release during implementation.
92
+
93
+ | Issue criterion / settled addition | Work | Observable check and expected result |
94
+ |---|---:|---|
95
+ | Grammar and compiled artifact are local, guide-derived, tested, and packaged | 2 | Run the upstream-supported PARG embedded-test command against `grammars/postscript.parg`; all embedded tests pass. Compile to a temporary artifact and compare payload with `grammars/postscript.json` after excluding envelope metadata; payloads match. Build the gem and inspect its file list; both artifacts are present. |
96
+ | Full Guide vocabulary is accepted and level coverage is complete | 2, 4 | CI compares Guide command names/categories to grammar name acceptance and the loaded Ruby registry; no Guide category/operator is silently omitted. A Level 3-only operator remains syntactically accepted in the same grammar and is marked as unavailable by Level 1/2 metadata validation. |
97
+ | Native and Ruby token streams agree | 3, 5 | Differential checks assert token type, value, line, column, and `literal` for the same inputs. Include comments/DSC, delimiter boundaries, radix and decimal forms, escaped/nested strings, hex strings, arrays, procedures, dictionaries, and names. All assertions match. |
98
+ | `Model::Program` parity across existing suite/fixtures | 3, 5 | Run `bundle exec rspec` (the issue cites 149 examples); compare `engine: :native` and `engine: :ruby` results on the suite and corpus. AST node classes/fields, headers, operator construction, unknown operators, and user procedure invocation match. |
99
+ | Ruby lexer remains the default | 3, 5 | Without parsanol installed, `Postscript::Source.parse(source)` returns the same program and errors as before; `engine: :native` raises a clear error. |
100
+ | Error behavior and token positions remain compatible | 3, 5 | Focused malformed-input cases assert `LexError`/`SyntaxError` class and `source_position`; token locations preserve the current one-based line/column contract. |
101
+ | Benchmarks are recorded | 5 | Run the same benchmark command and corpus against baseline Ruby and native paths; include manifest/SHA, expected failures, environment, corpus identity/size, warm-up/repetition method, and measured results in the implementation PR. |
102
+ | Project checks pass | 2–5 | Run `bundle exec rake` (RSpec and RuboCop via `Rakefile`) and the grammar compile/test checks. Record exact commands and outcomes; these remain planned until run. |
103
+
104
+ Proposed implementation commands (the comparison script, focused specs, and benchmark are created by the work items above):
105
+
106
+ ```sh
107
+ bundle exec parsanol parg test grammars/postscript.parg
108
+ bundle exec parsanol parg compile grammars/postscript.parg -o /tmp/postscript-fresh.json
109
+ bundle exec ruby script/check_parg_artifact.rb grammars/postscript.json /tmp/postscript-fresh.json
110
+ bundle exec ruby -rparsanol/parg/artifact -e 'Parsanol::PARG::Artifact.load("grammars/postscript.json")'
111
+ bundle exec rspec spec/postscript/source/native_parity_spec.rb spec/postscript/source/level_validator_spec.rb spec/postscript/model/operator_guide_coverage_spec.rb
112
+ bundle exec rake
113
+ gem build postscript.gemspec
114
+ bundle exec ruby benchmark/parse.rb --engine ruby
115
+ bundle exec ruby benchmark/parse.rb --engine native
116
+ ```
117
+
118
+ Confirm the selected release's artifact require path in work item 1. Inspect the built gem's file list for both grammar files. The benchmark must report which engine actually ran and fail a requested native run if native execution is unavailable.
119
+
120
+ Baseline: `bundle exec rake` is the repository's default RSpec + RuboCop task. The issue reports 149 examples; establish the current count during implementation and run the full current suite. No runtime test or CI result is claimed by this plan.
121
+
122
+ ## Sequencing and integration
123
+
124
+ Delivered as separate PRs:
125
+
126
+ 1. postscript-parg#3: token captures (upstream).
127
+ 2. Vendor the grammar and artifact with CI checks (work item 2), after postscript-parg#3 merges.
128
+ 3. Opt-in native lexer, parity spec, error mapping and benchmark (work items 1, 3, 5). It can be developed against a local parsanol build and merges after parsanol 1.3.96 is released.
129
+ 4. Operator vocabulary and language-level metadata (work item 4), independent of parsanol.
130
+
131
+ ## Effort and uncertainty
132
+
133
+ | Work item | Estimate |
134
+ |---|---:|
135
+ | 1. Confirm the released engine | 1 h |
136
+ | 2. Vendor grammar/artifact and CI | 2–4 h |
137
+ | 3. Opt-in native tokenization | 3–6 h |
138
+ | 4. Operator vocabulary/levels | 3–5 h |
139
+ | 5. Parity, errors, benchmarks | 3–4 h |
140
+ | **Subtotal** | **12–20 h** |
141
+ | Contingency (20%) | 2.4–4.0 h |
142
+ | **Total** | **14.4–24 h** |
143
+
144
+ The largest remaining uncertainty is how many grammar/lexer differences the parity spec finds; each one is either a grammar change upstream or a follow-up issue. Native speed is a known limitation, not a blocker, because native is opt-in. Estimates assume the Guide is accessible at its cited paths.
145
+
146
+ ## Progress and handoff
147
+
148
+ Status on 2026-10-22: **every work item is done**, and [#4](https://github.com/claricle/postscript/issues/4) is closed. The plan itself landed in [#7](https://github.com/claricle/postscript/pull/7). Upstream prerequisites are met: [postscript-parg#3](https://github.com/claricle/postscript-parg/pull/3) merged on 2026-10-20, and the engine fixes ([parsanol-rs#251](https://github.com/parsanol/parsanol-rs/pull/251), [parsanol-ruby#242](https://github.com/parsanol/parsanol-ruby/pull/242)) are released in parsanol 1.3.96 and later.
149
+
150
+ | Work item | Status | PRs | Evidence |
151
+ |---|---|---|---|
152
+ | 1. Confirm the released engine | Done | [#11](https://github.com/claricle/postscript/pull/11) | The native path requires parsanol 1.3.96 or newer with its native extension; CI runs the native specs on Ruby 3.3, 3.4 and 4.0. |
153
+ | 2. Vendor grammar/artifact and CI | Done | [#5](https://github.com/claricle/postscript/pull/5), [#6](https://github.com/claricle/postscript/pull/6), [#8](https://github.com/claricle/postscript/pull/8) | `grammars/postscript.parg` and `grammars/postscript.json` are pinned to an upstream commit in `grammars/upstream.yml`; the `grammar` workflow runs `script/check_grammar.rb`. |
154
+ | 3. Opt-in native tokenization | Done | [#10](https://github.com/claricle/postscript/pull/10), [#11](https://github.com/claricle/postscript/pull/11) | `Postscript::Source.parse(source, engine: :native)`; the Ruby lexer stays the default, and `NativeEngineUnavailable` is raised when parsanol is missing. |
155
+ | 4. Operator vocabulary/levels | Done | [#13](https://github.com/claricle/postscript/pull/13) (I4-A1), [#16](https://github.com/claricle/postscript/pull/16) (A2), [#19](https://github.com/claricle/postscript/pull/19) (A3), [#14](https://github.com/claricle/postscript/pull/14) (A4), [#18](https://github.com/claricle/postscript/pull/18) (B1), [#17](https://github.com/claricle/postscript/pull/17) (B3), [#20](https://github.com/claricle/postscript/pull/20) (B4), [#22](https://github.com/claricle/postscript/pull/22) (B5), [#21](https://github.com/claricle/postscript/pull/21) (C1), [#23](https://github.com/claricle/postscript/pull/23) (C2), [#25](https://github.com/claricle/postscript/pull/25) (C3), [#24](https://github.com/claricle/postscript/pull/24) (C4) | Guide operators extracted to `data/guide_operators.yml` and checked in CI, gaps filled in `data/operator_overrides.yml`, `Model::Vocabulary`, `Operator.language_level`, level violations through `Postscript.level_violations`, and the generated inventory in `docs/operators.adoc`. |
156
+ | 5. Parity, errors, benchmarks | Done | [#11](https://github.com/claricle/postscript/pull/11), [#15](https://github.com/claricle/postscript/pull/15) | `spec/postscript/source/native_lexer_spec.rb` checks token and `Model::Program` parity and errors against the Ruby lexer on every fixture; `benchmark/parse.rb` and the postsvg corpus benchmark record the measurements, and native stays opt-in. |
157
+
158
+ **Follow-ups, tracked separately:**
159
+
160
+ - [#26](https://github.com/claricle/postscript/issues/26): decide on the 6 places where the lexer differs from the Guide.
161
+ - [#27](https://github.com/claricle/postscript/issues/27): the AST builder drops dictionaries and non-literal array elements.
162
+ - Guide gaps behind the operator overrides, each linked from its `reason` in `data/operator_overrides.yml`: [postscript-guide#8](https://github.com/claricle/postscript-guide/issues/8) (pages without a level), [#9](https://github.com/claricle/postscript-guide/issues/9) (operators without a page), [#10](https://github.com/claricle/postscript-guide/issues/10) (Level 2 operators listed as new in Level 3), [#11](https://github.com/claricle/postscript-guide/issues/11) (operators named only on the level pages).
@@ -0,0 +1,22 @@
1
+ # grammars/
2
+
3
+ The PostScript grammar is maintained in
4
+ [claricle/postscript-parg](https://github.com/claricle/postscript-parg)
5
+ (claricle/postscript#4). This directory holds copies of its files:
6
+
7
+ - `postscript.parg`: the PARG source, with embedded tests.
8
+ - `postscript.json`: the artifact compiled from it.
9
+ - `upstream.yml`: the upstream commit the copies come from.
10
+
11
+ Do not edit the copies here. Change the grammar upstream, then:
12
+
13
+ 1. Copy `postscript.parg` and `postscript.json` from the merged
14
+ upstream commit into this directory.
15
+ 2. Set `commit` in `upstream.yml` to that commit.
16
+ 3. Run `ruby script/check_grammar.rb` (needs `gem install parsanol`,
17
+ Ruby 3.2 or newer).
18
+
19
+ The `grammar` workflow runs the same check. It fails if a copy differs
20
+ from upstream, the embedded tests fail, `postscript.json` is not what
21
+ the released parsanol compiles from `postscript.parg`, its checksum is
22
+ wrong, or the gem would not package both files.