-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More detailed failure reporting * Better ID in Rep * Autofix: TypeScript imports [atomist:generated] [atomist:autofix=typescript_imports] * lint * Move delimited literal to someplace useful * Remove some stringifying for test and move the dep to devDeps, as it's only used in tests * this conversion into tree nodes is hard * This is effed up because it needs ArrayPatternMatch * Delimited matcher * Please squash later * Important: fix isPatternMatch
- Loading branch information
Showing
16 changed files
with
268 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { InputState } from "../../../InputState"; | ||
import { MatchingLogic } from "../../../Matchers"; | ||
import { | ||
MatchFailureReport, | ||
MatchPrefixResult, | ||
matchPrefixSuccess, | ||
} from "../../../MatchPrefixResult"; | ||
import { TerminalPatternMatch } from "../../../PatternMatch"; | ||
import { | ||
LangState, | ||
LangStateMachine, | ||
} from "../LangStateMachine"; | ||
import { | ||
EscapeNextCharacter, | ||
Normal, | ||
} from "./States"; | ||
|
||
// TODO: pass in an inner matcher, support nesting | ||
export class DelimitedLiteral implements MatchingLogic { | ||
public readonly $id = `${this.delimiter} ... ${this.delimiter}`; | ||
|
||
constructor(public readonly delimiter: string, | ||
public readonly escapeChar: string = "\\", | ||
) { | ||
if (delimiter.length !== 1) { | ||
throw new Error("That is not gonna work. Delimiters are 1 char"); | ||
} | ||
if (escapeChar.length !== 1) { | ||
throw new Error("That is not gonna work. escapeChar must be 1 char"); | ||
} | ||
} | ||
public matchPrefix(is: InputState, thisMatchContext: {}, parseContext: {}): | ||
MatchPrefixResult { | ||
const delimiter = this.delimiter; | ||
const initialOffset = is.offset; | ||
let currentIs = is; // is this needed? seems likely. | ||
if (is.peek(1) !== delimiter) { | ||
return MatchFailureReport.from({ | ||
$matcherId: this.$id, | ||
$offset: initialOffset, | ||
cause: `No opening ${delimiter}; saw ${is.peek(1)} instead`, | ||
}); | ||
} | ||
currentIs = currentIs.consume(delimiter, "Opening delimiter"); | ||
let matched = delimiter; | ||
const sm = new DelimiterWithEscapeChar(delimiter, this.escapeChar); | ||
while (sm.state !== Done) { | ||
const next = currentIs.peek(1); | ||
if (next.length === 0) { | ||
// out of input | ||
return MatchFailureReport.from({ | ||
$matcherId: this.$id, | ||
$offset: initialOffset, | ||
cause: `End of input before the closing ${delimiter}`, | ||
}); | ||
} | ||
sm.consume(next); | ||
matched += next; | ||
currentIs = currentIs.consume(next, `Looking for a closing ${delimiter}`); | ||
} | ||
|
||
return matchPrefixSuccess(new TerminalPatternMatch( | ||
this.$id, matched, is.offset, matched)); | ||
} | ||
} | ||
|
||
const Done = new LangState("DONE", false, false); | ||
class DelimiterWithEscapeChar extends LangStateMachine { | ||
|
||
constructor(public readonly endChar: string, | ||
public readonly escapeChar: string, | ||
state: LangState = Normal) { | ||
super(state); | ||
} | ||
|
||
public clone(): DelimiterWithEscapeChar { | ||
return new DelimiterWithEscapeChar(this.endChar, this.escapeChar, this.state); | ||
} | ||
|
||
public consume(ch: string): void { | ||
switch (this.state) { | ||
case Done: | ||
break; | ||
case EscapeNextCharacter: | ||
this.state = Normal; | ||
break; | ||
case Normal: | ||
switch (ch) { | ||
case this.escapeChar: | ||
this.state = EscapeNextCharacter; | ||
break; | ||
case this.endChar: | ||
this.state = Done; | ||
break; | ||
default: | ||
// no change | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { MatchingLogic } from "../../../../Matchers"; | ||
import { DelimitedLiteral } from "../DelimitedLiteral"; | ||
|
||
export function regexLiteral(): MatchingLogic { | ||
return new DelimitedLiteral("/"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.