Skip to content

Commit

Permalink
Add dotted names to AST.
Browse files Browse the repository at this point in the history
See #422.
  • Loading branch information
flatheadmill committed Apr 16, 2020
1 parent 1ad24c7 commit 177255b
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions simplified.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ function map (definitions, packet, depth, extra = {}) {
} else if (depth == 0) {
// TODO It's not depth == 0, more like start of structure.
const fields = []
for (const field in packet) {
fields.push.apply(fields, map(definitions, packet[field], 1, { name: field }))
for (const name in packet) {
fields.push.apply(fields, map(definitions, packet[name], 1, {
name, dotted: `.${name}`
}))
}
const fixed = fields.reduce((fixed, field) => {
return fixed && field.fixed
Expand Down
1 change: 1 addition & 0 deletions test/language/compiled/minimal.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"fields": [
{
"name": "value",
"dotted": ".value",
"type": "integer",
"endianness": "big",
"fixed": true,
Expand Down
1 change: 1 addition & 0 deletions test/language/conditional.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require('proof')(1, okay => {
type: 'structure',
fields: [{
name: 'value',
dotted: '.value',
type: 'conditional',
fixed: false,
bits: 0,
Expand Down
4 changes: 4 additions & 0 deletions test/language/length-encoded-fixed.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ require('proof')(1, okay => {
lengthEncoded: true,
fields: [{
name: 'value',
dotted: '.value',
type: 'lengthEncoding',
fixed: true,
bits: 16,
endianness: 'big',
compliment: false
}, {
name: 'value',
dotted: '.value',
type: 'lengthEncoded',
fixed: false,
bits: 0,
Expand All @@ -24,13 +26,15 @@ require('proof')(1, okay => {
fixed: true,
fields: [{
name: 'first',
dotted: '.first',
type: 'integer',
fixed: true,
bits: 16,
endianness: 'big',
compliment: false
}, {
name: 'second',
dotted: '.second',
type: 'integer',
fixed: true,
bits: 16,
Expand Down
4 changes: 4 additions & 0 deletions test/language/length-encoded-variable.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ require('proof')(1, okay => {
lengthEncoded: true,
fields: [{
name: 'value',
dotted: '.value',
type: 'lengthEncoding',
fixed: true,
bits: 16,
endianness: 'big',
compliment: false
}, {
name: 'value',
dotted: '.value',
type: 'lengthEncoded',
fixed: false,
bits: 0,
Expand All @@ -24,13 +26,15 @@ require('proof')(1, okay => {
fixed: false,
fields: [{
name: 'first',
dotted: '.first',
type: 'lengthEncoding',
fixed: true,
bits: 16,
endianness: 'big',
compliment: false
}, {
name: 'first',
dotted: '.first',
type: 'lengthEncoded',
fixed: false,
bits: 0,
Expand Down
2 changes: 2 additions & 0 deletions test/language/length-encoded.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ require('proof')(1, okay => {
lengthEncoded: true,
fields: [{
name: 'value',
dotted: '.value',
type: 'lengthEncoding',
fixed: true,
bits: 16,
endianness: 'big',
compliment: false
}, {
name: 'value',
dotted: '.value',
type: 'lengthEncoded',
fixed: false,
bits: 0,
Expand Down
1 change: 1 addition & 0 deletions test/language/literal.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require('proof')(1, okay => {
value: '0faded'
}, {
name: 'value',
dotted: '.value',
type: 'integer',
fixed: true,
bits: 16,
Expand Down
1 change: 1 addition & 0 deletions test/language/little-endian.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require('proof')(1, okay => {
type: 'structure',
fields: [{
name: 'value',
dotted: '.value',
type: 'integer',
fixed: true,
bits: 16,
Expand Down
1 change: 1 addition & 0 deletions test/language/minimal.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require('proof')(1, okay => {
type: 'structure',
fields: [{
name: 'value',
dotted: '.value',
type: 'integer',
fixed: true,
bits: 16,
Expand Down

0 comments on commit 177255b

Please sign in to comment.