wasCSharpSQLite – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | #undef DEBUG |
2 | /* |
||
3 | * ParseAdaptor.java -- |
||
4 | * |
||
5 | * Temporary adaptor class that creates the interface from the |
||
6 | * current expression parser to the new Parser class. |
||
7 | * |
||
8 | * Copyright (c) 1997 by Sun Microsystems, Inc. |
||
9 | * |
||
10 | * See the file "license.terms" for information on usage and redistribution |
||
11 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
||
12 | * |
||
13 | * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart |
||
14 | * |
||
15 | * RCS @(#) $Id: ParseAdaptor.java,v 1.6 2003/02/05 09:24:40 mdejong Exp $ |
||
16 | */ |
||
17 | using System; |
||
18 | namespace tcl.lang |
||
19 | { |
||
20 | |||
21 | class ParseAdaptor |
||
22 | { |
||
23 | internal static ParseResult parseVar( Interp interp, string inString, int index, int length ) |
||
24 | { |
||
25 | ParseResult result; |
||
26 | |||
27 | index--; |
||
28 | result = Parser.parseVar( interp, inString.Substring( index, ( length ) - ( index ) ) ); |
||
29 | result.nextIndex += index; |
||
30 | return ( result ); |
||
31 | } |
||
32 | internal static ParseResult parseNestedCmd( Interp interp, string inString, int index, int length ) |
||
33 | { |
||
34 | CharPointer script; |
||
35 | TclObject obj; |
||
36 | |||
37 | // Check for the easy case where the last character in the string is '['. |
||
38 | if ( index == length ) |
||
39 | { |
||
40 | throw new TclException( interp, "missing close-bracket" ); |
||
41 | } |
||
42 | |||
43 | script = new CharPointer( inString ); |
||
44 | script.index = index; |
||
45 | |||
46 | interp.evalFlags |= Parser.TCL_BRACKET_TERM; |
||
47 | Parser.eval2( interp, script.array, script.index, length - index, 0 ); |
||
48 | obj = interp.getResult(); |
||
49 | obj.preserve(); |
||
50 | return ( new ParseResult( obj, index + interp.termOffset + 1 ) ); |
||
51 | } |
||
52 | internal static ParseResult parseQuotes( Interp interp, string inString, int index, int length ) |
||
53 | { |
||
54 | TclObject obj; |
||
55 | TclParse parse = null; |
||
56 | TclToken token; |
||
57 | CharPointer script; |
||
58 | |||
59 | try |
||
60 | { |
||
61 | |||
62 | script = new CharPointer( inString ); |
||
63 | script.index = index; |
||
64 | |||
65 | parse = new TclParse( interp, script.array, length, null, 0 ); |
||
66 | |||
67 | System.Diagnostics.Debug.WriteLine( "string is \"" + inString + "\"" ); |
||
68 | System.Diagnostics.Debug.WriteLine( "script.array is \"" + new string( script.array ) + "\"" ); |
||
69 | |||
70 | System.Diagnostics.Debug.WriteLine( "index is " + index ); |
||
71 | System.Diagnostics.Debug.WriteLine( "length is " + length ); |
||
72 | |||
73 | System.Diagnostics.Debug.WriteLine( "parse.endIndex is " + parse.endIndex ); |
||
74 | |||
75 | |||
76 | parse.commandStart = script.index; |
||
77 | token = parse.getToken( 0 ); |
||
78 | token.type = Parser.TCL_TOKEN_WORD; |
||
79 | token.script_array = script.array; |
||
80 | token.script_index = script.index; |
||
81 | parse.numTokens++; |
||
82 | parse.numWords++; |
||
83 | parse = Parser.parseTokens( script.array, script.index, Parser.TYPE_QUOTE, parse ); |
||
84 | |||
85 | // Check for the error condition where the parse did not end on |
||
86 | // a '"' char. Is this happened raise an error. |
||
87 | |||
88 | if ( script.array[parse.termIndex] != '"' ) |
||
89 | { |
||
90 | throw new TclException( interp, "missing \"" ); |
||
91 | } |
||
92 | |||
93 | // if there was no error then parsing will continue after the |
||
94 | // last char that was parsed from the string |
||
95 | |||
96 | script.index = parse.termIndex + 1; |
||
97 | |||
98 | // Finish filling in the token for the word and check for the |
||
99 | // special case of a word consisting of a single range of |
||
100 | // literal text. |
||
101 | |||
102 | token = parse.getToken( 0 ); |
||
103 | token.size = script.index - token.script_index; |
||
104 | token.numComponents = parse.numTokens - 1; |
||
105 | if ( ( token.numComponents == 1 ) && ( parse.getToken( 1 ).type == Parser.TCL_TOKEN_TEXT ) ) |
||
106 | { |
||
107 | token.type = Parser.TCL_TOKEN_SIMPLE_WORD; |
||
108 | } |
||
109 | parse.commandSize = script.index - parse.commandStart; |
||
110 | if ( parse.numTokens > 0 ) |
||
111 | { |
||
112 | obj = Parser.evalTokens( interp, parse.tokenList, 1, parse.numTokens - 1 ); |
||
113 | } |
||
114 | else |
||
115 | { |
||
116 | throw new TclRuntimeError( "parseQuotes error: null obj result" ); |
||
117 | } |
||
118 | } |
||
119 | finally |
||
120 | { |
||
121 | parse.release(); |
||
122 | } |
||
123 | |||
124 | return ( new ParseResult( obj, script.index ) ); |
||
125 | } |
||
126 | internal static ParseResult parseBraces( Interp interp, string str, int index, int length ) |
||
127 | { |
||
128 | char[] arr = str.ToCharArray(); |
||
129 | int level = 1; |
||
130 | |||
131 | for ( int i = index; i < length; ) |
||
132 | { |
||
133 | if ( Parser.charType( arr[i] ) == Parser.TYPE_NORMAL ) |
||
134 | { |
||
135 | i++; |
||
136 | } |
||
137 | else if ( arr[i] == '}' ) |
||
138 | { |
||
139 | level--; |
||
140 | if ( level == 0 ) |
||
141 | { |
||
142 | str = new string( arr, index, i - index ); |
||
143 | return new ParseResult( str, i + 1 ); |
||
144 | } |
||
145 | i++; |
||
146 | } |
||
147 | else if ( arr[i] == '{' ) |
||
148 | { |
||
149 | level++; |
||
150 | i++; |
||
151 | } |
||
152 | else if ( arr[i] == '\\' ) |
||
153 | { |
||
154 | BackSlashResult bs = Parser.backslash( arr, i ); |
||
155 | i = bs.nextIndex; |
||
156 | } |
||
157 | else |
||
158 | { |
||
159 | i++; |
||
160 | } |
||
161 | } |
||
162 | |||
163 | //if you run off the end of the string you went too far |
||
164 | throw new TclException( interp, "missing close-brace" ); |
||
165 | } |
||
166 | } // end ParseAdaptor |
||
167 | } |