Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fift language #2249

Merged
merged 4 commits into from Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pygments/lexers/_mapping.py
Expand Up @@ -159,6 +159,7 @@
'FantomLexer': ('pygments.lexers.fantom', 'Fantom', ('fan',), ('*.fan',), ('application/x-fantom',)),
'FelixLexer': ('pygments.lexers.felix', 'Felix', ('felix', 'flx'), ('*.flx', '*.flxh'), ('text/x-felix',)),
'FennelLexer': ('pygments.lexers.lisp', 'Fennel', ('fennel', 'fnl'), ('*.fnl',), ()),
'FiftLexer': ('pygments.lexers.fift', 'Fift', ('fift', 'fif'), ('*.fif',), ()),
'FishShellLexer': ('pygments.lexers.shell', 'Fish', ('fish', 'fishshell'), ('*.fish', '*.load'), ('application/x-fish',)),
'FlatlineLexer': ('pygments.lexers.dsls', 'Flatline', ('flatline',), (), ('text/x-flatline',)),
'FloScriptLexer': ('pygments.lexers.floscript', 'FloScript', ('floscript', 'flo'), ('*.flo',), ()),
Expand Down
65 changes: 65 additions & 0 deletions pygments/lexers/fift.py
@@ -0,0 +1,65 @@
"""
pygments.lexers.fift
~~~~~~~~~~~~~~~~~~~~

Lexers for fift.

:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""

from pygments.lexer import RegexLexer, include, words
from pygments.token import Literal, Comment, Name, String, \
Number, Whitespace

__all__ = ['FiftLexer']


class FiftLexer(RegexLexer):
"""
For Fift source code.
"""

name = 'Fift'
aliases = ['fift', 'fif']
filenames = ['*.fif']

dvlkv marked this conversation as resolved.
Show resolved Hide resolved
tokens = {
'root': [
(r'\s+', Whitespace),

include('comments'),

# allow escapes in strings
(r'\"([^\"\r\n\\]|\\.)*\"', String),
dvlkv marked this conversation as resolved.
Show resolved Hide resolved

# print string literal
(r'\.\"([^\"\r\n\\]|\\.)*\"', String),
dvlkv marked this conversation as resolved.
Show resolved Hide resolved

# numbers
(r'-?[0-9]+("/"-?[0-9]+)?', Number.Dec),
dvlkv marked this conversation as resolved.
Show resolved Hide resolved
(r'0[xX][0-9a-fA-F]+', Number.Hex),
dvlkv marked this conversation as resolved.
Show resolved Hide resolved
(r'0[bB][01]+', Number.Bin),
dvlkv marked this conversation as resolved.
Show resolved Hide resolved

# slices
(r'b\{[01]+\}', Literal),
(r'x\{[0-9a-fA-F_]+\}', Literal),

# byte literal
(r'B\{[0-9a-fA-F_]+\}', Literal),
dvlkv marked this conversation as resolved.
Show resolved Hide resolved

# treat anything as word
(r'\S+', Name)
dvlkv marked this conversation as resolved.
Show resolved Hide resolved
],

'comments': [
(r'//.*', Comment.Singleline),
(r'/\*', Comment.Multiline, 'comment'),
],
'comment': [
(r'[^/*]+', Comment.Multiline),
(r'/\*', Comment.Multiline, '#push'),
(r'\*/', Comment.Multiline, '#pop'),
(r'[*/]', Comment.Multiline),
],
}
42 changes: 42 additions & 0 deletions tests/examplefiles/fift/new-wallet-v3.fif
@@ -0,0 +1,42 @@
"TonUtil.fif" include
"Asm.fif" include

{ ."usage: " $0 type ." <workchain-id> <wallet-id> [<filename-base>]" cr
."Creates a new advanced wallet with unique 32-bit identifier <wallet-id> in specified workchain, with private key saved to or loaded from <filename-base>.pk" cr
."('new-wallet.pk' by default)" cr 1 halt
} : usage
$# 2- -2 and ' usage if

3 :$1..n
$1 parse-workchain-id =: wc // set workchain id from command line argument
$2 parse-int =: subwallet-id
$3 "new-wallet" replace-if-null =: file-base

."Creating new advanced v3 wallet in workchain " wc . cr
."with unique wallet id " subwallet-id . cr

// Create new advanced wallet; code adapted from `auto/wallet3-code.fif`
"wallet-v3-code.fif" include
// >libref
// code
<b 0 32 u, subwallet-id 32 u,
file-base +".pk" load-generate-keypair
constant wallet_pk
B,
b> // data
null // no libraries
<b b{0011} s, 3 roll ref, rot ref, swap dict, b> // create StateInit
dup ."StateInit: " <s csr. cr
dup hashu wc swap 2dup 2constant wallet_addr
."new wallet address = " 2dup .addr cr
2dup file-base +".addr" save-address-verbose
."Non-bounceable address (for init): " 2dup 7 .Addr cr
."Bounceable address (for later access): " 6 .Addr cr
<b subwallet-id 32 u, -1 32 i, 0 32 u, b>
dup ."signing message: " <s csr. cr
dup hashu wallet_pk ed25519_sign_uint rot
<b b{1000100} s, wallet_addr addr, b{000010} s, swap <s s, b{0} s, swap B, swap <s s, b>
dup ."External message for initialization is " <s csr. cr
2 boc+>B dup Bx. cr
file-base +"-query.boc" tuck B>file
."(Saved wallet creating query to file " type .")" cr