logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

texinfo.lua (9456B)


  1. -- Copyright 2014-2024 stef@ailleurs.land. See LICENSE.
  2. -- Plain Texinfo version 5.2 LPeg lexer
  3. -- Freely inspired from Mitchell work and valuable help from him too !
  4. -- Directives are processed (more or less) in the Reference Card Texinfo order Reference Card
  5. -- page for each directive group is in comment for reference
  6. --[[
  7. Note: Improving Fold Points use with Texinfo
  8. At the very beginning of your Texinfo file, it could be wised to insert theses alias :
  9. @alias startchapter = comment
  10. @alias endchapter = comment
  11. Then use this to begin each chapter :
  12. @endchapter --------------------------------------------------------------------
  13. @chapter CHAPTER TITLE
  14. @startchapter ------------------------------------------------------------------
  15. With the use of Scintilla's `SCI_FOLDALL(SC_FOLDACTION_TOGGLE)` or Textadept's
  16. `buffer:fold_all(buffer.FOLDACTION_TOGGLE)`, you have then a nice chapter folding, useful with
  17. large documents.
  18. ]]
  19. local lexer = lexer
  20. local token, word_match = lexer.token, lexer.word_match
  21. local P, S = lpeg.P, lpeg.S
  22. local lex = lexer.new(...)
  23. -- Directives.
  24. lex:add_rule('directive',
  25. lex:tag('command', ('@end' * lexer.space^1 + '@') * lex:word_match('directive', true)))
  26. -- Chapters.
  27. lex:add_rule('chapter', lex:tag('command.section',
  28. ('@end' * lexer.space^1 + '@') * lex:word_match('chapter', true)))
  29. -- Common keywords.
  30. lex:add_rule('keyword', lex:tag(lexer.KEYWORD, ('@end' * lexer.space^1 + '@') *
  31. lex:word_match(lexer.KEYWORD, true)))
  32. -- Italics
  33. local nested_braces = lexer.range('{', '}', false, false, true)
  34. lex:add_rule('emph', lex:tag(lexer.ITALIC, '@emph' * nested_braces))
  35. -- Bold
  36. lex:add_rule('strong', lex:tag(lexer.BOLD, '@strong' * nested_braces))
  37. -- Identifiers
  38. lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word))
  39. -- Strings.
  40. lex:add_rule('string', lex:tag(lexer.STRING, nested_braces))
  41. -- Numbers.
  42. lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number))
  43. -- Comments.
  44. local line_comment = lexer.to_eol('@c', true)
  45. -- local line_comment_long = lexer.to_eol('@comment', true)
  46. local block_comment = lexer.range('@ignore', '@end ignore')
  47. lex:add_rule('comment', lex:tag(lexer.COMMENT, line_comment + block_comment))
  48. -- Fold points.
  49. lex:add_fold_point('command', '@titlepage', '@end titlepage')
  50. lex:add_fold_point('command', '@copying', '@end copying')
  51. lex:add_fold_point('command', '@ifset', '@end ifset')
  52. lex:add_fold_point('command', '@tex', '@end tex')
  53. lex:add_fold_point('command', '@itemize', '@end itemize')
  54. lex:add_fold_point('command', '@enumerate', '@end enumerate')
  55. lex:add_fold_point('command', '@multitable', '@end multitable')
  56. lex:add_fold_point('command', '@example', '@end example')
  57. lex:add_fold_point('command', '@smallexample', '@end smallexample')
  58. lex:add_fold_point('command', '@cartouche', '@end cartouche')
  59. lex:add_fold_point('command', '@startchapter', '@end startchapter')
  60. -- Word lists.
  61. lex:set_word_list('directive', {
  62. 'end',
  63. -- Custom keywords for chapter folding
  64. 'startchapter', 'endchapter',
  65. -- List and tables (page 2, column 2)
  66. 'itemize', 'enumerate',
  67. -- Beginning a Texinfo document (page 1, column 1)
  68. 'titlepage', 'copying',
  69. -- Block environments (page 2, column 1)
  70. 'cartouche',
  71. -- Block environments > Displays using fixed-width fonts (page 2, column 2)
  72. 'example', 'smallexample',
  73. -- List and tables (page 2, column 2)
  74. 'multitable',
  75. -- Floating Displays (page 2, column 3)
  76. 'float', 'listoffloats', 'caption', 'shortcaption', 'image',
  77. -- Floating Displays > Footnotes (page 2, column 3)
  78. 'footnote', 'footnotestyle',
  79. -- Conditionally (in)visible text > Output formats (page 3, column 3)
  80. 'ifdocbook', 'ifhtml', 'ifinfo', 'ifplaintext', 'iftex', 'ifxml', 'ifnotdocbook', 'ifnothtml',
  81. 'ifnotplaintext', 'ifnottex', 'ifnotxml', 'ifnotinfo', 'inlinefmt', 'inlinefmtifelse',
  82. -- Conditionally (in)visible text > Raw formatter text (page 4, column 1)
  83. 'docbook', 'html', 'tex', 'xml', 'inlineraw',
  84. -- Conditionally (in)visible text > Documents variables (page 4, column 1)
  85. 'set', 'clear', 'value', 'ifset', 'ifclear', 'inlineifset', 'inlineifclear',
  86. -- Conditionally (in)visible text > Testing for commands (page 4, column 1)
  87. 'ifcommanddefined', 'ifcommandnotdefined', 'end',
  88. -- Defining new Texinfo commands (page 4, column 1)
  89. 'alias', 'macro', 'unmacro', 'definfounclose',
  90. -- File inclusion (page 4, column 1)
  91. 'include', 'verbatiminclude',
  92. -- Formatting and headers footers for TeX (page 4, column 1)
  93. 'allowcodebreaks', 'finalout', 'fonttextsize',
  94. -- Formatting and headers footers for TeX > paper size (page 4, column 2)
  95. 'smallbook', 'afourpaper', 'afivepaper', 'afourlatex', 'afourwide', 'pagesizes',
  96. -- Formatting and headers footers for TeX > Page headers and footers (page 4, column 2)
  97. -- not implemented
  98. -- Document preferences (page 4, column 2)
  99. -- not implemented
  100. -- Ending a Texinfo document (page 4, column 2)
  101. 'bye'
  102. })
  103. lex:set_word_list('chapter', {
  104. -- Chapter structuring (page 1, column 2)
  105. 'lowersections', 'raisesections', 'part',
  106. -- Chapter structuring > Numbered, included in contents (page 1, column 2)
  107. 'chapter', 'centerchap',
  108. -- Chapter structuring > Context-dependent, included in contents (page 1, column 2)
  109. 'section', 'subsection', 'subsubsection',
  110. -- Chapter structuring > Unumbered, included in contents (page 1, column 2)
  111. 'unnumbered', 'unnumberedsec', 'unnumberedsubsec', 'unnumberedsubsection', 'unnumberedsubsubsec',
  112. 'unnumberedsubsubsection',
  113. -- Chapter structuring > Letter and numbered, included in contents (page 1, column 2)
  114. 'appendix', 'appendixsec', 'appendixsection', 'appendixsubsec', 'appendixsubsection',
  115. 'appendixsubsubsec', 'appendixsubsubsection',
  116. -- Chapter structuring > Unumbered, not included in contents, no new page (page 1, column 3)
  117. 'chapheading', 'majorheading', 'heading', 'subheading', 'subsubheading'
  118. })
  119. lex:set_word_list(lexer.KEYWORD, {
  120. 'end',
  121. -- Beginning a Texinfo document (page 1, column 1)
  122. 'setfilename', 'settitle', 'insertcopying',
  123. -- Beginning a Texinfo document > Internationlization (page 1, column 1)
  124. 'documentencoding', 'documentlanguage', 'frenchspacing',
  125. -- Beginning a Texinfo document > Info directory specification and HTML document description
  126. -- (page 1, column 1)
  127. 'dircategory', 'direntry', 'documentdescription',
  128. -- Beginning a Texinfo document > Titre pages (page 1, column 1)
  129. 'shorttitlepage', 'center', 'titlefont', 'title', 'subtitle', 'author',
  130. -- Beginning a Texinfo document > Tables of contents (page 1, column 2)
  131. 'shortcontents', 'summarycontents', 'contents', 'setcontentsaftertitlepage',
  132. 'setshortcontentsaftertitlepage',
  133. -- Nodes (page 1, column 2)
  134. 'node', 'top', 'anchor', 'novalidate',
  135. -- Menus (page 1, column 2)
  136. 'menu', 'detailmenu',
  137. -- Cross references > Within the Info system (page 1, column 3)
  138. 'xref', 'pxref', 'ref', 'inforef', 'xrefautomaticsectiontitle',
  139. -- Cross references > Outside of info (page 1, column 3)
  140. 'url', 'cite',
  141. -- Marking text > Markup for regular text (page 1, column 3)
  142. 'var', 'dfn', 'acronym', 'abbr',
  143. -- Marking text > Markup for litteral text (page 1, column 3)
  144. 'code', 'file', 'command', 'env', 'option', 'kbd', 'key', 'email', 'indicateurl', 'samp', 'verb',
  145. -- Marking text > GUI sequences (page 2, column 1)
  146. 'clicksequence', 'click', 'clickstyle', 'arrow',
  147. -- Marking text > Math (page 2, column 1)
  148. 'math', 'minus', 'geq', 'leq',
  149. -- Marking text > Explicit font selection (page 2, column 1)
  150. 'sc', 'r', 'i', 'slanted', 'b', 'sansserif', 't',
  151. -- Block environments (page 2, column 1)
  152. 'noindent', 'indent', 'exdent',
  153. -- Block environments > Normally filled displays using regular text fonts (page 2, column 1)
  154. 'quotation', 'smallquotation', 'indentedblock', 'smallindentedblock', 'raggedright',
  155. -- Block environments > Line-for-line displays using regular test fonts (page 2, column 2)
  156. 'format', 'smallformat', 'display', 'smalldisplay', 'flushleft', 'flushright',
  157. -- Block environments > Displays using fixed-width fonts (page 2, column 2)
  158. 'lisp', 'smalllisp', 'verbatim',
  159. -- List and tables (page 2, column 2)
  160. 'table', 'ftable', 'vtable', 'tab', 'item', 'itemx', 'headitem', 'headitemfont', 'asis',
  161. -- Indices (page 2, column 3)
  162. 'cindex', 'findex', 'vindex', 'kindex', 'pindex', 'tindex', 'defcodeindex', 'syncodeindex',
  163. 'synindex', 'printindex',
  164. -- Insertions within a paragraph > Characters special to Texinfo (page 2, column 3)
  165. '@', '{', '}', 'backslashcar', 'comma', 'hashcar', ':', '.', '?', '!', 'dmn',
  166. -- Insertions within a paragraph > Accents (page 3, column 1)
  167. -- not implemented
  168. -- Insertions within a paragraph > Non-English characters (page 3, column 1)
  169. -- not implemented
  170. -- Insertions within a paragraph > Other text characters an logos (page 3, column 1)
  171. 'bullet', 'dots', 'enddots', 'euro', 'pounds', 'textdegree', 'copyright', 'registeredsymbol',
  172. 'TeX', 'LaTeX', 'today', 'guillemetleft', 'guillementright', 'guillemotleft', 'guillemotright',
  173. -- Insertions within a paragraph > Glyphs for code examples (page 3, column 2)
  174. 'equiv', 'error', 'expansion', 'point', 'print', 'result',
  175. -- Making and preventing breaks (page 3, column 2)
  176. '*', '/', '-', 'hyphenation', 'tie', 'w', 'refill',
  177. -- Vertical space (page 3, column 2)
  178. 'sp', 'page', 'need', 'group', 'vskip'
  179. -- Definition commands (page 3, column 2)
  180. -- not implemented
  181. })
  182. lexer.property['scintillua.comment'] = '@c'
  183. return lex