(infixRules)
| 14978 | }; |
| 14979 | |
| 14980 | function InfixRules(infixRules) { |
| 14981 | function untilExclusive(name) { |
| 14982 | return new InfixRules(infixRules.slice(0, ruleNames().indexOf(name))); |
| 14983 | } |
| 14984 | |
| 14985 | function untilInclusive(name) { |
| 14986 | return new InfixRules(infixRules.slice(0, ruleNames().indexOf(name) + 1)); |
| 14987 | } |
| 14988 | |
| 14989 | function ruleNames() { |
| 14990 | return infixRules.map(function(rule) { |
| 14991 | return rule.name; |
| 14992 | }); |
| 14993 | } |
| 14994 | |
| 14995 | function apply(leftResult) { |
| 14996 | var currentResult; |
| 14997 | var source; |
| 14998 | while (true) { |
| 14999 | currentResult = applyToTokens(leftResult.remaining()); |
| 15000 | if (currentResult.isSuccess()) { |
| 15001 | source = leftResult.source().to(currentResult.source()); |
| 15002 | leftResult = results.success( |
| 15003 | currentResult.value()(leftResult.value(), source), |
| 15004 | currentResult.remaining(), |
| 15005 | source |
| 15006 | ) |
| 15007 | } else if (currentResult.isFailure()) { |
| 15008 | return leftResult; |
| 15009 | } else { |
| 15010 | return currentResult; |
| 15011 | } |
| 15012 | } |
| 15013 | } |
| 15014 | |
| 15015 | function applyToTokens(tokens) { |
| 15016 | return rules.firstOf("infix", infixRules.map(function(infix) { |
| 15017 | return infix.rule; |
| 15018 | }))(tokens); |
| 15019 | } |
| 15020 | |
| 15021 | return { |
| 15022 | apply: apply, |
| 15023 | untilExclusive: untilExclusive, |
| 15024 | untilInclusive: untilInclusive |
| 15025 | } |
| 15026 | } |
| 15027 | |
| 15028 | exports.infix = function(name, ruleBuilder) { |
| 15029 | function map(func) { |
nothing calls this directly
no outgoing calls
no test coverage detected