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 --------------------------------------------------------------------------------
20 local gg = require 'metalua.grammar.generator'
23 local _M = gg.future(M)
26 local _A = gg.future(A)
29 -- Type identifier: Lua keywords such as `"nil"` allowed.
30 function M.annot.tid(lx)
33 if t=='Keyword' and w[1] :match '^[%a_][%w_]*$' or w.tag=='Id'
34 then return {tag='TId'; lineinfo=w.lineinfo; w[1]}
35 else return gg.parse_error (lx, 'tid expected') end
38 local field_types = { var='TVar'; const='TConst';
39 currently='TCurrently'; field='TField' }
41 -- TODO check lineinfo
42 function M.annot.tf(lx)
45 local tag = field_types[w]
46 if not tag then error ('Invalid field type '..w)
47 elseif tag=='TField' then return {tag='TField'} else
53 M.annot.tebar_content = gg.list{
54 name = 'tebar content',
56 separators = { ",", ";" },
59 M.annot.tebar = gg.multisequence{
61 --{ '*', builder = 'TDynbar' }, -- maybe not user-available
62 { '(', _A.tebar_content, ')',
63 builder = function(x) return x[1] end },
67 M.annot.te = gg.multisequence{
69 { _A.tid, builder=function(x) return x[1] end },
70 { '*', builder = 'TDyn' },
73 primary = gg.sequence{
77 separators = { ",", ";" },
78 terminators = { "]", "|" } },
79 gg.onkeyword{ "|", _A.tf },
82 local fields, other = unpack(x)
83 return { tag='TTable', other or {tag='TField'}, fields }
85 { '(', _A.tebar_content, ')', '->', '(', _A.tebar_content, ')',
87 local p, r = unpack(x)
88 return {tag='TFunction', p, r }
91 M.annot.ts = gg.multisequence{
93 { 'return', _A.tebar_content, builder='TReturn' },
94 { _A.tid, builder = function(x)
95 if x[1][1]=='pass' then return {tag='TPass'}
96 else error "Bad statement type" end
99 -- TODO: add parsers for statements:
104 M.annot.stat_annot = gg.sequence{
105 gg.list{ primary=_A.tid, separators='.' },