@@ -9,6 +9,8 @@ signature
99
1010 ppchar : StartChar -> ppchar
1111
12+ ppStmtBlock : Stmt * FollowLines -> ppStmtBlock
13+
1214 // For ambiguities
1315 amb : list -> choice
1416
@@ -19,10 +21,10 @@ strategies //=================START OF STRATEGIES============================
1921 io-wrap(fixed-to-free)
2022
2123 fixed-to-free =
22- outermost(fixed-disamb)
23- ; innermost(fixed-to-free-comments)
24+ // outermost(fixed-disamb)
25+ innermost(fixed-to-free-comments)
2426 ; innermost(fixed-to-free-form)
25- // ; < fixed-to-free-continuation> <id>
27+ ; outermost( fixed-to-free-continuation)
2628// ; innermost(fix-dos-line-endings)
2729
2830
@@ -42,88 +44,70 @@ fixed-disamb =
4244 <+ ? amb([BlankLine(ws, eol), Continuation(_,_,_,_)]) /* DOS blank lines with spaces */
4345 ; ! BlankLine(ws, eol)
4446
45- // Change comment character to '!'
46- //
47+
48+ /**
49+ * Change comment character to '!'
50+ */
4751fixed-to-free-comments = ? comchar("C") ; ! comchar("!")
4852 <+ ? comchar("c") ; ! comchar("!")
4953 <+ ? comchar("*") ; ! comchar("!")
5054
51- // Change DOS line endings to unix (unparsing doesn't work properly for DOS "\r\n" line endings)
52- //
55+
56+ /**
57+ * Change DOS line endings to unix (unparsing doesn't work properly for DOS "\r\n" line endings)
58+ */
5359fix-dos-line-endings: eol("\r\n") -> eol("\n")
5460
55- // Change fixed-form directive to free form
56- //
61+
62+ /**
63+ * Change fixed-form directive to free form
64+ */
5765fixed-to-free-form: Comment(comchar(_), "DEC$ NOFREEFORM", eol("\n"))
5866 -> Comment(comchar("!"), "DEC$ FREEFORM", eol("\n"))
5967fixed-to-free-form: Comment(comchar(_), "DIR$ FIXED", eol("\n"))
6068 -> Comment(comchar("!"), "DIR$ FREE", eol("\n"))
6169
62- // Change start character to ' '
63- //
70+ /**
71+ * Change start character to ' '
72+ */
6473fixed-to-free-form: stchar(_) -> ppchar(" ")
6574
66- // Change continuation character to '&'
67- //
75+
76+ /**
77+ * Change continuation character to '&'
78+ */
6879fixed-to-free-form: conchar(_) -> ppchar("&")
6980
70- // Add continuation character to end of continued lines
71- //
72- fixed-to-free-continuation =
73- {list
74- : ? File(lines)
75- ; <add-continuation(|[])> lines
76- ; ! File(<id>)
77- }
7881
79- // Add continuation character to next line if needed
80- // -------------------------------------------------
81- add-continuation(|list) =
82- {new_list
82+ /**
83+ * Add continuation character to end of continuations (except for last)
84+ *
85+ * This works by reversing the follow list in a StmtBlock, separating the
86+ * list at the last Continuation (now the first) and putting the entire
87+ * list back together in the proper order.
88+ */
89+ fixed-to-free-continuation =
8390
8491 /* has continuation branch */
85- : ? [head|tail]
86- ; <is-continued> tail
87- ; ! head
88- ; try(<insert-cont-char> head)
89- ; <concat> [list, [<id>]] => new_list
90- ; <add-continuation(|new_list)> tail
91-
92- /* no continuation branch */
93- <+ ? [head|tail]
94- ; <concat> [list, [head]] => new_list
95- ; <add-continuation(|new_list)> tail
96-
97- /* end of list branch */
98- <+ ? [head]
99- ; <concat> [list, [head]]
100- }
101-
102- // Succeeds if next non-blank line is continued
103- // --------------------------------------------
104- is-continued =
105- /* check for continuation */
106- ? [head|tail]
107- ; ! head
108- ; ? Continuation(_,_,_,_)
109-
110- /* check for continuation after a blank line */
111- <+ ? [head|tail]
112- ; ! head
113- ; ? BlankLine(_,_)
114- ; <is-continued> tail
115-
116- /* check for continuation after a comment line */
117- <+ ? [head|tail]
118- ; ! head
119- ; ? Comment(_,_,_)
120- ; <is-continued> tail
121-
122- /* check for continuation after a comment line */
123- <+ ? [head|tail]
124- ; ! head
125- ; ? FreeFormComment(_,_,_,_)
126- ; <is-continued> tail
92+ ? StmtBlock(stmt,follow)
93+ ; <has-continuation> follow
94+ ; <split-fetch-keep(?Continuation(_,_,_,_))> <reverse> follow
95+ ; ? (before, split, after)
96+ ; <concat> [<reverse(insert-cont-char)>after, [split], <reverse>before]
97+ ; ! ppStmtBlock(<insert-cont-char>stmt, <id>)
98+
99+ /* no continuation branch */
100+ <+ ? StmtBlock(stmt,follow)
101+ ; ! ppStmtBlock(stmt,follow)
102+
103+
104+ /**
105+ * Succeeds if a continuation line exists
106+ */
107+ has-continuation =
108+ ? list
109+ ; <fetch(?Continuation(_,_,_,_))> list
110+ ; ! list
127111
128112
129113/**
@@ -133,14 +117,18 @@ insert-cont-char =
133117 ? Stmt(begin,char,text,end)
134118 ; ! Stmt(begin,char,<insert-cont-char-in-text>text,end)
135119
136- insert-cont-char =
137- ? LabeledStmt(begin,char,text,end)
120+ <+ ? LabeledStmt(begin,char,text,end)
138121 ; ! LabeledStmt(begin,char,<insert-cont-char-in-text>text,end)
139122
140- insert-cont-char =
141- ? Continuation(begin,char,text,end)
123+ <+ ? Continuation(begin,char,text,end)
142124 ; ! Continuation(begin,char,<insert-cont-char-in-text>text,end)
143125
126+ /* these are left alone */
127+
128+ <+ ? BlankLine(_,_)
129+ <+ ? Comment(_,_,_)
130+ <+ ? Preprocess(_,_,_)
131+
144132/**
145133 * Insert continuation character in text (before comment or at end of text)
146134 */
0 commit comments