golang_tokens.txt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. # character sets
  2. [identifier_schars a-zA-Z_
  3. [identifier_chars a-zA-Z0-9_
  4. [num_chars_start 0-9
  5. [num_chars 0-9
  6. [octal_chars 0-7
  7. [hex_chars 0-9a-fA-F
  8. [float_chars_start 0-9.\-\+
  9. [float_chars 0-9.eE
  10. [float_chars_start 0-9.\-\+
  11. [ws \ \t\r\n
  12. [endl \r\n
  13. # keywords
  14. # : is extra user data to be carried through
  15. # | is a failover on a character set on discontinuity in the word
  16. {break :keyword |identifier_chars>LST_identifier
  17. {case :keyword |identifier_chars>LST_identifier
  18. {chan :keyword |identifier_chars>LST_identifier
  19. {const :keyword |identifier_chars>LST_identifier
  20. {continue :keyword |identifier_chars>LST_identifier
  21. {default :keyword |identifier_chars>LST_identifier
  22. {defer :keyword |identifier_chars>LST_identifier
  23. {else :keyword |identifier_chars>LST_identifier
  24. {fallthrough :keyword |identifier_chars>LST_identifier
  25. {for :keyword |identifier_chars>LST_identifier
  26. {func :keyword |identifier_chars>LST_identifier
  27. {go :keyword |identifier_chars>LST_identifier
  28. {goto :keyword |identifier_chars>LST_identifier
  29. {if :keyword |identifier_chars>LST_identifier
  30. {import :keyword |identifier_chars>LST_identifier
  31. {interface :keyword |identifier_chars>LST_identifier
  32. {iota :keyword |identifier_chars>LST_identifier
  33. {map :keyword |identifier_chars>LST_identifier
  34. {package :keyword |identifier_chars>LST_identifier
  35. {range :keyword |identifier_chars>LST_identifier
  36. {return :keyword |identifier_chars>LST_identifier
  37. {select :keyword |identifier_chars>LST_identifier
  38. {struct :keyword |identifier_chars>LST_identifier
  39. {switch :keyword |identifier_chars>LST_identifier
  40. {type :keyword |identifier_chars>LST_identifier
  41. {var :keyword |identifier_chars>LST_identifier
  42. # operators and punctuation
  43. {+ :operator
  44. {& :operator
  45. {+= :operator
  46. {&= :operator
  47. {&& :operator
  48. {== :operator
  49. {!= :operator
  50. {( :punct
  51. {) :punct
  52. {- :operator
  53. {| :operator
  54. {-= :operator
  55. {|= :operator
  56. {|| :operator
  57. {< :operator
  58. {<= :operator
  59. {[ :punct
  60. {] :punct
  61. {* :operator
  62. {^ :operator
  63. {*= :operator
  64. {^= :operator
  65. {<- :operator
  66. {> :operator
  67. {>= :operator
  68. {{ :punct
  69. {} :punct
  70. {/ :operator
  71. :LST_NULL___slash @/>LST_sl_comment
  72. :LST_NULL___slash @*>LST_ml_comment
  73. {<< :operator
  74. {/= :operator
  75. {<<= :operator
  76. {++ :operator
  77. {= :operator
  78. {:= :operator
  79. {, :operator
  80. {; :operator
  81. {% :operator
  82. {>> :operator
  83. {%= :operator
  84. {>>= :operator
  85. {-- :operator
  86. {! :operator
  87. {... :operator
  88. {. :operator +num_chars>LST_float
  89. {: :operator
  90. {&^ :operator
  91. {&^= :operator
  92. # types
  93. {uint8 :type |identifier_chars>LST_identifier
  94. {uint16 :type |identifier_chars>LST_identifier
  95. {uint32 :type |identifier_chars>LST_identifier
  96. {uint64 :type |identifier_chars>LST_identifier
  97. {int8 :type |identifier_chars>LST_identifier
  98. {int16 :type |identifier_chars>LST_identifier
  99. {int32 :type |identifier_chars>LST_identifier
  100. {int64 :type |identifier_chars>LST_identifier
  101. {float32 :type |identifier_chars>LST_identifier
  102. {float64 :type |identifier_chars>LST_identifier
  103. {complex64 :type |identifier_chars>LST_identifier
  104. {complex128 :type |identifier_chars>LST_identifier
  105. {rune :type |identifier_chars>LST_identifier
  106. {byte :type |identifier_chars>LST_identifier
  107. {uint :type |identifier_chars>LST_identifier
  108. {int :type |identifier_chars>LST_identifier
  109. {uintptr :type |identifier_chars>LST_identifier
  110. {string :type |identifier_chars>LST_identifier
  111. # mark some terminal states
  112. &LST_float
  113. &LST_probenum
  114. &LST_intnum
  115. &LST_octalnum
  116. &LST_hexnum
  117. &LST_identifier
  118. &LST_float_exp
  119. # all other identifiers
  120. # + is transition on a character set
  121. :LST_identifier +identifier_chars>LST_identifier
  122. :LST_NULL +identifier_schars>LST_identifier
  123. # ignore whitespace
  124. # ^ discards the char while moving to the next state
  125. :LST_NULL +ws^LST_NULL
  126. # strings
  127. # @ is a single-char transition
  128. :LST_string @"=LST_string
  129. :LST_NULL @">LST_string
  130. &LST_string_end
  131. :LST_string @\\>LST_string_esc
  132. :LST_string !@/>LST_string
  133. :LST_string_esc @">LST_string
  134. # char literals
  135. :LST_charlit @'=LST_charlit
  136. :LST_NULL @'>LST_charlit
  137. &LST_charlit_end
  138. :LST_charlit @\\>LST_charlit_esc
  139. :LST_charlit !@/>LST_charlit
  140. :LST_charlit_esc @'>LST_charlit
  141. # numbers
  142. :LST_NULL @0>LST_probenum
  143. :LST_NULL @1>LST_intnum
  144. :LST_NULL @2>LST_intnum
  145. :LST_NULL @3>LST_intnum
  146. :LST_NULL @4>LST_intnum
  147. :LST_NULL @5>LST_intnum
  148. :LST_NULL @6>LST_intnum
  149. :LST_NULL @7>LST_intnum
  150. :LST_NULL @8>LST_intnum
  151. :LST_NULL @9>LST_intnum
  152. :LST_probenum @.>LST_float
  153. :LST_probenum @x>LST_hexnum
  154. :LST_probenum @X>LST_hexnum
  155. :LST_probefixed @x>LST_hexnum
  156. :LST_probefixed @X>LST_hexnum
  157. :LST_probenum +num_chars>LST_octalnum
  158. :LST_probefixed +num_chars>LST_octalnum
  159. :LST_intnum @.>LST_float
  160. :LST_intnum +num_chars>LST_intnum
  161. :LST_octalnum +octal_chars>LST_octalnum
  162. :LST_hexnum +hex_chars>LST_hexnum
  163. :LST_float @.>LST_INVALID
  164. :LST_float +num_chars>LST_float
  165. :LST_float @e>LST_float_exp_start
  166. :LST_float @E>LST_float_exp_start
  167. :LST_float_exp_start +num_chars>LST_float_exp
  168. :LST_float_exp_start @->LST_float_exp
  169. :LST_float_exp_start @+>LST_float_exp
  170. :LST_float_exp +num_chars>LST_float_exp
  171. # comments
  172. # @c~state terminates the token on finding c but does NOT consume c
  173. # @c=state terminates the token on finding c but DOES consume c
  174. # note how single-line comments do not include the linebreak but do terminate on it
  175. # whereas multiline comments terminate on the slash as well as include it
  176. &LST_sl_comment
  177. :LST_sl_comment !+endl>LST_sl_comment
  178. :LST_sl_comment @\r~LST_sl_comment
  179. :LST_sl_comment @\n~LST_sl_comment
  180. &LST_ml_comment
  181. :LST_ml_comment @*>LST_ml_comment_star
  182. :LST_ml_comment !@*>LST_ml_comment
  183. :LST_ml_comment_star @/=LST_ml_comment
  184. :LST_ml_comment_star !@/>LST_ml_comment