KlynParser
classin packageklyn.code.klyn
public class KlynParser extends Object
└ KlynParser

Lightweight structural parser for Klyn source code (.kn).

Extracts package headers, imports, classes, interfaces, enums, structs, records, annotations, constructors, methods, operators, properties, signals, events, fields, and KlynDoc documentation blocks into a hierarchical list of DeclarationNode objects with accurate SourceRange line spans. Used by KlynDoc, KlynMetrik, TestSourceScanner, and KlynEditor outline views.

import klyn.code.klyn

code = "package demo\n\npublic class Greeter:\n    public greet(name as String) as String:\n        return f\"Hello {name}\"\n"
declarations = KlynParser.parseDeclarations(code)
assert declarations.size == 1
assert declarations[0].name == "Greeter"
assert declarations[0].children.size == 1
assert declarations[0].children[0].name == "greet"
Inherited Properties
propertyInherited Properties from Object: type
Methods
Modifier and Type Member Description
public static isValidPackageName
isValidPackageName(value as String) as Boolean
Checks whether value is a syntactically valid Klyn dot-separated package identifier.
public static parseDeclarations
parseDeclarations(source as String, publicOnly as Boolean = false) as ArrayList<DeclarationNode>
Parses top-level type and callable declarations from Klyn source into a hierarchy of DeclarationNodes (classes/interfaces/enums/annotations contain their fields, properties, signals, events, constructors, methods, and operators).
public static parseImports
parseImports(source as String) as ArrayList<String>
Extracts all imported package names from a Klyn source file.
public static parsePackageName
parsePackageName(source as String) as String
Extracts the package name declared at the top of a Klyn source file, or "" if none.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, hash, toDict, toJson, toMap, toString, toXml