25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

97 lines
3.6 KiB

  1. """
  2. pygments.lexers.openscad
  3. ~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for the OpenSCAD languages.
  5. :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, bygroups, words, include
  9. from pygments.token import Text, Comment, Punctuation, Operator, Keyword, Name, Number, Whitespace, Literal, String
  10. __all__ = ['OpenScadLexer']
  11. class OpenScadLexer(RegexLexer):
  12. """For openSCAD code.
  13. """
  14. name = "OpenSCAD"
  15. url = "https://openscad.org/"
  16. aliases = ["openscad"]
  17. filenames = ["*.scad"]
  18. mimetypes = ["application/x-openscad"]
  19. version_added = '2.16'
  20. tokens = {
  21. "root": [
  22. (r"[^\S\n]+", Whitespace),
  23. (r'//', Comment.Single, 'comment-single'),
  24. (r'/\*', Comment.Multiline, 'comment-multi'),
  25. (r"[{}\[\]\(\),;:]", Punctuation),
  26. (r"[*!#%\-+=?/]", Operator),
  27. (r"<=|<|==|!=|>=|>|&&|\|\|", Operator),
  28. (r"\$(f[asn]|t|vp[rtd]|children)", Operator),
  29. (r"(undef|PI)\b", Keyword.Constant),
  30. (
  31. r"(use|include)((?:\s|\\\\s)+)",
  32. bygroups(Keyword.Namespace, Text),
  33. "includes",
  34. ),
  35. (r"(module)(\s*)([^\s\(]+)",
  36. bygroups(Keyword.Namespace, Whitespace, Name.Namespace)),
  37. (r"(function)(\s*)([^\s\(]+)",
  38. bygroups(Keyword.Declaration, Whitespace, Name.Function)),
  39. (words(("true", "false"), prefix=r"\b", suffix=r"\b"), Literal),
  40. (words((
  41. "function", "module", "include", "use", "for",
  42. "intersection_for", "if", "else", "return"
  43. ), prefix=r"\b", suffix=r"\b"), Keyword
  44. ),
  45. (words((
  46. "circle", "square", "polygon", "text", "sphere", "cube",
  47. "cylinder", "polyhedron", "translate", "rotate", "scale",
  48. "resize", "mirror", "multmatrix", "color", "offset", "hull",
  49. "minkowski", "union", "difference", "intersection", "abs",
  50. "sign", "sin", "cos", "tan", "acos", "asin", "atan", "atan2",
  51. "floor", "round", "ceil", "ln", "log", "pow", "sqrt", "exp",
  52. "rands", "min", "max", "concat", "lookup", "str", "chr",
  53. "search", "version", "version_num", "norm", "cross",
  54. "parent_module", "echo", "import", "import_dxf",
  55. "dxf_linear_extrude", "linear_extrude", "rotate_extrude",
  56. "surface", "projection", "render", "dxf_cross",
  57. "dxf_dim", "let", "assign", "len"
  58. ), prefix=r"\b", suffix=r"\b"),
  59. Name.Builtin
  60. ),
  61. (r"\bchildren\b", Name.Builtin.Pseudo),
  62. (r'""".*?"""', String.Double),
  63. (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
  64. (r"-?\d+(\.\d+)?(e[+-]?\d+)?", Number),
  65. (r"\w+", Name),
  66. ],
  67. "includes": [
  68. (
  69. r"(<)([^>]*)(>)",
  70. bygroups(Punctuation, Comment.PreprocFile, Punctuation),
  71. ),
  72. ],
  73. 'comment': [
  74. (r':param: [a-zA-Z_]\w*|:returns?:|(FIXME|MARK|TODO):',
  75. Comment.Special)
  76. ],
  77. 'comment-single': [
  78. (r'\n', Text, '#pop'),
  79. include('comment'),
  80. (r'[^\n]+', Comment.Single)
  81. ],
  82. 'comment-multi': [
  83. include('comment'),
  84. (r'[^*/]+', Comment.Multiline),
  85. (r'/\*', Comment.Multiline, '#push'),
  86. (r'\*/', Comment.Multiline, '#pop'),
  87. (r'[*/]', Comment.Multiline)
  88. ],
  89. }