рдирдорд╕реНрдХрд╛рд░, рдореЗрд░рд╛ рдирд╛рдо рджрд┐рдорд┐рддреНрд░реА рдХрд╛рд░реНрд▓реЛрд╡реНрд╕реНрдХреА рд╣реИ рдФрд░ рдореИрдВ ... рд╕рд╛рдЗрдХрд┐рд▓ рдкрд░ рд╡рд┐рджрд╛рд░рдХ ... рдСрдл-рд░реЛрдб ... рд╣рд╡рд╛ рдХреЗ рдЦрд┐рд▓рд╛рдл ... рд╕реНрдХреАрдЗрдВрдЧред рдФрд░ рдЖрдЬ рдореИрдВ рдЖрдкрдХреЛ рдЕрдкрдиреЗ рд╕рд╛рде рдкрд╛рда рдбреЗрдЯрд╛ рдкреНрд░рд╛рд░реВрдкреЛрдВ рдХреЗ рд╕рд╛рде рд╕рд╡рд╛рд░реА рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдЖрдордВрддреНрд░рд┐рдд рдХрд░рддрд╛ рд╣реВрдВ рдФрд░ рд╕рд╛рде рдореЗрдВ рдЖрджрд░реНрд╢ рдкреНрд░рд╛рд░реВрдк рдбрд┐рдЬрд╛рдЗрди рдХрд░рддрд╛ рд╣реВрдВред
рдореИрдВрдиреЗ 5 рд╕рд╛рд▓ рдкрд╣рд▓реЗ рд╣реА рдЗрд╕ рдмрд╛рд░реЗ рдореЗрдВ рдмрд╛рдд рдХреА рдереА, рдЬрд┐рд╕рдХреЗ рдХрд╛рд░рдг рдПрдХ рдЧрд░рдорд╛рдЧрд░рдо рдмрд╣рд╕ рд╣реБрдИ, рдЬрд┐рд╕рдиреЗ рд╡рд╛рдХреНрдпрд╡рд┐рдиреНрдпрд╛рд╕ рдореЗрдВ рдЫреЛрдЯреЗ рдмрджрд▓рд╛рд╡ рдХрд┐рдПред рдЗрд╕рд▓рд┐рдП, рдореБрдЭреЗ рдЦрд░реЛрдВрдЪ рд╕реЗ рдмрддрд╛рдПрдВ рдХрд┐ рдпрд╣ рд╡рд░реНрддрдорд╛рди рдореЗрдВ рдХреНрдпрд╛ рд╣реИред
\
\PiterJS #47
2020-05-20
рдпрд╣ PiterJS # 47 рдкрд░ рдЕрдирд╛рдо рдкреНрд░рджрд░реНрд╢рди рдХрд╛ рдПрдХ рд╡рд┐рд╕реНрддрд╛рд░рд┐рдд рдкрд╛рда рд╕рдВрд╕реНрдХрд░рдг рд╣реИ ред рдЖрдк рдЗрд╕реЗ рдПрдХ рд▓реЗрдЦ рдХреЗ рд░реВрдк рдореЗрдВ рдкрдврд╝ рд╕рдХрддреЗ рд╣реИрдВ , рдпрд╛ рдЗрд╕реЗ рдкреНрд░рд╕реНрддреБрддрд┐ рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдореЗрдВ рдЦреЛрд▓ рд╕рдХрддреЗ рд╣реИрдВ , рдпрд╛ рдПрдХ рд╡реАрдбрд┐рдпреЛ рджреЗрдЦ рд╕рдХрддреЗ рд╣реИрдВ ред
рдпреЛрдЬрдирд╛
- рд▓реЛрдХрдкреНрд░рд┐рдп рдкрд╛рда рдбреЗрдЯрд╛ рд╕реНрд╡рд░реВрдкреЛрдВ рдХрд╛ рд╡рд┐рд╢реНрд▓реЗрд╖рдг рдХрд░реЗрдВ
- рдЦрд░реЛрдВрдЪ рд╕реЗ, рджреЛрд╖реЛрдВ рдХреЗ рдмрд┐рдирд╛ рдПрдХ рдирдпрд╛ рдкреНрд░рд╛рд░реВрдк рд╡рд┐рдХрд╕рд┐рдд рдХрд░реЗрдВ
- рдирдпрд╛ рдкреНрд░рд╛рд░реВрдк рд▓рд╛рдЧреВ рдХрд░рдиреЗ рдХреЗ рдЙрджрд╛рд╣рд░рдг рджрд┐рдЦрд╛рдПрдВ
рд╣рдо 5 рдкреНрд░рд╛рд░реВрдкреЛрдВ рдХреА рддреБрд▓рдирд╛ рдХрд░реЗрдВрдЧреЗред
рдкрд╣рд▓реЗ рддреАрди рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рдХреЗрд╡рд▓ рдмрдзрд┐рд░реЛрдВ рдХреЛ рдирд╣реАрдВ рд╕реБрдирд╛ред рд▓реЗрдХрд┐рди рдХрдИ рд▓реЛрдЧреЛрдВ рдХреЗ рд▓рд┐рдП рдЕрдВрддрд┐рдо рджреЛ рдХрд╛рд▓реЗ рдШреЛрдбрд╝реЗ рд╣реИрдВред рдЦреИрд░, рдХреБрдЫ рдирд╣реАрдВ, рдЖрдЬ рдореИрдВ рдЙрди рдкрд░ рдкреНрд░рдХрд╛рд╢ рдбрд╛рд▓реВрдВрдЧрд╛ред
XML
XML тАФ , " ". , , -.
<!DOCTYPE svg
PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle r="30" cx="50" cy="50" fill="orange" />
</svg>
JSON
XML тАФ JSON.
{
"name": "example",
"version": "1.0.0",
"description": "example package",
"main": "index.js",
"repository": "https://example.org",
"author": "anonymous",
"license": "MIT"
}
, , , , .
YAML
- YAML JSON.
Date: 2001-11-23 15:03:17 -5
User: ed
Fatal:
Unknown variable "bar"
Where:
file: TopClass.py
line: 23
code: |
x = MoreObject("345\n")
.
TOML
TOML . , , .
[servers]
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"
, , INI-, JSON. .
Tree
, , Tree, .
spoiler
. .
, .
XML
XML .
- NodeList
- Element Node (
<br/>
) - Attribute Node (
tabindex="1"
) - Text Node (
Hello, World!
) - CDATA Node (
<![CDATA[ ... ]]>
) - Processing Instruction Node (
<? ... ?>
) - Comment Node (
<!-- ... -->
) - Document Node
- Document Type Node (
<!DOCTYPE html>
)
XML
, : , . , XML , . , : .
<panel>
<head> ?</head>
<body>
<button></button>
<button></button>
</body>
</panel>
panel
тАФ , body
тАФ , . , .
XML
, XML , .
<xsl:stylesheet
version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" href="web.css" />
</head>
<body>
<xsl:apply-templates select="*" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
тАФ , .
JSON
JSON , . .
- Null
- Boolean
- Number
- String
- Array
- Dictionary
JSON
, . , . , .
{
"foo": 777,
"bar": 666
}
?
[
[ "foo" , 777 ],
[ "bar" , 666 ]
]
. - .
JSON
JSON , - , . MongoDB, , JSON .
{
"$or": [
{
"sex": "female",
"age": { "$gt": 16 },
},
{
"hobby": {
"$regex": "\\b(?:java|type)script\\b"
}
}
]
}
, OR AND . , "", "" " ". , , JSON , "$regexp", .
YAML
YAML JSON. .
- !!null
- !!bool
- !!int
- !!float
- !!str
- !!timestamp
- !!seq
- !!map
- Anchor & Alias
- Document
- TypeTags
YAML
YAML , .
--- !!omap
- foo: 777
- bar: 666
" -" OrderedMap ( ).
TOML
TOML JSON, . , , , .
- Boolean
- Integer
- Float
- String
- DateTime
- Array
- Dictionary
, JSON.
Tree
, . . , , . . .
, . , .
, . , , , .
YAML. . , . , JSON , 30 .
, , .
: , , , , .
. .
XML
XML , . , , , , .
, !
?
?
<message>
<greeting>
, <a href="http://example.org/user/alice"></a>!
</greeting>
<body>
<s> ?</s><br/>
<time datetime="1979-10-14T12:00:00.001-04:00"></time>
?
</body>
</message>
JSON
XML , JSON, , . , .
{ "greetings": ", !\n ?\n ?\n" }
. YAML .
YAML
a: true # boolean
b: tru # string
c: (-: # error
d: :-) # string
YAML .
тАФ . . .
XML
XML тАФ , .
foo > 0 && foo < 10
- , , .
`foo > 0 && foo < 10`
JSON
JSON, . - VSCode, , JSON , .
/"[\s\S]*"/
, . , - .
"\"[\\s\\S]*\""
YAML
YAML , .
, YAML .
Tree
тАФ . . , , , .
. .
XML
<users>
<user>
<name>Alice</name>
<age>20</age>
</user>
</users>
XML, , .
<users><user><name>Alice</name><age>20</age></user></users>
JSON
{
"users": [
{
"name": "Alice",
"age": 20
}
]
}
JSON , тАФ .
{"users":[{"name":"Alice","age":20}]}
Tree
тАФ , .
.
, , , , . , , , .
тАФ , , .
, . , , , . , - .
, .
, JSON, , . . . .
serialization: foo\bar => "foo\\bar"
parsing: "foo\\bar" => foo\bar
, , . , .
. , JSON, , - , , . , . , . .
XML- , тАФ . , , . - , .
, , . . , AST .
, , , . , . , . .
, . , , тАФ . , , , тАФ .
, . , XML SAX , , : - , , - . JSON . , .
, . , , . , . .
, , .
tree-
, "house". ?
house
.
tree-
, ?
house
roof
wall
door
window
floor
.
tree-
?
house
roof
wall
door
window
floor
. Python тАФ , .
tree-
.
house
roof
wall
door
window
glass
floor
, - - .
street
house
wall
door
window
, .
street house wall
window
door
.
, - , - .
\ \(^_^)/
. . , , , . тАФ , тАФ .
? : .
\
\ тАН
\ тАН
\ тАН
.
, . , .
user
name \Jin
age \35
hobby
\kendo
\dance
\role play
default
, . 2 4 .
, . , .
тАФ , .
tree.
grammar.tree
grammar.tree тАФ . , tree.
tree .is .optional .list_of line
line .is .sequence
.optional indent
.optional nodes
new_line
nodes .is .sequence
.optional .list_of struct
.optional data
.with_delimiter space
struct .is .list_of .byte
.except special
data .is .sequence
data_prefix
.optional .list_of .byte
.except new_line
special .is .any_of
new_line
data_prefix
indent
space
new_line .is .byte \0A
indent .is .list_of .byte \09
data_prefix .is .byte \5C
space .is .list_of .byte \20
, , .
: tree тАФ , тАФ , . .
grammar.tree vs EBNF
grammar.tree , , , тАФ , , , .
tree .is .optional .list_of line
line .is .sequence
.optional indent
.optional nodes
new_line
nodes .is .sequence
.optional .list_of struct
.optional data
.with_delimiter space
tree = { line };
line = [ indent ],
[ nodes ],
new_line;
nodes = data |
struct,
{ space , struct },
[ space , data ];
xml.tree vs XML
xml.tree тАФ XML tree . XML. , XML xml.tree.
! doctype html
html
meta @ charset \utf-8
link
@ href \web.css
@ rel \stylesheet
script @ src \web.js
body
h1 \Procter & Gamble
<!doctype html>
<html>
<meta charset="utf-8" />
<link href="web.css" rel="stylesheet" />
<script src="web.js"></script>
<body>
<h1>Procter & Gamble</div>
</body>
</html>
IDE, XML xml.tree , XML. XML , , , markdown.
json.tree vs JSON
json.tree тАФ json.
* user *
name \Jin
age 35
hobby /
\kendo
\dance
home \C:\users\jin\
{
"user": {
"name": "Jin",
"age": 35,
"hobby": [
"kendo ",
"dance ",
],
"home": "C:\\users\\jin\\"
}
}
2 тАФ .
json.tree
, XML Tree , . , json, tree . , , . ?
*
# \If disabled will be used platform specific delimiters
# \CRLN on windows and LN on others
unix_delimiters true
tree , .
{
"unix_delimiters#1": "If disabled will be used platform specific delimiters",
"unix_delimiters#2": "CRLN on windows and LN on others",
"unix_delimiters": true,
}
JSON , - .
view.tree vs TypeScript
view.tree тАФ $mol.
$my_details $mol_view
sub /
<= Pager $mol_paginator
value?val <=> page?val 0
, . , view.tree json.tree , , JSON .
TypeScript . , .
class $my_details extends $mol_view {
sub() { return [ this.Pager() ] }
@ $mol_mem Pager() {
const Pager = new $mol_paginator
Pager.value = val => this.page( val )
return Pager
}
@ $mol_mem page( val = 0 ) {
return val
}
}
API
, API .
XML, , DOM, SAX. , , , . JSON , тАФ . . . , API.
JSON AST
JSON ASTExplorer.
{
"user": {}
}
{
"type" : "Object",
"children" : [
{
"type" : "Property",
"key" : {
"type": "Identifier",
"value": "user"
}
"value": {
"type": "Object",
"children": []
}
}
]
}
, AST . JSON AST. .
AST Tree
tree .
user
name \Jin
age 35
hobby
\kendo
\dance
\role play
AST.
user
name \Jin
age 35
hobby
\kendo
\dance
\role play
, - . . , , , tree тАФ AST.
Tree
TypeScript .
interface $mol_tree2 {
type: string
value: string
kids: $mol_tree2[]
span: $mol_span
}
Span тАФ .
interface $mol_span {
uri: string
row: number
col: number
length: number
}
Tree
, . , , span . .
interface $mol_tree2 {
struct : ( type , kids )=> $mol_tree2
data : ( value , kids )=> $mol_tree2
list : ( kids )=> $mol_tree2
clone : ( kids )=> $mol_tree2
}
Tree
, , тАФ , .
const config_path = './config.tree'
const config_text = fs.readFileSync( config_path )
const config = $mol_tree2.fromString( config_text , config_path )
// server auth
// login \root
// password \qwerty
const password = config.select( 'server' , 'auth' , 'password' , '' )
if( !auth( password.text() ) ) {
// AuthError: Wrong password
// \default
// ./config.tree#5:3-11
throw password.error( 'Wrong password' , AuthError )
}
Tree
тАФ , "auth" "credentials". :
// server credentials
// login \root
// password \qwerty
const new_config = config.list(
input.hack({
'auth' : ( tree , context )=> [
tree.struct( 'credentials' , tree.hack( context ) ),
] ,
'' : ( tree , context )=> [
tree.clone( tree.hack( context ) ),
] ,
})
)
fs.writeFileSync( config_path , new_config )
, tree , , AST.
, . , .
, .
, tree .
sql.tree тАФ
MongoDB? SQL:
select
from $users
fetch
@name
@phone
@photo *
@uri
@width
@height
where or
and
@sex = female
@age > 16
@hobby ~ \\b(?:java|type)script\b
тАФ , SQL. , "", "" " ". , tree, .
select
from $users
fetch *
where @hobby ~
word-edge
or
\java
\type
\script
word-edge
domain.tree тАФ
. .
hyoo_api_person
descr \
inherit hyoo_api_entity
field
id
descr \
example \person=jin
key unique
type text
edit author
avatar
descr \
type list hyoo_api_image
edit author
mail
descr \
type set hyoo_api_mail
API, ACL, .
. тАФ , . , , , тАФ .

access.log.tree тАФ
, , ?
193.34.12.132 - - [2011-10-20T12:46:08+04:00] GET /nin-jin/slides/edit/master/t
ree/readme.md HTTP/1.1 200 4435
193.34.12.132 - - [2011-10-20T12:46:09+04:00] GET /nin-jin/slides/edit/master/t
ree/readme.html HTTP/1.1 404 4435
access
ip \193.34.12.132
time \2011-10-20T12:46:08+04:00
method \GET
uri \/nin-jin/slides/edit/master/tree/readme.md
protocol \HTTP/1.1
response \200
size \4435
, . , , , .
> cat access.log.tree | pick ip time method uri | table
\193.34.12.132 2011-10-20T12:46:08+04:00 GET /index.html
\193.34.12.132 2011-10-20T12:46:10+04:00 GET /index.css
\193.34.12.132 2011-10-20T12:46:20+04:00 GET /index.js
> cat access.log.tree | filter time >= 2019-09 | pick ip uri | table
\193.34.12.132 /index.html
\193.34.12.132 /index.css
\193.34.12.132 /index.js
, - . , - . , , .
tree
tree, , . JSON XML, тАФ , . , - , .
> git log
commit
message \$mol_style: TS@3.9 compatibility
sha \b1a8f07c839604d0d34430a186246f0c1f71e628
date \2020-05-15T23:24:32+0300
author \nin-jin <sairi-na-tenshi@ya.ru>
commit
message \$mol_regexp: concurent parse ability
sha \be1abfa50542728dd5c156517ea31f469e7fb4d4
date \2020-05-15T23:03:30+0300
author \nin-jin <nin-jin@ya.ru>
> git log | pick date message | table
\2020-05-15T23:24:32+0300 $mol_style: TS@3.9 compatibility
\2020-05-15T23:03:30+0300 $mol_regexp: concurent parse ability
WAT
WebAssembly тАФ , . , s-expressions.
(func $fact (param $x i64) (result i64)
(if $x (result i64)
(i64.eqz
(local.get $x))
(then
(i64.const 1))
(else
(i64.mul
(local.get $x)
(call $fact
(i64.sub
(local.get $x)
(i64.const 1)))))))
. , .
wasm.tree тАФ
wasm.tree .
func
name $fact
param $x i64
result i64
body switch
test i64.eqz local.get $x
then i64.const 1
else i64.mul
local.get $x
call $fact i64.sub
local.get $x
64.const 1
- bin.tree, .
00
61
73
6d
01
00
00
00
.
.
.
- - тАФ WAT2.0. WebAssembly тАФ .
jack.tree тАФ LISP
. -, . , , .
jack
import wasm
tree func $fact
> $x #8
< #8 switch
test is-zero $x
then #8 1
else mul
$x
$fact sub
$x
#8 1
, AST , wasm-. , , , , tree , . .
$mol_jack
LLVM
wasm , , .
compile pipelines:
jack.tree => wasm.tree =============> bin.tree
jack.tree => wasm.tree => arm.tree => bin.tree
any-dsl.tree => jack.tree => wasm.tree => arm.tree => bin.tree
, , , .
optimization midlewares:
jack.tree => jack.tree
wasm.tree => wasm.tree
arm.tree => arm.tree
, , , . AST tree .
, , LLVM.
AST
, , . Tree тАФ AST. , TypeScript .
code =(P)=> loader =(P)=> compiler =(SP)=> bundler =(SP)=> terser =(S)=> bundle
P - Parse
S - Serialize
AST, , . AST, .
code =(P)=> loader =====> compiler ======> bundler ======> terser =(S)=> bundle
( ), tree AST , .
,
. . , , . , .