compiler: Flesh Out CST Visitor Framework
As a use case, use it to implement text serialization of the CST. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -46,5 +46,30 @@ import TreeSitterP4
|
||||
let v = CSTTextSerializer()
|
||||
let c = CSTTextSerializerContext();
|
||||
let vd = CSTVisitorDriver();
|
||||
#expect(#RequireOkResult((vd.visit(program: program, visitor: v, context: c))))
|
||||
let result = try #UseOkResult((vd.start(program: program, visitor: v, context: c)))
|
||||
|
||||
let expected = """
|
||||
Parser Expression
|
||||
State: Direct Transition
|
||||
Statements:
|
||||
Expression Statement:
|
||||
Literal Expression
|
||||
Next State:
|
||||
Identifier: accept
|
||||
State: Select Transition
|
||||
Select Expression:
|
||||
Selector:
|
||||
Literal Expression
|
||||
Case Expressions:
|
||||
Case Expression:
|
||||
Keyset Expression:
|
||||
Next State:
|
||||
Identifier: accept
|
||||
Case Expression:
|
||||
Keyset Expression:
|
||||
Next State:
|
||||
Identifier: reject
|
||||
|
||||
"""
|
||||
#expect(result.serialized == expected)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user