nmode-attributes.sl 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % Nmode-Attributes.SL - macros for NMODE parsing primitives
  4. % [This file used to be Parsing-Attributes.SL]
  5. %
  6. % Author: Alan Snyder
  7. % Hewlett-Packard/CRC
  8. % Date: 22 November 1982
  9. %
  10. % This file defines Macros! Load it at compile-time!
  11. %
  12. % See the document NMODE-PARSING.TXT for a description of the parsing strategy.
  13. %
  14. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  15. (CompileTime (load objects fast-int))
  16. % Internal Constants:
  17. % Type attributes:
  18. % Exactly one of these should always be on.
  19. (defconst OPENER-BITS 2#000000001) % part of an opening "bracket"
  20. (defconst CLOSER-BITS 2#000000010) % part of a closing "bracket"
  21. (defconst ATOM-BITS 2#000000100) % part of an "atom"
  22. (defconst BLANKS-BITS 2#000001000) % part of a "blank region"
  23. (defconst COMMENT-BITS 2#000010000) % part of a comment
  24. % Secondary attributes:
  25. % Zero or more of these may be on.
  26. (defconst PREFIX-BITS 2#000100000) % a subclass of opening bracket
  27. % Position attributes:
  28. % One or two of these should always be on.
  29. (defconst FIRST-BITS 2#001000000) % the first character of an item
  30. (defconst MIDDLE-BITS 2#010000000) % neither first nor last
  31. (defconst LAST-BITS 2#100000000) % the last character of an item
  32. % Masks:
  33. (defconst POSITION-BITS #.(| (const FIRST-BITS)
  34. (| (const MIDDLE-BITS) (const LAST-BITS))))
  35. (defconst BRACKET-BITS #.(| (const OPENER-BITS) (const CLOSER-BITS)))
  36. (defconst WHITESPACE-BITS #.(| (const BLANKS-BITS) (const COMMENT-BITS)))
  37. (defconst NOT-SPACE-BITS #.(| (const BRACKET-BITS) (const ATOM-BITS)))
  38. (defconst PRIMARY-TYPE-BITS #.(| (const NOT-SPACE-BITS)
  39. (const WHITESPACE-BITS)))
  40. (defconst SECONDARY-TYPE-BITS #.(const PREFIX-BITS))
  41. (defconst TYPE-BITS #.(| (const PRIMARY-TYPE-BITS)
  42. (const SECONDARY-TYPE-BITS)))
  43. (de parse-character-attributes (attribute-list)
  44. % Given a list of attribute names, return an integer containing
  45. % all of their bits.
  46. (let ((bits 0))
  47. (for (in attribute-name attribute-list)
  48. (do
  49. (selectq attribute-name
  50. (OPENER (setf bits (| bits (const OPENER-BITS))))
  51. (CLOSER (setf bits (| bits (const CLOSER-BITS))))
  52. (BRACKET (setf bits (| bits (const BRACKET-BITS))))
  53. (ATOM (setf bits (| bits (const ATOM-BITS))))
  54. (BLANKS (setf bits (| bits (const BLANKS-BITS))))
  55. (COMMENT (setf bits (| bits (const COMMENT-BITS))))
  56. (WHITESPACE (setf bits (| bits (const WHITESPACE-BITS))))
  57. (NOT-SPACE (setf bits (| bits (const NOT-SPACE-BITS))))
  58. (PREFIX (setf bits (| bits (const PREFIX-BITS))))
  59. (FIRST (setf bits (| bits (const FIRST-BITS))))
  60. (MIDDLE (setf bits (| bits (const MIDDLE-BITS))))
  61. (LAST (setf bits (| bits (const LAST-BITS))))
  62. (t (StdError
  63. (BldMsg "Invalid character attribute: %p" attribute-name)))
  64. )))
  65. bits
  66. ))
  67. (de unparse-character-attributes (bits)
  68. % Return a list of attribute names.
  69. (let ((l ()))
  70. (if (~= 0 (& bits (const OPENER-BITS))) (setf l (cons 'OPENER l)))
  71. (if (~= 0 (& bits (const CLOSER-BITS))) (setf l (cons 'CLOSER l)))
  72. (if (~= 0 (& bits (const ATOM-BITS))) (setf l (cons 'ATOM l)))
  73. (if (~= 0 (& bits (const BLANKS-BITS))) (setf l (cons 'BLANKS l)))
  74. (if (~= 0 (& bits (const COMMENT-BITS))) (setf l (cons 'COMMENT l)))
  75. (if (~= 0 (& bits (const PREFIX-BITS))) (setf l (cons 'PREFIX l)))
  76. (if (~= 0 (& bits (const LAST-BITS))) (setf l (cons 'LAST l)))
  77. (if (~= 0 (& bits (const MIDDLE-BITS))) (setf l (cons 'MIDDLE l)))
  78. (if (~= 0 (& bits (const FIRST-BITS))) (setf l (cons 'FIRST l)))
  79. l
  80. ))
  81. (de decode-character-attribute-type (bits)
  82. % Return a primary type attribute name or NIL.
  83. (cond
  84. ((~= 0 (& bits (const OPENER-BITS))) 'OPENER)
  85. ((~= 0 (& bits (const CLOSER-BITS))) 'CLOSER)
  86. ((~= 0 (& bits (const ATOM-BITS))) 'ATOM)
  87. ((~= 0 (& bits (const BLANKS-BITS))) 'BLANKS)
  88. ((~= 0 (& bits (const COMMENT-BITS))) 'COMMENT)
  89. (t NIL)
  90. ))
  91. (de fix-attribute-bits (bits)
  92. (if (= (& bits (const POSITION-BITS)) 0)
  93. % No position specified? Then any position will do.
  94. (setf bits (| bits (const POSITION-BITS))))
  95. (if (= (& bits (const TYPE-BITS)) 0)
  96. % No type specified? Then any type will do.
  97. (setf bits (| bits (const TYPE-BITS))))
  98. bits
  99. )
  100. (defmacro attributes attributes-list
  101. (parse-character-attributes attributes-list)
  102. )
  103. (defmacro test-attributes attributes-list
  104. (fix-attribute-bits (parse-character-attributes attributes-list))
  105. )