1+ // From @codemirror /legacy-modes
2+ function errorIfNotEmpty ( stream ) {
3+
4+ var nonWS = stream . match ( / ^ \s * \S / ) ;
5+
6+ stream . skipToEnd ( ) ;
7+
8+ return nonWS ? "error" : null ;
9+
10+ }
11+
12+
13+ export const asciiArmor = {
14+
15+ name : "asciiarmor" ,
16+
17+ token : function ( stream , state ) {
18+
19+ var m ;
20+
21+ if ( state . state == "top" ) {
22+
23+ if ( stream . sol ( ) && ( m = stream . match ( / ^ - - - - - B E G I N ( .* ) ? - - - - - \s * $ / ) ) ) {
24+
25+ state . state = "headers" ;
26+
27+ state . type = m [ 1 ] ;
28+
29+ return "tag" ;
30+
31+ }
32+
33+ return errorIfNotEmpty ( stream ) ;
34+
35+ } else if ( state . state == "headers" ) {
36+
37+ if ( stream . sol ( ) && stream . match ( / ^ \w + : / ) ) {
38+
39+ state . state = "header" ;
40+
41+ return "atom" ;
42+
43+ } else {
44+
45+ var result = errorIfNotEmpty ( stream ) ;
46+
47+ if ( result ) state . state = "body" ;
48+
49+ return result ;
50+
51+ }
52+
53+ } else if ( state . state == "header" ) {
54+
55+ stream . skipToEnd ( ) ;
56+
57+ state . state = "headers" ;
58+
59+ return "string" ;
60+
61+ } else if ( state . state == "body" ) {
62+
63+ if ( stream . sol ( ) && ( m = stream . match ( / ^ - - - - - E N D ( .* ) ? - - - - - \s * $ / ) ) ) {
64+
65+ if ( m [ 1 ] != state . type ) return "error" ;
66+
67+ state . state = "end" ;
68+
69+ return "tag" ;
70+
71+ } else {
72+
73+ if ( stream . eatWhile ( / [ A - Z a - z 0 - 9 + \/ = ] / ) ) {
74+
75+ return null ;
76+
77+ } else {
78+
79+ stream . next ( ) ;
80+
81+ return "error" ;
82+
83+ }
84+
85+ }
86+
87+ } else if ( state . state == "end" ) {
88+
89+ return errorIfNotEmpty ( stream ) ;
90+
91+ }
92+
93+ } ,
94+
95+ blankLine : function ( state ) {
96+
97+ if ( state . state == "headers" ) state . state = "body" ;
98+
99+ } ,
100+
101+ startState : function ( ) {
102+
103+ return { state : "top" , type : null } ;
104+
105+ }
106+
107+ } ;
0 commit comments