Skip to content

Instantly share code, notes, and snippets.

@farcaller
Created November 14, 2012 17:30
Show Gist options
  • Save farcaller/4073513 to your computer and use it in GitHub Desktop.
Save farcaller/4073513 to your computer and use it in GitHub Desktop.
Rly::Lex
Simple Lexer
should have a list of defined tokens
should output tokens one by one
Error handling
raises an error, if there are no suitable tokens
calls an error function if it is available, which can skip a token
raises an error, if there is no possible tokens defined
calls an error function if it is available, which returns a fixed token
Block-based Token Lexer
calls a block to further process a token
Ignores Lexer
should honour ignores list
Non-outputtable tokens Lexer
process but don't output tokens without a name
Literals Lexer
should output literal tokens
Rly::Production
should have a length same as length of its symbols
should convert to_s as source -> symbols
should build a list of unique symbols
Rly::Grammar
requires a list of terminals to be initialized
should generate parser.out same as Ply does (PENDING: No reason given)
should reject terminals named in lowercase
has a default terminal -- error
precedence
should allow to set precedence
should allow setting only :left, :right or :noassoc precedence associations
should not allow to set precedence after any productions have been added
should not allow setting precedence several times for same terminal
LR tables
builds LR items for grammar
builds correct FOLLOW table
sets LR items to correct default values
builds correct FIRST table
productions
should return a Production object when adding production
should register one-char terminals
should default precedence to [:right, 0]
should add production to the list of non-terminals
should add production number to referenced non-terminals
should reject productions not named in lowercase
should add production number to referenced terminals
should base the precedence on right-most terminal
should add production to the list of productions
should reject :error production
should not allow duplicate rules
should raise ArgumentError if one-char terminal is not actually an one char
should add production to the list of productions referenced by names
start
should set start symbol if specified explicit
should add 0 to start rule nonterminals
should accept only existing non-terminal as a start
should set start symbol to first production result
should set zero rule to S' -> :start
Rly::LRTable
should compute the LR(0) closure operation on I, where I is a set of LR(0) items
should compute the LR(0) goto function goto(I,X) where I is a set of LR(0) items and X is a grammar symbol
should compute the LR(0) sets of item function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment