Skip to content

Commit

Permalink
Add Hare lexer (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
triallax authored Nov 28, 2023
1 parent 2346007 commit d77dc8a
Show file tree
Hide file tree
Showing 4 changed files with 390 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ translators for Pygments lexers and styles.
| E | EBNF, Elixir, Elm, EmacsLisp, Erlang |
| F | Factor, Fennel, Fish, Forth, Fortran, FortranFixed, FSharp |
| G | GAS, GDScript, Genshi, Genshi HTML, Genshi Text, Gherkin, GLSL, Gnuplot, Go, Go HTML Template, Go Text Template, GraphQL, Groff, Groovy |
| H | Handlebars, Haskell, Haxe, HCL, Hexdump, HLB, HLSL, HolyC, HTML, HTTP, Hy |
| H | Handlebars, Hare, Haskell, Haxe, HCL, Hexdump, HLB, HLSL, HolyC, HTML, HTTP, Hy |
| I | Idris, Igor, INI, Io, ISCdhcpd |
| J | J, Java, JavaScript, JSON, Julia, Jungle |
| K | Kotlin |
Expand Down
98 changes: 98 additions & 0 deletions lexers/embedded/hare.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<lexer>
<config>
<name>Hare</name>
<alias>hare</alias>
<filename>*.ha</filename>
<mime_type>text/x-hare</mime_type>
</config>
<rules>
<state name="string">
<rule pattern="&quot;">
<token type="LiteralString"/>
<pop depth="1"/>
</rule>
<rule pattern="\\([\\0abfnrtv&quot;']|x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8})">
<token type="LiteralStringEscape"/>
</rule>
<rule pattern="[^\\&quot;\n]+">
<token type="LiteralString"/>
</rule>
<rule pattern="\\">
<token type="LiteralString"/>
</rule>
</state>
<state name="root">
<rule pattern="[\s\n]+">
<token type="TextWhitespace"/>
</rule>
<rule pattern="@[a-z]+">
<token type="NameDecorator"/>
</rule>
<rule pattern="//.*\n">
<token type="CommentSingle"/>
</rule>
<rule pattern="&quot;">
<token type="LiteralString"/>
<push state="string"/>
</rule>
<rule pattern="`[^`]*`">
<token type="LiteralString"/>
</rule>
<rule pattern="'(\\[\\0abfnrtv&quot;']||\\(x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8})|[^\\'])'">
<token type="LiteralStringChar"/>
</rule>
<rule pattern="(0|[1-9]\d*)\.\d+([eE][+-]?\d+)?(f32|f64)?">
<token type="LiteralNumberFloat"/>
</rule>
<rule pattern="(0|[1-9]\d*)([eE][+-]?\d+)?(f32|f64)">
<token type="LiteralNumberFloat"/>
</rule>
<rule pattern="0x[0-9a-fA-F]+\.[0-9a-fA-F]+([pP][+-]?\d+(f32|f64)?)?">
<token type="LiteralNumberFloat"/>
</rule>
<rule pattern="0x[0-9a-fA-F]+[pP][+-]?\d+(f32|f64)">
<token type="LiteralNumberFloat"/>
</rule>
<rule pattern="0x[0-9a-fA-F]+(z|[iu](8|16|32|64)?)?">
<token type="LiteralNumberHex"/>
</rule>
<rule pattern="0o[0-7]+(z|[iu](8|16|32|64)?)?">
<token type="LiteralNumberOct"/>
</rule>
<rule pattern="0b[01]+(z|[iu](8|16|32|64)?)?">
<token type="LiteralNumberBin"/>
</rule>
<rule pattern="(0|[1-9]\d*)([eE][+-]?\d+)?(z|[iu](8|16|32|64)?)?">
<token type="LiteralNumberInteger"/>
</rule>
<rule pattern="[~!%^&amp;*+=|?:&lt;&gt;/-]|[ai]s\b|\.\.\.">
<token type="Operator"/>
</rule>
<rule pattern="[()\[\],.{};]">
<token type="Punctuation"/>
</rule>
<rule pattern="use\b">
<token type="KeywordNamespace"/>
</rule>
<rule pattern="(_|align|break|const|continue|else|enum|export|for|if|return|static|struct|offset|union|fn|free|assert|abort|alloc|let|len|def|type|match|switch|case|append|delete|insert|defer|yield|vastart|vaarg|vaend)\b">
<token type="Keyword"/>
</rule>
<rule pattern="(size)([\s\n]*)(\()">
<bygroups>
<token type="Keyword" />
<token type="TextWhitespace" />
<token type="Punctuation" />
</bygroups>
</rule>
<rule pattern="(str|size|rune|bool|int|uint|uintptr|u8|u16|u32|u64|i8|i16|i32|i64|f32|f64|null|void|nullable|valist|opaque|never)\b">
<token type="KeywordType"/>
</rule>
<rule pattern="(true|false)\b">
<token type="NameBuiltin"/>
</rule>
<rule pattern="[a-zA-Z_]\w*">
<token type="Name"/>
</rule>
</state>
</rules>
</lexer>
32 changes: 32 additions & 0 deletions lexers/testdata/hare.actual
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// test comment
use bufio::*;
use fmt, os::exec = exec;
use time;

type foo = struct {
bar: str,
baz: time::duration,
};

export type e = enum u8 {
a, b, c
};

const arr: [_]foo= [
foo { bar = "This is a \"string\"!", baz = 25 * time::MINUTE },
foo { bar = `This is also a
string`, baz = 5 * time::SECOND},
];

let c = 'a'; // char
let d = 0b1010u16;
let e: size = 32z;
let g = 0xffa31u32 + 0o3u32;

export fn main() void = {
fmt::println("{}", size(int))!;

for (let i = 0z; i < 5; i += 1) {
fmt::println("{}", i);
};
};
Loading

0 comments on commit d77dc8a

Please sign in to comment.