babel-bridge
Version:
a 'runtime' parsing expression grammar parser
70 lines (54 loc) • 2.27 kB
text/coffeescript
{log, defineModule, toInspectedObjects, isPlainObject, push, isString, compactFlatten, inspect, pad, upperCamelCase, merge} = require 'art-standard-lib'
{BaseClass} = require "art-class-system"
defineModule module, class ScratchNode extends BaseClass
: []
: 0
: (parentNode, ruleVariant) ->
if >= .length
[ ++] = new ScratchNode parentNode, ruleVariant
else
[ ++].reset parentNode, ruleVariant
: (scratchNode) ->
throw new Error "WTF" unless scratchNode == [-- ]
constructor: (parent, ruleVariant) ->
= []
= []
parent, ruleVariant
reset: ( , ) ->
{ } =
= .getNextOffset() | 0
= =
= 0
= null
@
"parser",
source: -> .source
nextOffset: -> +
inspectedObjects: ->
offset:
matchLength:
matches: toInspectedObjects
matchPatterns: toInspectedObjects
getNextText: (length)->
nextOffset = ()
.slice nextOffset, nextOffset + length
firstPartialMatchParent: -> .firstPartialMatchParent
realNode: ->
||= new .VariantNodeClass .realNode || ,
ruleVariant:
matchLength:
matches: > 0 && .slice 0,
matchPatterns: > 0 && .slice 0,
checkin: -> ScratchNode.checkin @
subparse: (subSource, options) ->
.subparse subSource, merge options, parentNode: @
addMatch: (pattern, match) ->
return false unless match
?.addMatch pattern, match
[ ++] = match
[ ++] = pattern
= match.nextOffset -
true
_addToParentAsNonMatch: ->
._addToParentAsNonMatch()