Mon, 28 May 2018 10:29:43 +0800
Merge
1 Parsing
3 - primtive types
4 - lists of various sorts
6 Basic models
8 prefix A,BCDF scans left-to-right
9 suffix ABCD:F scans right-to-left
11 Model 1:
12 data is sep,op,next,combine
14 if (sep found in data)
15 split data into prefix, rest
16 return combine( op(prefix), next(rest) )
17 else
18 return combine( default, next(data) )
20 pop = suffix1( ":", op3, op4, ++ )
21 op = prefix1( ",", op2, pop, ++ )
23 op( A,BDF.FGH:Z ) =
25 op2(A) ++ pop( BDF.FGH:Z ) =
26 op2(A) ++ op4( BDF.FGH ) ++ op3( Z )
28 Model 2:
29 data is sep,op,next,combine
31 if (sep found in data)
32 split data into prefix, rest
33 return combine( op(prefix), next(rest) )
34 else
35 return op(data)
37 example
38 op = prefix2( ":", op2, null, ++ )
39 op.setNext( op ) ;
41 op( A:B:C:D ) =
43 op2(A) ++ op2(B) ++ op2(C) ++ op2(D)
47 reduce( sep, initial, op, combine )
49 operate( data )
50 if (sep in data)
51 split data into prefix, rest
52 return combine( op(prefix), operate( rest ))
53 else
54 return combine( op(data), initial )
56 reduce( sep, op1, op2, initial, combine )
58 operate(data)
59 if (sep in data) // either first from left orfirst from right
60 split data into prefix, rest
61 return combine( op1( prefix ), op2( rest ) )
62 else
63 return opx( data )
65 type<X,Y>
66 class combine
67 init : X
68 add( X, Y ) : X
69 op1( String ) : X
70 op2( String ) : Y
72 reduce( sep, op1, op2, comb ) ( String ) : X
74 operate(data)
75 if (sep in data) // either first from left orfirst from right
76 split data into prefix, rest
77 return comb.add( op2.operate( rest ), op1.operate( prefix ) )
78 else
79 return comb.add( comb.init(), op1.operate( data ) )
81 example
83 op = reduce( ":", op1, null, comb )
84 op.setop2( op )
86 op.operate( "A:B:C" ) =
87 comb.add( op.operate( "B:C" ), op1.operate( "A" ) ) =
88 comb.add( comb.add( op.operate("C"), op1.operate("B") ), op1.operate( "A" ) =
89 comb.add( comb.add( comb.add( comb.init(), op1.operate("C") ), op1.operate("B") ),
90 op1.operate("A") )
93 Splitter interface
95 interface Splitter {
96 List split( String str )
97 }
99 variations:
100 - separated list SL
101 - first sep rest FSR
102 - fail if not present one arg
103 - default value two args
104 - rest sep last RSL
105 - fail if not present one arg
106 - default value two args
108 Have we just pushed the real problem off a level?
110 How do we combine:
111 op1 = FSR("@",v12)
112 op2 = LSR(":",9090)
114 str = 1.2@myhost:2345
116 op1(str) = ( "1.2" "myhost:2345" )
118 define splice( int index, Operator op ) on a list of strings, with op( String ) : (String)
119 to replace the indexth element of a list of strings with the list returned
120 from op( element ).
122 compose( op1, splice( 1, op2 )) is the correct parser.
125 A grammar for parsers?
127 parser : simple_parser
128 | parser ":" simple_parser ;
130 simple_parser : ident
131 | ident "(" param_list ")" ;
133 param_list : param
134 | param_list "," param ;
136 param : constant
137 | parser ;
139 constant is a Java constant
140 ident x is interpreted as either a public static method on OperationFactory
141 named xAction which takes as arguments the types of the param list, or as
142 the fully qualified class name of a class that implements Operation and has
143 a constructor which takes as arguments the types of the param list.
145 From parser table:
147 debugFlags string
148 ORBInitialHost string
149 ORBInitialPort integer
150 ORBServerHost string
151 ORBServerPort integer
152 orbId string
153 highWaterMark integer
154 lowWaterMark integer
155 etc.
157 giopVersion construct(GIOPVersion.class):map(integer):list('.')
158 giopFragmentSize mod(ORBConstants.GIOP_FRAGMENT_DIVISOR):min(ORBConstants.GIOP_FRAGMENT_SIZE):integer
160 Lisp notation:
161 parse((mod ORBConstants.GIOP_FRAGMENT_DIVISOR) (min ...) (integer))
163 giop11BuffMgr makeMap(map) where map is constructed in java with
164 map.get("GROW") = Integer(0)
165 map.get("CLCT") = Integer(1)
166 map.get("STRM") = Integer(2)
168 giopTargetAddressPreference intToShort:integerRange(0,3)
169 giopAddressDisposition another map variant
171 charData construct(CodeSetComponentInfo.class):string
174 What about corbaloc:?
176 v12 = GIOPVersion.v12 ;
178 giopVersion = construct( GIOPVersion.class ):mapSequence( [integer,integer] ):FSR(".")
180 iiopAddress = mapSequence( [giopVersion,identity,integer] ):
181 splice( 1, LSR( ":" 9090 )):
182 FSR( "@", v12 )
184 addressHandler = choice(
185 "iiop:", iiopAddress
186 ":", iiopAddress
187 )
189 addressList = map(addressHandler):SL(",")
191 choice(
192 "corbaloc:", mapSequence( [addressList,string] ):RSL("/", "NameService"),
193 "corbaname:", ...
194 )