index.d.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. declare module 'pug-lexer' {
  2. namespace lex {
  3. export interface Loc {
  4. start: {line: number; column: number};
  5. end: {line: number; column: number};
  6. }
  7. export type LexTokenType =
  8. | ':'
  9. | '&attributes'
  10. | 'attribute'
  11. | 'block'
  12. | 'blockcode'
  13. | 'call'
  14. | 'case'
  15. | 'class'
  16. | 'code'
  17. | 'comment'
  18. | 'default'
  19. | 'doctype'
  20. | 'dot'
  21. | 'each'
  22. | 'eachOf'
  23. | 'else-if'
  24. | 'else'
  25. | 'end-attributes'
  26. | 'end-pipeless-text'
  27. | 'end-pug-interpolation'
  28. | 'eos'
  29. | 'extends'
  30. | 'filter'
  31. | 'id'
  32. | 'if'
  33. | 'include'
  34. | 'indent'
  35. | 'interpolated-code'
  36. | 'interpolation'
  37. | 'mixin-block'
  38. | 'mixin'
  39. | 'newline'
  40. | 'outdent'
  41. | 'path'
  42. | 'slash'
  43. | 'start-attributes'
  44. | 'start-pipeless-text'
  45. | 'start-pug-interpolation'
  46. | 'tag'
  47. | 'text-html'
  48. | 'text'
  49. | 'when'
  50. | 'while'
  51. | 'yield';
  52. export interface LexToken<Type extends LexTokenType> {
  53. type: Type;
  54. loc: Loc;
  55. }
  56. export interface TagToken extends LexToken<'tag'> {
  57. val: string;
  58. }
  59. export type StartAttributesToken = LexToken<'start-attributes'>;
  60. export interface AttributeToken extends LexToken<'attribute'> {
  61. name: string;
  62. val: string | boolean;
  63. mustEscape: boolean;
  64. }
  65. export type EndAttributesToken = LexToken<'end-attributes'>;
  66. export interface IndentToken extends LexToken<'indent'> {
  67. val: number;
  68. }
  69. export interface ClassToken extends LexToken<'class'> {
  70. val: string;
  71. }
  72. export type OutdentToken = LexToken<'outdent'>;
  73. export type EosToken = LexToken<'eos'>;
  74. export interface CommentToken extends LexToken<'comment'> {
  75. val: string;
  76. buffer: boolean;
  77. }
  78. export type NewlineToken = LexToken<'newline'>;
  79. export interface TextToken extends LexToken<'text'> {
  80. val: string;
  81. }
  82. export interface InterpolatedCodeToken
  83. extends LexToken<'interpolated-code'> {
  84. mustEscape: boolean;
  85. buffer: boolean;
  86. val: string;
  87. }
  88. export interface CodeToken extends LexToken<'code'> {
  89. val: string;
  90. mustEscape: boolean;
  91. buffer: boolean;
  92. }
  93. export interface IdToken extends LexToken<'id'> {
  94. val: string;
  95. }
  96. export type StartPipelessTextToken = LexToken<'start-pipeless-text'>;
  97. export type EndPipelessTextToken = LexToken<'end-pipeless-text'>;
  98. export interface DoctypeToken extends LexToken<'doctype'> {
  99. val: string;
  100. }
  101. export type DotToken = LexToken<'dot'>;
  102. export interface BlockToken extends LexToken<'block'> {
  103. val: string;
  104. mode: 'replace' | 'prepend' | 'append';
  105. }
  106. export type ExtendsToken = LexToken<'extends'>;
  107. export interface PathToken extends LexToken<'path'> {
  108. val: string;
  109. }
  110. export type StartPugInterpolationToken = LexToken<
  111. 'start-pug-interpolation'
  112. >;
  113. export type EndPugInterpolationToken = LexToken<'end-pug-interpolation'>;
  114. export interface InterpolationToken extends LexToken<'interpolation'> {
  115. val: string;
  116. }
  117. export type IncludeToken = LexToken<'include'>;
  118. export interface FilterToken extends LexToken<'filter'> {
  119. val: string;
  120. }
  121. export interface CallToken extends LexToken<'call'> {
  122. val: string;
  123. args: string;
  124. }
  125. export interface MixinToken extends LexToken<'mixin'> {
  126. val: string;
  127. args: string | null;
  128. }
  129. export interface IfToken extends LexToken<'if'> {
  130. val: string;
  131. }
  132. export type MixinBlockToken = LexToken<'mixin-block'>;
  133. export interface ElseToken extends LexToken<'else'> {
  134. val: string;
  135. }
  136. export interface AndAttributesToken extends LexToken<'&attributes'> {
  137. val: string;
  138. }
  139. export interface TextHtmlToken extends LexToken<'text-html'> {
  140. val: string;
  141. }
  142. export interface EachToken extends LexToken<'each'> {
  143. val: string;
  144. key: string | null;
  145. code: string;
  146. }
  147. export interface EachOfToken extends LexToken<'eachOf'> {
  148. val: string;
  149. value: string;
  150. code: string;
  151. }
  152. export interface WhileToken extends LexToken<'while'> {
  153. val: string;
  154. }
  155. export interface CaseToken extends LexToken<'case'> {
  156. val: string;
  157. }
  158. export interface WhenToken extends LexToken<'when'> {
  159. val: string;
  160. }
  161. export type ColonToken = LexToken<':'>;
  162. export type DefaultToken = LexToken<'default'>;
  163. export interface ElseIfToken extends LexToken<'else-if'> {
  164. val: string;
  165. }
  166. export type BlockcodeToken = LexToken<'blockcode'>;
  167. export type YieldToken = LexToken<'yield'>;
  168. export type SlashToken = LexToken<'slash'>;
  169. export type Token =
  170. | AndAttributesToken
  171. | AttributeToken
  172. | BlockcodeToken
  173. | BlockToken
  174. | CallToken
  175. | CaseToken
  176. | ClassToken
  177. | CodeToken
  178. | ColonToken
  179. | CommentToken
  180. | DefaultToken
  181. | DoctypeToken
  182. | DotToken
  183. | EachToken
  184. | EachOfToken
  185. | ElseIfToken
  186. | ElseToken
  187. | EndAttributesToken
  188. | EndPipelessTextToken
  189. | EndPugInterpolationToken
  190. | EosToken
  191. | ExtendsToken
  192. | FilterToken
  193. | IdToken
  194. | IfToken
  195. | IncludeToken
  196. | IndentToken
  197. | InterpolatedCodeToken
  198. | InterpolationToken
  199. | MixinBlockToken
  200. | MixinToken
  201. | NewlineToken
  202. | OutdentToken
  203. | PathToken
  204. | SlashToken
  205. | StartAttributesToken
  206. | StartPipelessTextToken
  207. | StartPugInterpolationToken
  208. | TagToken
  209. | TextHtmlToken
  210. | TextToken
  211. | WhenToken
  212. | WhileToken
  213. | YieldToken;
  214. export type LexerFunction = (type: string, exp?: any) => boolean;
  215. export interface LexerOptions {
  216. filename: string;
  217. interpolated?: boolean;
  218. startingLine?: number;
  219. startingColumn?: number;
  220. plugins?: LexerFunction[];
  221. }
  222. export class Lexer {
  223. input: string;
  224. originalInput: string;
  225. filename?: string;
  226. interpolated: boolean;
  227. lineno: number;
  228. colno: number;
  229. plugins: LexerFunction[];
  230. indentStack: number[];
  231. indentRe: RegExp | null;
  232. interpolationAllowed: boolean;
  233. whitespaceRe: RegExp;
  234. tokens: Token[];
  235. ended: boolean;
  236. constructor(str: string, options?: LexerOptions);
  237. error(code: string, message: string): never;
  238. assert(value: any, message: string): void;
  239. isExpression(exp: string): boolean;
  240. assertExpression(exp: string, noThrow?: boolean): boolean;
  241. assertNestingCorrect(exp: string): void;
  242. private tok<Type extends LexTokenType>(
  243. type: Type,
  244. val?: any,
  245. ): LexToken<Type>;
  246. private tokEnd<Type extends LexTokenType>(
  247. tok: LexToken<Type>,
  248. ): LexToken<Type>;
  249. private incrementLine(increment: number): void;
  250. private incrementColumn(increment: number): void;
  251. private consume(len: number): void;
  252. private scan<Type extends LexTokenType>(
  253. regexp: RegExp,
  254. type: Type,
  255. ): LexToken<Type> | undefined;
  256. private scanEndOfLine<Type extends LexTokenType>(
  257. regexp: RegExp,
  258. type: Type,
  259. ): LexToken<Type> | undefined;
  260. private bracketExpression(skip?: number): number;
  261. scanIndentation(): RegExpExecArray | null;
  262. eos(): true | undefined;
  263. blank(): true | undefined;
  264. comment(): true | undefined;
  265. interpolation(): true | undefined;
  266. tag(): true | undefined;
  267. filter(): true | undefined;
  268. doctype(): true | undefined;
  269. id(): true | undefined;
  270. className(): true | undefined;
  271. endInterpolation(): true | undefined;
  272. addText(
  273. type: LexTokenType,
  274. value: string,
  275. prefix?: string,
  276. escaped?: number,
  277. ): void;
  278. text(): true | undefined;
  279. textHtml(): true | undefined;
  280. dot(): true | undefined;
  281. extends(): true | undefined;
  282. prepend(): true | undefined;
  283. append(): true | undefined;
  284. block(): true | undefined;
  285. mixinBlock(): true | undefined;
  286. yield(): true | undefined;
  287. include(): true | undefined;
  288. path(): true | undefined;
  289. case(): true | undefined;
  290. when(): true | undefined;
  291. default(): true | undefined;
  292. call(): true | undefined;
  293. mixin(): true | undefined;
  294. conditional(): true | undefined;
  295. while(): true | undefined;
  296. each(): true | undefined;
  297. eachOf(): true | undefined;
  298. code(): true | undefined;
  299. blockCode(): true | undefined;
  300. attribute(): string;
  301. attributeValue(
  302. str: string,
  303. ): {val?: string; mustEscape?: boolean; remainingSource: string};
  304. attrs(): true | undefined;
  305. attributesBlock(): true | undefined;
  306. indent(): true | NewlineToken | undefined;
  307. pipelessText(indents?: number): boolean | undefined;
  308. slash(): true | undefined;
  309. colon(): true | undefined;
  310. fail(): never;
  311. callLexerFunction(func: string): boolean;
  312. private advance(): boolean;
  313. getTokens(): Token[];
  314. }
  315. }
  316. function lex(str: string, options?: lex.LexerOptions): lex.Token[];
  317. export = lex;
  318. }