1// Copyright (C) 2025 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import {language} from './language.js'; 16import {TreeCursor} from '@lezer/common'; 17 18// Helper function to pretty-print the CST 19function printCST(cursor: TreeCursor, source: string, indent = 0) { 20 const nodeName = cursor.name; 21 const nodeText = source.substring(cursor.from, cursor.to); 22 23 console.log(`${' '.repeat(indent)}${nodeName}: "${nodeText}"`); 24 25 if (cursor.firstChild()) { 26 do { 27 printCST(cursor, source, indent + 1); 28 } while (cursor.nextSibling()); 29 cursor.parent(); // Important: Move back up to the parent 30 } 31} 32 33describe('perfettoSqlLang', () => { 34 test('simple', () => { 35 const code = 'select * from slice limit 100'; 36 const tree = language.parser.parse(code); 37 const cursor = tree.cursor(); 38 const spec = ['Keyword', 'identifier', 'Keyword', 'identifier']; 39 console.log(printCST(cursor, code), spec); 40 }); 41}); 42