Changeset View
Changeset View
Standalone View
Standalone View
src/script/data/indentation/pascal.js
Show First 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | |||||
89 | The following bugs are known. | 89 | The following bugs are known. | ||
90 | Fixing them is possible, but would make the indenter too big, slow and clever. | 90 | Fixing them is possible, but would make the indenter too big, slow and clever. | ||
91 | - 'else' keyword in 'case' statement not recognised. Use 'otherwise' instead | 91 | - 'else' keyword in 'case' statement not recognised. Use 'otherwise' instead | ||
92 | - comments keep alignment relative to preceding line, but naturally | 92 | - comments keep alignment relative to preceding line, but naturally | ||
93 | should keep alignment relative to following line. | 93 | should keep alignment relative to following line. | ||
94 | - procedure/function declarations in 'interface' should be indented | 94 | - procedure/function declarations in 'interface' should be indented | ||
95 | */ | 95 | */ | ||
96 | 96 | | |||
97 | "use strict"; | | |||
98 | | ||||
99 | // required katepart js libraries | 97 | // required katepart js libraries | ||
100 | require ("range.js"); | 98 | require ("range.js"); | ||
101 | require ("cursor.js"); | | |||
102 | require ("string.js"); | 99 | require ("string.js"); | ||
103 | 100 | | |||
104 | //BEGIN USER CONFIGURATION | 101 | //BEGIN USER CONFIGURATION | ||
105 | var cfgIndentCase = true; // indent elements in a case statement | 102 | var cfgIndentCase = true; // indent elements in a case statement | ||
106 | var cfgIndentBegin = 0; // indent begin | 103 | var cfgIndentBegin = 0; // indent begin | ||
107 | var cfgAutoInsertStar = true; // auto insert '*' in comments | 104 | var cfgAutoInsertStar = true; // auto insert '*' in comments | ||
108 | var cfgSnapParen = true; // snap ')' to '*)' in comments | 105 | var cfgSnapParen = true; // snap ')' to '*)' in comments | ||
109 | var debugMode = false; // send debug output to terminal | 106 | var debugMode = false; // send debug output to terminal | ||
110 | //END USER CONFIGURATION | 107 | //END USER CONFIGURATION | ||
111 | 108 | | |||
112 | 109 | | |||
113 | const patTrailingSemi = /;\s*(\/\/.*|\{.*\}|\(\*.*\*\))?\s*$/; | 110 | var patTrailingSemi = /;\s*(\/\/.*|\{.*\}|\(\*.*\*\))?\s*$/; | ||
114 | const patMatchEnd = /\b(begin|case|record)\b/i; | 111 | var patMatchEnd = /\b(begin|case|record)\b/i; | ||
115 | const patDeclaration = /^\s*(program|module|unit|uses|import|implementation|interface|label|const|type|var|function|procedure|operator)\b/i; | 112 | var patDeclaration = /^\s*(program|module|unit|uses|import|implementation|interface|label|const|type|var|function|procedure|operator)\b/i; | ||
116 | const patTrailingBegin = /\bbegin\s*(\/\/.*|\{.*\}|\(\*.*\*\))?\s*$/i; | 113 | var patTrailingBegin = /\bbegin\s*(\/\/.*|\{.*\}|\(\*.*\*\))?\s*$/i; | ||
117 | const patTrailingEnd = /\bend;?\s*(\/\/.*|\{.*\}|\(\*.*\*\))?\s*$/i; | 114 | var patTrailingEnd = /\bend;?\s*(\/\/.*|\{.*\}|\(\*.*\*\))?\s*$/i; | ||
118 | const patCaseValue = /^(\s*[^,:;]+\s*(,\s*[^,:;]+\s*)*):(?!=)/; | 115 | var patCaseValue = /^(\s*[^,:;]+\s*(,\s*[^,:;]+\s*)*):(?!=)/; | ||
119 | const patEndOfStatement = /(;|end)\s*(\/\/.*|\{.*\}|\(\*.*\*\))?\s*$/i; | 116 | var patEndOfStatement = /(;|end)\s*(\/\/.*|\{.*\}|\(\*.*\*\))?\s*$/i; | ||
120 | 117 | | |||
121 | function dbg() { | 118 | function dbg() { | ||
122 | if (debugMode) { | 119 | if (debugMode) { | ||
123 | debug.apply(this, arguments); | 120 | debug.apply(this, arguments); | ||
124 | } | 121 | } | ||
125 | } | 122 | } | ||
126 | 123 | | |||
127 | 124 | | |||
▲ Show 20 Lines • Show All 1259 Lines • ▼ Show 20 Line(s) | |||||
1387 | 1384 | | |||
1388 | } // tryStatement() | 1385 | } // tryStatement() | ||
1389 | 1386 | | |||
1390 | 1387 | | |||
1391 | // specifies the characters which should trigger indent, beside the default '\n' | 1388 | // specifies the characters which should trigger indent, beside the default '\n' | ||
1392 | triggerCharacters = " \t)]}#;"; | 1389 | triggerCharacters = " \t)]}#;"; | ||
1393 | 1390 | | |||
1394 | // possible outdent for lines that match this regexp | 1391 | // possible outdent for lines that match this regexp | ||
1395 | const PascalReIndent = /^\s*((end|const|type|var|begin|until|function|procedure|operator|else|otherwise|\w+\s*:)\s+|[#\)\]\}]|end;)(.*)$/; | 1392 | var PascalReIndent = /^\s*((end|const|type|var|begin|until|function|procedure|operator|else|otherwise|\w+\s*:)\s+|[#\)\]\}]|end;)(.*)$/; | ||
1396 | 1393 | | |||
1397 | // check if the trigger characters are in the right context, | 1394 | // check if the trigger characters are in the right context, | ||
1398 | // otherwise running the indenter might be annoying to the user | 1395 | // otherwise running the indenter might be annoying to the user | ||
1399 | function reindentTrigger(line) | 1396 | function reindentTrigger(line) | ||
1400 | { | 1397 | { | ||
1401 | var res = PascalReIndent.exec(document.line(line)); | 1398 | var res = PascalReIndent.exec(document.line(line)); | ||
1402 | dbg("reindentTrigger: checking line, found", ((res && res[3] == "" )? "'"+ (res[2]?res[2]:res[1])+"'": "nothing") ); | 1399 | dbg("reindentTrigger: checking line, found", ((res && res[3] == "" )? "'"+ (res[2]?res[2]:res[1])+"'": "nothing") ); | ||
1403 | return ( res && (res[3] == "" )); | 1400 | return ( res && (res[3] == "" )); | ||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |