Files
lix/tests/functional/lang/parse-okay-json.exp
T
piegames cf57b5c14c libexpr: Remove Expr::show, add JSON expression serialization
The code for serialization Expr nodes back into (pseudo-)Nix has been
removed for being subtly error-prone and tedious to maintain. Instead,
`nix-instantiate --parse` now prints a JSON representation of the AST.

Usage patterns of the --parse flag I've found in the wild:

1. Check if a file is well-formed, i.e. discard output and test exit code
2. Get parser errors from a file, i.e. discard stdout and use stderr
3. Nixfmt uses --parse to test equivalence pre/post format, and that property is (should be?) preserved

None of these should break with the current change

Closes #487

Change-Id: Icdbaad17790f2ad8765fa08e02e6597ee4c7a909
2025-01-21 11:35:51 +01:00

557 lines
13 KiB
Plaintext

_type: ExprWith
attrs:
_type: ExprSet
recursive: false
body:
_type: ExprList
elems:
- _type: ExprInt
value: 0
- _type: ExprFloat
value: 0.0
- _type: ExprString
value: ''
- _type: ExprString
value: foo
- _type: ExprString
value: 'foo
bar'
- _type: ExprPath
value: /root
- _type: ExprVar
value: var1
- _type: ExprSelect
attrs:
- bar
default:
_type: ExprVar
value: baz
e:
_type: ExprVar
value: foo
- _type: ExprOpHasAttr
attrs:
- bar
- baz
e:
_type: ExprVar
value: foo
- _type: ExprSet
recursive: false
- _type: ExprSet
recursive: true
- _type: ExprSet
attrs:
attr1:
_type: ExprVar
value: value1
attr2:
_type: ExprVar
value: 'null'
attr3:
_type: ExprSet
attrs:
nested:
_type: ExprSet
attrs:
merged:
_type: ExprInt
value: 1
more:
_type: ExprInt
value: 0
recursive: false
recursive: false
fake dynamic attr:
_type: ExprInt
value: 42
string attr:
_type: ExprString
value: string value
dynamicAttrs:
- name:
_type: ExprVar
value: dynamicAttr
value:
_type: ExprSet
dynamicAttrs:
- name:
_type: ExprConcatStrings
es:
- _type: ExprString
value: anotherOne
- _type: ExprString
value: ''
forceString: false
value:
_type: ExprVar
value: 'null'
recursive: false
inherit:
foo:
_type: ExprVar
value: foo
inheritFrom:
- attrs:
- baz
from:
_type: ExprVar
value: bar
- attrs:
- thing
from:
_type: ExprCall
args:
- _type: ExprList
elems:
- _type: ExprVar
value: expression
fun:
_type: ExprVar
value: complicated
recursive: false
- _type: ExprSet
attrs:
attr1:
_type: ExprVar
value: value1
attr2:
_type: ExprVar
value: 'null'
attr3:
_type: ExprSet
attrs:
nested:
_type: ExprSet
attrs:
merged:
_type: ExprInt
value: 1
more:
_type: ExprInt
value: 0
recursive: false
recursive: false
fake dynamic attr:
_type: ExprInt
value: 42
string attr:
_type: ExprString
value: string value
dynamicAttrs:
- name:
_type: ExprVar
value: dynamicAttr
value:
_type: ExprSet
dynamicAttrs:
- name:
_type: ExprConcatStrings
es:
- _type: ExprString
value: anotherOne
- _type: ExprString
value: ''
forceString: false
value:
_type: ExprVar
value: 'null'
recursive: false
inherit:
foo:
_type: ExprVar
value: foo
inheritFrom:
- attrs:
- baz
from:
_type: ExprVar
value: bar
- attrs:
- thing
from:
_type: ExprCall
args:
- _type: ExprList
elems:
- _type: ExprVar
value: expression
fun:
_type: ExprVar
value: complicated
recursive: true
- _type: ExprLet
body:
_type: ExprLet
attrs:
attr1:
_type: ExprVar
value: value1
attr2:
_type: ExprVar
value: 'null'
attr3:
_type: ExprSet
attrs:
nested:
_type: ExprSet
attrs:
merged:
_type: ExprInt
value: 1
more:
_type: ExprInt
value: 0
recursive: false
recursive: false
fake dynamic attr:
_type: ExprInt
value: 42
string attr:
_type: ExprString
value: string value
body:
_type: ExprAssert
body:
_type: ExprAssert
body:
_type: ExprAssert
body:
_type: ExprList
elems: []
cond:
_type: ExprLet
body:
_type: ExprOpEq
e1:
_type: ExprCall
args:
- _type: ExprSelect
attrs:
- overrideStuff
e:
_type: ExprSet
recursive: false
fun:
_type: ExprVar
value: myFunction
e2:
_type: ExprFloat
value: 4.2
cond:
_type: ExprVar
value: 'true'
cond:
_type: ExprVar
value: 'false'
inherit:
foo:
_type: ExprVar
value: foo
inheritFrom:
- attrs:
- baz
from:
_type: ExprVar
value: bar
- attrs:
- thing
from:
_type: ExprCall
args:
- _type: ExprList
elems:
- _type: ExprVar
value: expression
fun:
_type: ExprVar
value: complicated
- _type: ExprLambda
arg: x
body:
_type: ExprVar
value: x
- _type: ExprLambda
arg: x
body:
_type: ExprLambda
arg: y
body:
_type: ExprLambda
arg: z
body:
_type: ExprCall
args:
- _type: ExprVar
value: y
- _type: ExprVar
value: x
fun:
_type: ExprVar
value: z
- _type: ExprLambda
body:
_type: ExprVar
value: 'null'
formalsEllipsis: false
- _type: ExprLambda
body:
_type: ExprVar
value: 'null'
formalsEllipsis: true
- _type: ExprLambda
arg: arg
body:
_type: ExprVar
value: 'null'
formalsEllipsis: false
- _type: ExprLambda
arg: all
body:
_type: ExprVar
value: all
formals:
bar: null
baz: null
foo:
_type: ExprVar
value: 'null'
formalsEllipsis: false
- _type: ExprLambda
arg: all
body:
_type: ExprVar
value: all
formals:
foo:
_type: ExprVar
value: 'null'
formalsEllipsis: true
- _type: ExprIf
cond:
_type: ExprVar
value: 'null'
else:
_type: ExprInt
value: 1
then:
_type: ExprInt
value: 0
- _type: ExprOpNot
e:
_type: ExprVar
value: 'true'
- _type: ExprCall
args:
- _type: ExprConcatStrings
es:
- _type: ExprInt
value: 7
- _type: ExprCall
args:
- _type: ExprCall
args:
- _type: ExprCall
args:
- _type: ExprInt
value: 0
- _type: ExprInt
value: 5
fun:
_type: ExprVar
value: __sub
- _type: ExprInt
value: 12
fun:
_type: ExprVar
value: __mul
- _type: ExprInt
value: 3
fun:
_type: ExprVar
value: __div
forceString: false
- _type: ExprInt
value: 1
fun:
_type: ExprVar
value: __sub
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprInt
value: 0
- _type: ExprCall
args:
- _type: ExprInt
value: 0
- _type: ExprInt
value: 10
fun:
_type: ExprVar
value: __sub
forceString: false
- _type: ExprCall
args:
- _type: ExprInt
value: 0
- _type: ExprCall
args:
- _type: ExprInt
value: 0
- _type: ExprInt
value: 11
fun:
_type: ExprVar
value: __sub
fun:
_type: ExprVar
value: __sub
forceString: false
- _type: ExprCall
args:
- _type: ExprInt
value: 0
- _type: ExprVar
value: x
fun:
_type: ExprVar
value: __sub
forceString: false
- _type: ExprIf
cond:
_type: ExprOpImpl
e1:
_type: ExprOpEq
e1:
_type: ExprCall
args:
- _type: ExprInt
value: 1
- _type: ExprInt
value: 2
fun:
_type: ExprVar
value: __lessThan
e2:
_type: ExprCall
args:
- _type: ExprInt
value: 1
- _type: ExprInt
value: 2
fun:
_type: ExprVar
value: __lessThan
e2:
_type: ExprOpOr
e1:
_type: ExprOpAnd
e1:
_type: ExprOpNEq
e1:
_type: ExprOpNot
e:
_type: ExprCall
args:
- _type: ExprInt
value: 2
- _type: ExprInt
value: 1
fun:
_type: ExprVar
value: __lessThan
e2:
_type: ExprOpNot
e:
_type: ExprCall
args:
- _type: ExprInt
value: 2
- _type: ExprInt
value: 1
fun:
_type: ExprVar
value: __lessThan
e2:
_type: ExprVar
value: 'true'
e2:
_type: ExprVar
value: 'false'
else:
_type: ExprVar
value: err
then:
_type: ExprInt
value: 1
- _type: ExprOpUpdate
e1:
_type: ExprVar
value: foo
e2:
_type: ExprOpUpdate
e1:
_type: ExprSet
recursive: false
e2:
_type: ExprSelect
attrs:
- baz
e:
_type: ExprVar
value: bar
- _type: ExprOpConcatLists
e1:
_type: ExprVar
value: foo
e2:
_type: ExprOpConcatLists
e1:
_type: ExprList
elems: []
e2:
_type: ExprCall
args:
- _type: ExprVar
value: cond
- _type: ExprVar
value: value
fun:
_type: ExprVar
value: optional
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprInt
value: 1
- _type: ExprInt
value: 2
forceString: false
- _type: ExprInt
value: 3
forceString: false
- _type: ExprConcatStrings
es:
- _type: ExprString
value: ''
forceString: true
- _type: ExprConcatStrings
es:
- _type: ExprString
value: 'Foo '
- _type: ExprConcatStrings
es:
- _type: ExprInt
value: 3
- _type: ExprString
value: '2'
forceString: false
forceString: true
- _type: ExprPos