1 //
2 // aegis - project change supervisor
3 // Copyright (C) 2008 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at
8 // your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #include <libaegis/gram.h>
20 #include <libaegis/input.h>
21 #include <libaegis/meta_context.h>
22 #include <libaegis/meta_lex.h>
23 #include <libaegis/sem.h>
24 
25 
26 static meta_context *context;
27 
28 
29 void
sem_integer(long n)30 sem_integer(long n)
31 {
32     context->integer(n);
33 }
34 
35 
36 void
sem_real(double n)37 sem_real(double n)
38 {
39     context->real(n);
40 }
41 
42 
43 void
sem_string(const nstring & s)44 sem_string(const nstring &s)
45 {
46     context->string(s);
47 }
48 
49 
50 void
sem_enum(const nstring & s)51 sem_enum(const nstring &s)
52 {
53     context->enumeration(s);
54 }
55 
56 
57 void
sem_list(void)58 sem_list(void)
59 {
60     context->list();
61 }
62 
63 
64 void
sem_list_end(void)65 sem_list_end(void)
66 {
67     context->list_end();
68 }
69 
70 
71 void
sem_field(const nstring & name)72 sem_field(const nstring &name)
73 {
74     context->field(name);
75 }
76 
77 
78 void
sem_field_end()79 sem_field_end()
80 {
81     context->field_end();
82 }
83 
84 
85 void
sem_parse(meta_context & ctx,input & ifp)86 sem_parse(meta_context &ctx, input &ifp)
87 {
88     context = &ctx;
89     lex_open_input(ifp);
90     gram_parse();
91     context->end();
92     lex_close();
93     context = 0;
94 }
95 
96 
97 void
sem_parse_file(meta_context & ctx,const nstring & filename)98 sem_parse_file(meta_context &ctx, const nstring &filename)
99 {
100     input ip = lex_iopen_file(filename);
101     sem_parse(ctx, ip);
102 }
103 
104 
105 void
sem_parse_env(meta_context & ctx,const nstring & name)106 sem_parse_env(meta_context &ctx, const nstring &name)
107 {
108     input ip = lex_iopen_env(name);
109     sem_parse(ctx, ip);
110 }
111