note:sun_jun_22_2025

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
note:sun_jun_22_2025 [2025/06/22 02:34] – created lingaonote:sun_jun_22_2025 [2025/06/22 14:52] (current) lingao
Line 1: Line 1:
 ====== Code Formatter ====== ====== Code Formatter ======
  
-  * https://yorickpeterse.com/articles/how-to-write-a-code-formatter/ +  * :!: https://yorickpeterse.com/articles/how-to-write-a-code-formatter/  
-  * https://www.ntietz.com/blog/writing-basic-code-formatter/+  * https://www.ntietz.com/blog/writing-basic-code-formatter/  
 +  * :!: https://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-ever-written/ 
 + 
 +===== How to write a code formatter ===== 
 + 
 +reference: https://www.ntietz.com/blog/writing-basic-code-formatter/ 
 + 
 +prettier is based on [[https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf|this paper]] 
 + 
 +===== code gen ===== 
 + 
 +<code ts> 
 +type LowcodeInterface = { 
 +  identifier: string; 
 +  fields: { name: string, type: string, comment?: string }[]; 
 +  comment?: string; 
 +
 + 
 +function printField(field: { name: string, type: string, comment?: string }) { 
 +  return (field.comment ? '  /* ' + field.comment + ' */' + "\n" : ""
 +          + "  " + field.name + ": " + field.type; 
 +
 + 
 +function printInterface(lowcodeInterface: LowcodeInterface) { 
 +  return (lowcodeInterface.comment ? '/* ' + lowcodeInterface.comment + " */\n" : ""
 +          + "interface " + lowcodeInterface.identifier + " {\n" 
 +          + lowcodeInterface.fields.map(printField).join('\n')  
 +          + "\n}"; 
 +
 + 
 +export { printInterface };   
 +</code> 
  • note/sun_jun_22_2025.1750559665.txt.gz
  • Last modified: 2025/06/22 02:34
  • by lingao