Skip to content

Commit

Permalink
Fix TableConstructorField separator parsing - Closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
Kampfkarren committed May 24, 2019
1 parent a2b8623 commit bb1c354
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 94 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Properties are no longer `pub` and now have public accessor methods
- License has been changed from GPL to LGPL

### Fixed
- Fixed `TableConstructorField` parsing not correctly giving separator tokens ([#12](https://github.com/Kampfkarren/full-moon/issues/12))

## [0.2.0] - 2019-05-23
### Added
- Added VisitorMut trait which is passed mutable nodes. Mutation is not completely ready yet and may cause side effects
Expand Down
8 changes: 4 additions & 4 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@ define_parser!(ParseTableConstructor, TableConstructor<'a>, |_, state| {
let mut fields = Vec::new();

while let Ok((new_state, field)) = keep_going!(ParseField.parse(state)) {
let field_sep = if let Ok((new_state, _)) = ParseSymbol(Symbol::Comma).parse(new_state) {
let field_sep = if let Ok((new_state, separator)) = ParseSymbol(Symbol::Comma).parse(new_state) {
state = new_state;
Some(state.peek())
} else if let Ok((new_state, _)) = ParseSymbol(Symbol::Semicolon).parse(new_state) {
Some(separator)
} else if let Ok((new_state, separator)) = ParseSymbol(Symbol::Semicolon).parse(new_state) {
state = new_state;
Some(state.peek())
Some(separator)
} else {
state = new_state;
None
Expand Down
24 changes: 12 additions & 12 deletions tests/cases/pass/table-constructor-2/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@
},
{
"start_position": {
"bytes": 14,
"character": 15,
"bytes": 12,
"character": 13,
"line": 1
},
"end_position": {
"bytes": 15,
"character": 16,
"bytes": 13,
"character": 14,
"line": 1
},
"token_type": {
"type": "Number",
"text": "2"
"type": "Symbol",
"symbol": ","
}
}
],
Expand Down Expand Up @@ -92,18 +92,18 @@
},
{
"start_position": {
"bytes": 17,
"character": 18,
"bytes": 15,
"character": 16,
"line": 1
},
"end_position": {
"bytes": 18,
"character": 19,
"bytes": 16,
"character": 17,
"line": 1
},
"token_type": {
"type": "Number",
"text": "3"
"type": "Symbol",
"symbol": ","
}
}
],
Expand Down
76 changes: 38 additions & 38 deletions tests/cases/pass/table-constructor-3/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@
},
{
"start_position": {
"bytes": 21,
"character": 2,
"line": 3
"bytes": 18,
"character": 7,
"line": 2
},
"end_position": {
"bytes": 22,
"character": 3,
"line": 3
"bytes": 19,
"character": 8,
"line": 2
},
"token_type": {
"type": "Identifier",
"identifier": "b"
"type": "Symbol",
"symbol": ","
}
}
],
Expand Down Expand Up @@ -128,18 +128,18 @@
},
{
"start_position": {
"bytes": 29,
"character": 2,
"line": 4
"bytes": 26,
"character": 7,
"line": 3
},
"end_position": {
"bytes": 30,
"character": 3,
"line": 4
"bytes": 27,
"character": 8,
"line": 3
},
"token_type": {
"type": "Identifier",
"identifier": "c"
"type": "Symbol",
"symbol": ","
}
}
],
Expand Down Expand Up @@ -264,18 +264,18 @@
},
{
"start_position": {
"bytes": 59,
"character": 2,
"line": 9
"bytes": 56,
"character": 7,
"line": 8
},
"end_position": {
"bytes": 60,
"character": 3,
"line": 9
"bytes": 57,
"character": 8,
"line": 8
},
"token_type": {
"type": "Identifier",
"identifier": "b"
"type": "Symbol",
"symbol": ","
}
}
],
Expand Down Expand Up @@ -323,18 +323,18 @@
},
{
"start_position": {
"bytes": 67,
"character": 2,
"line": 10
"bytes": 64,
"character": 7,
"line": 9
},
"end_position": {
"bytes": 68,
"character": 3,
"line": 10
"bytes": 65,
"character": 8,
"line": 9
},
"token_type": {
"type": "Identifier",
"identifier": "c"
"type": "Symbol",
"symbol": ","
}
}
],
Expand Down Expand Up @@ -382,18 +382,18 @@
},
{
"start_position": {
"bytes": 74,
"character": 8,
"bytes": 72,
"character": 7,
"line": 10
},
"end_position": {
"bytes": 75,
"character": 2,
"line": 11
"bytes": 73,
"character": 8,
"line": 10
},
"token_type": {
"type": "Symbol",
"symbol": "}"
"symbol": ","
}
}
]
Expand Down
12 changes: 6 additions & 6 deletions tests/cases/pass/table-constructor-4/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@
},
{
"start_position": {
"bytes": 27,
"character": 15,
"bytes": 25,
"character": 14,
"line": 2
},
"end_position": {
"bytes": 28,
"character": 2,
"line": 3
"bytes": 26,
"character": 15,
"line": 2
},
"token_type": {
"type": "Symbol",
"symbol": "}"
"symbol": ","
}
}
]
Expand Down
28 changes: 14 additions & 14 deletions tests/cases/pass/table-constructor-5/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@
},
{
"start_position": {
"bytes": 28,
"character": 2,
"line": 3
"bytes": 25,
"character": 14,
"line": 2
},
"end_position": {
"bytes": 29,
"character": 3,
"line": 3
"bytes": 26,
"character": 15,
"line": 2
},
"token_type": {
"type": "Number",
"text": "2"
"type": "Symbol",
"symbol": ","
}
}
],
Expand Down Expand Up @@ -128,18 +128,18 @@
},
{
"start_position": {
"bytes": 31,
"character": 4,
"bytes": 29,
"character": 3,
"line": 3
},
"end_position": {
"bytes": 32,
"character": 2,
"line": 4
"bytes": 30,
"character": 4,
"line": 3
},
"token_type": {
"type": "Symbol",
"symbol": "}"
"symbol": ","
}
}
]
Expand Down
40 changes: 20 additions & 20 deletions tests/cases/pass/table-constructors-7/ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@
},
{
"start_position": {
"bytes": 66,
"character": 2,
"line": 3
"bytes": 63,
"character": 44,
"line": 2
},
"end_position": {
"bytes": 67,
"character": 3,
"line": 3
"bytes": 64,
"character": 45,
"line": 2
},
"token_type": {
"type": "Symbol",
"symbol": "["
"symbol": ";"
}
}
],
Expand Down Expand Up @@ -140,18 +140,18 @@
},
{
"start_position": {
"bytes": 142,
"character": 2,
"line": 4
"bytes": 139,
"character": 75,
"line": 3
},
"end_position": {
"bytes": 143,
"character": 3,
"line": 4
"bytes": 140,
"character": 76,
"line": 3
},
"token_type": {
"type": "Symbol",
"symbol": "["
"symbol": ";"
}
}
],
Expand Down Expand Up @@ -205,18 +205,18 @@
},
{
"start_position": {
"bytes": 215,
"character": 74,
"bytes": 213,
"character": 73,
"line": 4
},
"end_position": {
"bytes": 216,
"character": 2,
"line": 5
"bytes": 214,
"character": 74,
"line": 4
},
"token_type": {
"type": "Symbol",
"symbol": "}"
"symbol": ";"
}
}
]
Expand Down

0 comments on commit bb1c354

Please sign in to comment.