c

Parse C.

In this module:

Language

Name (Aliases)

Description

Filename(s)

Mime Type(s)

C

C (c, cpp)

C/C++ programming language

*.[ch], *.[ch]pp, *.cc, *.hh

text/x-c

class C[source]

Bases: parce.language.Language

root

All C language constructs.

compound

Stuff between {}.

paren

Stuff between ().

arguments

Stuff between name().

class_name

The class name after struct, union or enum.

string

A double-quoted string.

macro

Stuff after #.

singleline_comment
multiline_comment

Example:

Root lexicon C.root and text:

Text rendered using default theme

#include <stdio.h>

int main(void)
{
    printf("hello, world\n");
}

Result tree:

<Context C.root at 0-68 (8 children)>
 ├╴<Token '#' at 0:1 (Delimiter.Preprocessed)>
 ├╴<Context C.macro at 1-18 (2 children)>
 │  ├╴<Token 'include' at 1:8 (Keyword.Preprocessed)>
 │  ╰╴<Token '<stdio.h>' at 9:18 (Literal.String.Template)>
 ├╴<Token 'int' at 20:23 (Name.Type)>
 ├╴<Token 'main' at 24:28 (Name.Function)>
 ├╴<Token '(' at 28:29 (Delimiter)>
 ├╴<Context C.arguments at 29-34 (2 children)>
 │  ├╴<Token 'void' at 29:33 (Keyword)>
 │  ╰╴<Token ')' at 33:34 (Delimiter)>
 ├╴<Token '{' at 35:36 (Delimiter.Bracket.Start)>
 ╰╴<Context C.compound at 41-68 (5 children)>
    ├╴<Token 'printf' at 41:47 (Name.Function)>
    ├╴<Token '(' at 47:48 (Delimiter)>
    ├╴<Context C.arguments at 48-65 (3 children)>
    │  ├╴<Token '"' at 48:49 (Literal.String.Start)>
    │  ├╴<Context C.string at 49-64 (3 children)>
    │  │  ├╴<Token 'hello, world' at 49:61 (Literal.String)>
    │  │  ├╴<Token '\\n' at 61:63 (Literal.String.Escape)>
    │  │  ╰╴<Token '"' at 63:64 (Literal.String.End)>
    │  ╰╴<Token ')' at 64:65 (Delimiter)>
    ├╴<Token ';' at 65:66 (Delimiter)>
    ╰╴<Token '}' at 67:68 (Delimiter.Bracket.End)>