Mercurial > hg > ltpda
comparison m-toolbox/classes/@LTPDAworkbench/parse.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % PARSE an LTPDA command | |
2 % | |
3 % Try to parse out: | |
4 % output vars | |
5 % input vars | |
6 % method name | |
7 % plists | |
8 % comment at end of line | |
9 % | |
10 % $Id: parse.m,v 1.2 2010/08/06 19:10:49 ingo Exp $ | |
11 % | |
12 function out = parse(cmd) | |
13 | |
14 cmd = strtrim(cmd); | |
15 | |
16 % get comment | |
17 st = regexp(cmd, '%', 'split'); | |
18 if numel(st)>1 | |
19 cmt = st{2}; | |
20 else | |
21 cmt = ''; | |
22 end | |
23 | |
24 % get method | |
25 str = st{1}; | |
26 mtdend = length(str); | |
27 for kk=1:length(str) | |
28 if str(kk) == '(' | |
29 mtdend = kk-1; | |
30 break; | |
31 end | |
32 end | |
33 mtdstart = 1; | |
34 for kk=1:mtdend | |
35 if str(kk) == '=' | |
36 mtdstart = kk+1; | |
37 break; | |
38 end | |
39 end | |
40 method = strtrim(regexp(str(mtdstart:mtdend), '\w*', 'match')); | |
41 method = method{1}; | |
42 | |
43 % get output | |
44 output = ''; | |
45 for kk=1:mtdstart | |
46 if str(kk) == '=' | |
47 output = str(1:kk-1); | |
48 break; | |
49 end | |
50 end | |
51 output = strrep(output, '[', ''); | |
52 output = strrep(output, ']', ''); | |
53 if ~isempty(output) | |
54 outvars = regexp(output, ',*\s*', 'split'); | |
55 else | |
56 outvars = {}; | |
57 end | |
58 | |
59 pls = {}; | |
60 pl = ''; | |
61 rest = strrep(cmd, pl, ''); | |
62 plstart = regexp(rest, 'plist\(', 'start'); | |
63 while ~isempty(plstart) | |
64 % look for the opening ( | |
65 for kk=plstart(1):length(rest) | |
66 if rest(kk) == '(' | |
67 plstart = kk; | |
68 break | |
69 end | |
70 end | |
71 % now look for the ending ) for this plist | |
72 nexp = 1; | |
73 kk=plstart+1; | |
74 while nexp~=0 | |
75 if rest(kk) == '(' | |
76 nexp = nexp + 1; | |
77 elseif rest(kk) == ')' | |
78 nexp = nexp - 1; | |
79 end | |
80 kk=kk+1; | |
81 end | |
82 plend = kk-1; | |
83 pl = ['plist' rest(plstart:plend)]; | |
84 rest = strrep(rest, pl, ''); | |
85 plstart = regexp(rest, 'plist\(', 'start'); | |
86 pls = [pls {pl}]; | |
87 end | |
88 | |
89 % input vars | |
90 invars = regexp(rest, '\((.*)\)', 'tokens'); | |
91 if ~isempty(invars) | |
92 invars = regexp(invars{1}, '\s*,\s*', 'split'); | |
93 invars = invars{1}; | |
94 for kk=1:numel(invars) | |
95 % remove leading [ and trailing ] | |
96 iv = strtrim(invars{kk}); | |
97 if ~isempty(iv) | |
98 if invars{kk}(1) == '[' && invars{kk}(end) == ']' | |
99 invars{kk} = invars{kk}(2:end-1); | |
100 end | |
101 else | |
102 invars{kk} = iv; | |
103 end | |
104 end | |
105 end | |
106 out.outvars = strtrim(outvars(cellfun(@(x) ~isempty(x),outvars))); | |
107 out.method = strtrim(method); | |
108 out.invars = strtrim(invars(cellfun(@(x) ~isempty(x),invars))); | |
109 out.pls = strtrim(pls(cellfun(@(x) ~isempty(x),pls))); | |
110 out.comment = strtrim(cmt); | |
111 | |
112 end |