Skip to content

Commit 57c1bd9

Browse files
authored
Added pony lexer (#372)
1 parent 500529f commit 57c1bd9

File tree

3 files changed

+682
-0
lines changed

3 files changed

+682
-0
lines changed

lexers/p/pony.go

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package p
2+
3+
import (
4+
. "github.com/alecthomas/chroma" // nolint
5+
"github.com/alecthomas/chroma/lexers/internal"
6+
)
7+
8+
// Pony lexer.
9+
var Pony = internal.Register(MustNewLexer(
10+
&Config{
11+
Name: "Pony",
12+
Aliases: []string{"pony"},
13+
Filenames: []string{"*.pony"},
14+
MimeTypes: []string{},
15+
},
16+
Rules{
17+
"root": {
18+
{`\n`, Text, nil},
19+
{`[^\S\n]+`, Text, nil},
20+
{`//.*\n`, CommentSingle, nil},
21+
{`/\*`, CommentMultiline, Push("nested_comment")},
22+
{`"""(?:.|\n)*?"""`, LiteralStringDoc, nil},
23+
{`"`, LiteralString, Push("string")},
24+
{`\'.*\'`, LiteralStringChar, nil},
25+
{`=>|[]{}:().~;,|&!^?[]`, Punctuation, nil},
26+
{Words(``, `\b`, `addressof`, `and`, `as`, `consume`, `digestof`, `is`, `isnt`, `not`, `or`), OperatorWord, nil},
27+
{`!=|==|<<|>>|[-+/*%=<>]`, Operator, nil},
28+
{Words(``, `\b`, `box`, `break`, `compile_error`, `compile_intrinsic`, `continue`, `do`, `else`, `elseif`, `embed`, `end`, `error`, `for`, `if`, `ifdef`, `in`, `iso`, `lambda`, `let`, `match`, `object`, `recover`, `ref`, `repeat`, `return`, `tag`, `then`, `this`, `trn`, `try`, `until`, `use`, `var`, `val`, `where`, `while`, `with`, `#any`, `#read`, `#send`, `#share`), Keyword, nil},
29+
{`(actor|class|struct|primitive|interface|trait|type)((?:\s)+)`, ByGroups(Keyword, Text), Push("typename")},
30+
{`(new|fun|be)((?:\s)+)`, ByGroups(Keyword, Text), Push("methodname")},
31+
{Words(``, `\b`, `U8`, `U16`, `U32`, `U64`, `ULong`, `USize`, `U128`, `Unsigned`, `Stringable`, `String`, `StringBytes`, `StringRunes`, `InputNotify`, `InputStream`, `Stdin`, `ByteSeq`, `ByteSeqIter`, `OutStream`, `StdStream`, `SourceLoc`, `I8`, `I16`, `I32`, `I64`, `ILong`, `ISize`, `I128`, `Signed`, `Seq`, `RuntimeOptions`, `Real`, `Integer`, `SignedInteger`, `UnsignedInteger`, `FloatingPoint`, `Number`, `Int`, `ReadSeq`, `ReadElement`, `Pointer`, `Platform`, `NullablePointer`, `None`, `Iterator`, `F32`, `F64`, `Float`, `Env`, `DoNotOptimise`, `DisposableActor`, `Less`, `Equal`, `Greater`, `Compare`, `HasEq`, `Equatable`, `Comparable`, `Bool`, `AsioEventID`, `AsioEventNotify`, `AsioEvent`, `Array`, `ArrayKeys`, `ArrayValues`, `ArrayPairs`, `Any`, `AmbientAuth`), KeywordType, nil},
32+
{`_?[A-Z]\w*`, NameClass, nil},
33+
{`string\(\)`, NameOther, nil},
34+
{`(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+`, LiteralNumberFloat, nil},
35+
{`0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
36+
{`\d+`, LiteralNumberInteger, nil},
37+
{`(true|false)\b`, Keyword, nil},
38+
{`_\d*`, Name, nil},
39+
{`_?[a-z][\w\'_]*`, Name, nil},
40+
},
41+
"typename": {
42+
{`(iso|trn|ref|val|box|tag)?((?:\s)*)(_?[A-Z]\w*)`, ByGroups(Keyword, Text, NameClass), Pop(1)},
43+
},
44+
"methodname": {
45+
{`(iso|trn|ref|val|box|tag)?((?:\s)*)(_?[a-z]\w*)`, ByGroups(Keyword, Text, NameFunction), Pop(1)},
46+
},
47+
"nested_comment": {
48+
{`[^*/]+`, CommentMultiline, nil},
49+
{`/\*`, CommentMultiline, Push()},
50+
{`\*/`, CommentMultiline, Pop(1)},
51+
{`[*/]`, CommentMultiline, nil},
52+
},
53+
"string": {
54+
{`"`, LiteralString, Pop(1)},
55+
{`\\"`, LiteralString, nil},
56+
{`[^\\"]+`, LiteralString, nil},
57+
},
58+
},
59+
))

lexers/testdata/pony.actual

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
use "net"
2+
use "files"
3+
4+
class ClientSide is TCPConnectionNotify
5+
let _env: Env
6+
7+
new iso create(env: Env) =>
8+
_env = env
9+
10+
fun ref connecting(conn: TCPConnection ref, count: U32) =>
11+
_env.out.print("connecting: " + count.string())
12+
13+
fun ref connected(conn: TCPConnection ref) =>
14+
try
15+
(let host, let service) = conn.remote_address().name()?
16+
_env.out.print("connected to " + host + ":" + service)
17+
conn.set_nodelay(true)
18+
conn.set_keepalive(10)
19+
conn.write("client says hi")
20+
end
21+
22+
class Listener is TCPListenNotify
23+
let _env: Env
24+
let _limit: USize
25+
var _host: String = ""
26+
var _count: USize = 0
27+
28+
new create(env: Env, limit: USize) =>
29+
_env = env
30+
_limit = limit
31+
32+
fun ref connected(listen: TCPListener ref): TCPConnectionNotify iso^ =>
33+
let env = _env
34+
35+
_env.out.print("Server starting")
36+
37+
let server = ServerSide(env)
38+
39+
_spawn(listen)
40+
server
41+
42+
fun ref _spawn(listen: TCPListener ref) =>
43+
if (_limit > 0) and (_count >= _limit) then
44+
listen.dispose()
45+
return
46+
end
47+
48+
_count = _count + 1
49+
_env.out.print("spawn " + _count.string())
50+
51+
try
52+
let env = _env
53+
54+
_env.out.print("Client starting")
55+
TCPConnection(
56+
_env.root as AmbientAuth,
57+
ClientSide(env),
58+
_host,
59+
_service)
60+
else
61+
_env.out.print("couldn't create client side")
62+
listen.close()
63+
end
64+
65+
actor Main
66+
new create(env: Env) =>
67+
let limit = try
68+
env.args(1)?.usize()?
69+
else
70+
1
71+
end
72+
73+
try
74+
let auth = env.root as AmbientAuth
75+
TCPListener(auth, recover Listener(env, limit) end)
76+
UDPSocket(auth, recover Pong(env) end)
77+
else
78+
env.out.print("unable to use the network")
79+
end
80+
be test() =>
81+
nonsensical.stuff.here()
82+

0 commit comments

Comments
 (0)