1 --------------------------------------------------------------------------------
2 -- Copyright (c) 2006-2013 Fabien Fleutot and others.
4 -- All rights reserved.
6 -- This program and the accompanying materials are made available
7 -- under the terms of the Eclipse Public License v1.0 which
8 -- accompanies this distribution, and is available at
9 -- http://www.eclipse.org/legal/epl-v10.html
11 -- This program and the accompanying materials are also made available
12 -- under the terms of the MIT public license which accompanies this
13 -- distribution, and is available at http://www.lua.org/license.html
16 -- Fabien Fleutot - API and implementation
18 --------------------------------------------------------------------------------
21 local gg = require 'metalua.grammar.generator'
24 function M.opt(mlc, primary, a_type)
25 checks('table', 'table|function', 'string')
28 gg.onkeyword{ "#", function() return assert(mlc.annot[a_type]) end },
30 local t, annot = unpack(x)
31 return annot and { tag='Annot', t, annot } or t
35 -- split a list of "foo" and "`Annot{foo, annot}" into a list of "foo"
36 -- and a list of "annot".
37 -- No annot list is returned if none of the elements were annotated.
39 local x, a, some = { }, { }, false
40 for i, p in ipairs(lst) do
41 if p.tag=='Annot' then
42 some, x[i], a[i] = true, unpack(p)
45 if some then return x, a else return lst end