blob: 1c8eb382c4ff72abfbf05d2193ed1e8af580bafd [file] [log] [blame]
-- Copyright (c) 2012-2013 Sierra Wireless.
-- All rights reserved. This program and the accompanying materials
-- are made available under the terms of the Eclipse Public License v1.0
-- which accompanies this distribution, and is available at
-- Contributors:
-- Kevin KIN-FOO <>
-- - initial API and implementation and initial documentation
require 'metalua.loader'
local compiler = require 'metalua.compiler'
local javamodelfactory = require 'javamodelfactory'
local mlc51, mlc52
-- Just redefining classic print, as there is a flush problem calling it from Java
local print = function(...) print(...) io.flush() end
local M = {}
function M.newMLC51()
local function lexer51()
local generic_lexer = require 'metalua.grammar.lexer'
local lexer = generic_lexer.lexer :clone()
local keywords = {
"and", "break", "do", "else", "elseif",
"end", "false", "for", "function",
"in", "local", "nil", "not", "or", "repeat",
"return", "then", "true", "until", "while",
"...", "..", "==", ">=", "<=", "~=",
"+{", "-{"
for _, w in ipairs(keywords) do lexer :add (w) end
return lexer
local newmlc =
newmlc.parser.lexer = lexer51()
return newmlc
-- Build Java Model from source code
-- @param #string source Code to parse
-- @param LuaSourceRoot, DLTK node, root of DLTK AST
function, modulename, root, luaGrammar)
local mlc
if (luaGrammar == "lua-5.1") then
if (not mlc51) then
mlc51 = M.newMLC51()
mlc = mlc51
if (not mlc52) then
mlc52 =
mlc = mlc52
-- manage shebang
if source then source = source:gsub("^(#.-\n)", function (s) return string.rep(' ',string.len(s)) end) end
-- if no errors, check AST
local ast = mlc:src_to_ast( source )
-- Create api model
local apimodelbuilder = require 'models.apimodelbuilder'
local _file, comment2apiobj = apimodelbuilder.createmoduleapi(ast,modulename)
-- create internal model
local internalmodelbuilder = require "models.internalmodelbuilder"
local _internalcontent = internalmodelbuilder.createinternalcontent(ast,_file,comment2apiobj,modulename)
-- Converting api model to java
local javaapimodelbuilder = require 'javaapimodelbuilder'
local jfile, handledexpr = javaapimodelbuilder._file(_file)
-- Converting internal model to java
local javainternalmodelbuilder = require 'javainternalmodelbuilder'
local jinternalcontent = javainternalmodelbuilder._internalcontent(_internalcontent,_file, handledexpr)
-- Append information from documentation
local handledcomments={}
-- TODO clean perf profiling
-- local e = os.clock()
-- print ('global time', type(e), type(s),(e*1000-s*1000))
return M