2 # The source code parser is implemented as a state machine.
4 # Each state is associated with a particular language and semantic (:code, :comment, or :blank).
6 # The state name -- any helpful mnemonic, but must be unique within this language.
9 # When in this state, we are considered to be reading this language.
12 # One of :code, :comment, or :blank.
15 def initialize(language, name, semantic)
16 raise ArgumentError.new("unknown semantic '#{ semantic }'") unless [:code, :comment, :blank].include?(semantic)
19 @name = name.to_s.downcase
24 "#{ language }_#{ name.to_s }".upcase
31 # Emit the state definition as C statements into the generated file.
33 io.puts %(State #{ definition } = { "#{ full_name }", "#{ @language }", semantic_#{ semantic.to_s } };)