Permalink
Browse files

C lexer now recognizes preprocessor lines

  • Loading branch information...
1 parent 9deb39b commit 00e2168d12d5f537c6c21318277f7969e620bafb @stevedonovan committed Mar 28, 2012
Showing with 4 additions and 3 deletions.
  1. +1 −1 macro.lua
  2. +2 −1 macro/clexer.lua
  3. +1 −1 tests/cexport.lua
View
@@ -545,7 +545,7 @@ function M.substitute(src,name, use_c)
end
while t do
--- print('tv',t,v)
+ --print('tv',t,v)
local dump = true
if t == 'iden' then -- classic name macro
local mac = imacros[v]
View
@@ -83,13 +83,14 @@ function clexer.init ()
local singleline_comment = P '//' * (1 - S '\r\n\f') ^ 0
local multiline_comment = '/*' * (1 - P'*/')^0 * '*/'
local comment = token('comment', multiline_comment + singleline_comment)
+ local prepro = token('prepro',P '#' * (1 - S '\r\n\f') ^ 0)
-- whitespace
local whitespace = token('space', S('\r\n\f\t ')^1)
-- ordered choice of all tokens and last-resort error which consumes one character
local any_token = whitespace + number + keyword + ident +
- string + char + comment + operator + token('error', 1)
+ string + char + comment + prepro + operator + token('error', 1)
table_of_tokens = Ct(any_token ^ 0)
View
@@ -10,7 +10,7 @@ end
local f,hname,mname
M.keyword_handler('BEGIN',function()
- hname = M.filename:gsub('%.c$','')..'.h'
+ hname = M.filename:gsub('%.%a+$','')..'.h'
mname = hname:gsub('%.','_'):upper()
f = io.open(M.filename..'.h','w')
f:write('#ifndef ',mname,'\n')

0 comments on commit 00e2168

Please sign in to comment.