Skip to content

Commit

Permalink
Merge pull request #8 from kevinastone/scope-modifiers
Browse files Browse the repository at this point in the history
Added grouping and only: modifier for scopes
  • Loading branch information
kevinastone committed Mar 5, 2016
2 parents 187169e + c4d28d3 commit d464ea7
Show file tree
Hide file tree
Showing 15 changed files with 455 additions and 68 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## master

- Added start-of-line (<<) and end-of-line (>>) position operators
- Added scope matching modifier and grouping (`only:` or `=`)
- =(scope1 scope2)
- only:scope1
- =scope1

## 0.4.0 - 2016-03-03

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int square(int x)
// ^ string.quoted.double

// EOF Check (root scope)
// >> source.c
// >> =source.c
```
Once you've defined your grammar test, you can simply plug into the Jasmine
Expand Down
22 changes: 8 additions & 14 deletions lib/assertions.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
'use babel';

import parse from './grammar';
import { matchScopes } from './scope';
import { matcherBuilder } from './matchers';


class Assertion {
constructor(line, column, ...scopes) {
constructor(line, column, matcher) {
this.line = line;
this.column = column;
this.scopes = scopes;
}

findMissing(...scopes) {
return this.scopes.filter((expected) =>
!scopes.some((actual) =>
matchScopes(actual, expected)
)
);
this.matcher = matcher;
}

findToken(...tokens) {
return tokens.filter((token) => token.matches(this.column)).shift();
}

message() {
return `${this.scopes.join(', ')} at ${this.line}:${this.column}`;
return `${this.matcher.scopes.join(', ')} at ${this.line}:${this.column}`;
}
}

Expand Down Expand Up @@ -68,14 +60,16 @@ export class AssertionParser {

for (const value of this.iterator) {
try {
const [positions, scopes] = this.parseLine(value.line);
const [positions, [modifier, scopes]] = this.parseLine(value.line);
if (!currentLine) {
throw Error("Can't have assertion before any syntax");
}

const matcher = matcherBuilder(modifier, ...scopes);

for (const position of positions) {
currentLine.assertions.push(
new Assertion(currentLine.lineNumber, position, ...scopes)
new Assertion(currentLine.lineNumber, position, matcher)
);
}
} catch (_e) {
Expand Down
235 changes: 219 additions & 16 deletions lib/grammar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d464ea7

Please sign in to comment.