Where is the formal ICAO flight plan text format specified? I want to write a parser for ICAO format flight plans, like the one shown below.

(FPL-AEE036-IS
-A320/M-SCDE2GHILORTUWY/S
-LGTS1635
-N0471F310 LEKPO UL617 SKP UB1 ABLON
-LGAV0042 LGSA
-PBN/C1B2S1 DOF/160805 REG/SXDVD)

The thing is that everything I come across is related to flight plan filling and not about this format, what to expect, what not to expect, field meanings, possible values etc.

I am looking for something like that but formal, preferably from some ICAO document
You will want to look in PANS-ATM (ICAO Document 4444), specifically, Appendix 2. (reproducing the entire appendix in this answer is not practical; it is 10 pages long). SKYbrary is also a nice resource.

Note that the ICAO model flight plan form actually contains the text format embedded in the form. Where slashes, hyphens, prefix letters etc. are required, they are printed directly on the form. I have highlited a few in the below screenshot for clarification:



&lt;&lt;≡ denotes start/end of message and newline.

➝ denotes a space.