tur/parser
scscm-cstr-eq?
(scscm-cstr-eq? [a :cstr b :cstr])
lex-err?
(lex-err? [r :ptr<void>])
lex-ok-val
(lex-ok-val [r :ptr<void>])
lex-err
(lex-err [e :int])
lex-ok
(lex-ok [x :int])
token-type
(token-type [tok :int])
token-value
(token-value [tok :int])
scscm-ast-leaf
(scscm-ast-leaf [kind :int value :cstr])
allocate a leaf AST node with a value string.
scscm-ast-list-node
(scscm-ast-list-node [kind :int])
allocate a composite AST node (list or vector).
scscm-ast-add-child
(scscm-ast-add-child [node :int child :int])
append a child handle to a composite node.
ast-kind
(ast-kind [node :int])
return the kind keyword string of an AST node.
| node | AST node handle |
One of ":atom" ":symbol" ":keyword" ":number" ":string" ":list" ":vector" ":quote" ":quasiquote" ":unquote" ":unquote-splice" ":hash-paren"
(ast-kind node) ; => ":symbol"
Since: SC1
ast-symbol-name
(ast-symbol-name [node :int])
return the raw symbol text of a symbol node.
| node | a ":symbol" AST node |
Symbol name as :cstr (e.g. "foo-bar").
(ast-symbol-name node) ; => "foo-bar"
Since: SC1
ast-number-value
(ast-number-value [node :int])
return the text representation of a number node.
| node | a ":number" AST node |
Number text as :cstr (e.g. "440", "0.5").
(ast-number-value node) ; => "440"
Since: SC1
ast-string-value
(ast-string-value [node :int])
return the contents of a string node (without quotes).
| node | a ":string" AST node |
String contents as :cstr (escape sequences preserved as-is from source).
(ast-string-value node) ; => "hello"
Since: SC1
ast-list-len
(ast-list-len [node :int])
return the number of children of a composite node.
| node | a ":list", ":vector", or wrapper node |
Child count as :int.
(ast-list-len node) ; => 3
Since: SC1
ast-list-get
(ast-list-get [node :int i :int])
return the i-th child (0-indexed) of a composite node.
| node | a ":list", ":vector", or wrapper node | |
| i | 0-based child index |
Child node handle as :int.
(ast-list-get node 0) ; => first child handle
Since: SC1
scscm-ast-value
(scscm-ast-value [node :int])
ast-free
(ast-free [node :int])
free one AST node and all its children recursively.
| node | AST node handle (may be 0/nil) |
(ast-free node)
Since: SC1
ast-free-all
(ast-free-all [nodes :int])
free every AST node in a cons list plus the list cells.
| nodes | cons list of AST node handles |
(ast-free-all top-level-forms)
Since: SC1
scscm-parse-list-body
(scscm-parse-list-body [tokens :int node :int close-ttyp :cstr])
scscm-parse-wrapper
(scscm-parse-wrapper [kind :int tokens :int])
scscm-parse-all
(scscm-parse-all [tokens :int acc :int])
scscm-parse-form
(scscm-parse-form [tokens :int])
parse
(parse [tokens :int])
parse a token cons list into a cons list of top-level AST nodes.
| tokens | cons list of token handles returned by tokenize |
lex-ok(nodes :int) where nodes is a cons list of AST node handles. lex-err(msg-int :int) on parse error (msg-int is a :cstr cast to :int).
(let [r (tokenize "(+ 1 2)")]
(if (lex-ok? r) (parse (lex-ok-val r)) (lex-err-val r)))
Since: SC1