@@ -7,7 +7,18 @@ const lastLineTypeMessage = (raw: string) => {
77 return { type : m ? m [ 1 ] : null , message : m ? m [ 2 ] : tail , tail, lines } ;
88} ;
99
10- export const skulptAdapter : AdapterFn = ( raw , code ) => {
10+ /**
11+ * Parses a CPython-shaped traceback (`File "...", line N`).
12+ *
13+ * Skulpt and Pyodide both emit this format, so a single adapter covers both.
14+ * There is no current need for runtime-specific parsing . The `runtime` label on
15+ * the returned trace is left as "unknown"; the engine adds the concrete runtime
16+ * (the registration key it dispatched on) in `coerceTrace`. If the two runtimes
17+ * ever diverge (e.g CPython 3.11+ caret ranges or "Did you mean?" hints that
18+ * Pyodide surfaces but Skulpt does not), branch here on a passed-in runtime
19+ * hint to parse those features out of the message
20+ */
21+ export const cpythonAdapter : AdapterFn = ( raw , code ) => {
1122 const { type, message, tail, lines } = lastLineTypeMessage ( raw ) ;
1223 let file : string | undefined , line : number | undefined , col : number | undefined ;
1324
@@ -17,6 +28,8 @@ export const skulptAdapter: AdapterFn = (raw, code) => {
1728 file = mm [ 1 ] ;
1829 line = parseInt ( mm [ 2 ] , 10 ) ;
1930 }
31+ const cc = L . match ( / c o l u m n \s + ( \d + ) / i) ;
32+ if ( cc ) col = parseInt ( cc [ 1 ] , 10 ) ;
2033 }
2134 if ( ! line ) {
2235 const loc = tail . match ( / \b (?: o n | a t ) \s + l i n e \s + ( \d + ) \s + (?: o f | i n ) \s + ( [ ^ \s : ] + ) \b / i) ;
@@ -38,7 +51,7 @@ export const skulptAdapter: AdapterFn = (raw, code) => {
3851 // - name: quoted symbol from the message (helpful for NameError/KeyError/etc.)
3952 //
4053 // If none are present, the input is not parseable enough for this adapter,
41- // so we return null and let the caller handle that failure explicitly.
54+ // so we return null and let the caller handle that failure explicitly
4255 const hasStructuredSignal = Boolean ( type || line || name ) ;
4356 if ( ! hasStructuredSignal ) return null ;
4457
@@ -51,7 +64,7 @@ export const skulptAdapter: AdapterFn = (raw, code) => {
5164 col,
5265 frames : [ ] ,
5366 name,
54- runtime : "skulpt "
67+ runtime : "unknown "
5568 } ;
5669
5770 if ( code && line ) {
0 commit comments